Skip to content

main: allow indirect linking with libsystemd.so#622

Open
rjarry wants to merge 1 commit into
DPDK:mainfrom
rjarry:sd-notifyf
Open

main: allow indirect linking with libsystemd.so#622
rjarry wants to merge 1 commit into
DPDK:mainfrom
rjarry:sd-notifyf

Conversation

@rjarry
Copy link
Copy Markdown
Collaborator

@rjarry rjarry commented May 22, 2026

Avoid the following error when linking to DPDK dynamic libraries which are indirectly linked to libsystemd:

/usr/bin/x86_64-linux-gnu-ld.bfd: /usr/lib/x86_64-linux-gnu/libsystemd.a(src_libsystemd_sd-daemon_sd-daemon.c.o): in function `sd_notifyf':
(.text+0x2030): multiple definition of `sd_notifyf'; grout.p/main_sd_notify.c.o:./obj-x86_64-linux-gnu/../main/sd_notify.c:36: first defined here

Define our symbol as weak so that it can be overridden.

Changes

main/sd_notify.h

Created new header file declaring sd_notifyf with __attribute__((format(printf, 2, 3), weak)). The weak attribute allows the symbol to be overridden by libsystemd's definition when linking against DPDK dynamic libraries that indirectly depend on libsystemd. The format(printf, 2, 3) attribute enables compile-time format string validation.

Rationale

Resolves multiple definition linker error:

/usr/bin/x86_64-linux-gnu-ld.bfd: /usr/lib/x86_64-linux-gnu/libsystemd.a(...): 
in function `sd_notifyf': multiple definition of `sd_notifyf'

By marking the locally-defined sd_notifyf symbol as weak, the linker preferentially uses libsystemd's definition instead of rejecting the duplicate symbol.

Review Change Stack

Avoid the following error when linking to DPDK dynamic libraries which
are indirectly linked to libsystemd:

/usr/bin/x86_64-linux-gnu-ld.bfd: /usr/lib/x86_64-linux-gnu/libsystemd.a(src_libsystemd_sd-daemon_sd-daemon.c.o): in function `sd_notifyf':
(.text+0x2030): multiple definition of `sd_notifyf'; grout.p/main_sd_notify.c.o:./obj-x86_64-linux-gnu/../main/sd_notify.c:36: first defined here

Define our symbol as weak so that it can be overridden.

Signed-off-by: Robin Jarry <rjarry@redhat.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

📝 Walkthrough

Walkthrough

This PR adds compile-time validation metadata and weak linkage semantics to the sd_notifyf function declaration in the public header main/sd_notify.h. The function now carries a GCC/Clang format(printf, 2, 3) attribute for printf-style format string checking, plus a weak attribute to preserve weak symbol semantics. This is a minimal header-only change.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@main/sd_notify.h`:
- Around line 7-8: The sd_notifyf declaration is marked weak in the header but
the implementation of sd_notifyf (the function definition) is not, causing
possible multiple-definition/link conflicts; update the sd_notifyf definition to
include the weak attribute (same as the header: __attribute__((format(printf, 2,
3), weak))) or add an equivalent weak alias for sd_notifyf in the implementation
so libsystemd can override it, ensuring the symbol is weak at the definition
site (target the sd_notifyf function definition/implementation).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e68044b3-ac79-492f-bff1-3a6e3a8fecdb

📥 Commits

Reviewing files that changed from the base of the PR and between ee3b837 and 7706b31.

📒 Files selected for processing (1)
  • main/sd_notify.h

Comment thread main/sd_notify.h
Comment on lines +7 to +8
int sd_notifyf(int unset_environment, const char *format, ...)
__attribute__((format(printf, 2, 3), weak));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check if sd_notifyf definition has weak attribute

# Search for the function definition and surrounding context
rg -n -A 5 -B 2 'sd_notifyf.*\{' main/sd_notify.c

Repository: DPDK/grout

Length of output: 305


Apply weak to the sd_notifyf definition (not just the header declaration)
main/sd_notify.h marks the sd_notifyf declaration as __attribute__((format(printf, 2, 3), weak)), but main/sd_notify.c defines sd_notifyf without the weak attribute (function definition starts at int sd_notifyf(...) {). To allow libsystemd’s sd_notifyf to override and prevent multiple-definition link errors, the weak attribute needs to be on the definition (or an equivalent weak symbol/alias must be created there).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@main/sd_notify.h` around lines 7 - 8, The sd_notifyf declaration is marked
weak in the header but the implementation of sd_notifyf (the function
definition) is not, causing possible multiple-definition/link conflicts; update
the sd_notifyf definition to include the weak attribute (same as the header:
__attribute__((format(printf, 2, 3), weak))) or add an equivalent weak alias for
sd_notifyf in the implementation so libsystemd can override it, ensuring the
symbol is weak at the definition site (target the sd_notifyf function
definition/implementation).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant