main: allow indirect linking with libsystemd.so#622
Conversation
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>
📝 WalkthroughWalkthroughThis PR adds compile-time validation metadata and weak linkage semantics to the 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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
main/sd_notify.h
| int sd_notifyf(int unset_environment, const char *format, ...) | ||
| __attribute__((format(printf, 2, 3), weak)); |
There was a problem hiding this comment.
🧩 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.cRepository: 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).
Avoid the following error when linking to DPDK dynamic libraries which are indirectly linked to libsystemd:
Define our symbol as weak so that it can be overridden.
Changes
main/sd_notify.h
Created new header file declaring
sd_notifyfwith__attribute__((format(printf, 2, 3), weak)). Theweakattribute allows the symbol to be overridden by libsystemd's definition when linking against DPDK dynamic libraries that indirectly depend on libsystemd. Theformat(printf, 2, 3)attribute enables compile-time format string validation.Rationale
Resolves multiple definition linker error:
By marking the locally-defined
sd_notifyfsymbol as weak, the linker preferentially uses libsystemd's definition instead of rejecting the duplicate symbol.