https://sourceware.org/bugzilla/show_bug.cgi?id=24486
Bug ID: 24486 Summary: ld shouldn't complain undefined weak refereence Product: binutils Version: 2.33 (HEAD) Status: NEW Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: hjl.tools at gmail dot com Target Milestone: --- [hjl@gnu-cfl-1 lto-6]$ cat foo.c extern void bar (void) __attribute__((weak)); void foo (void) { if (bar) bar (); } [hjl@gnu-cfl-1 lto-6]$ cat lib.c int FLAGS_verbose; [hjl@gnu-cfl-1 lto-6]$ cat x.c extern int FLAGS_verbose; extern void bar (void); int a(const char *b) { return FLAGS_verbose; } void unused (void) { bar(); } int main() { a(""); return 0; } [hjl@gnu-cfl-1 lto-6]$ make clean rm -f *.o *.so x *.out ./*.s ./*.res [hjl@gnu-cfl-1 lto-6]$ cat foo.c extern void bar (void) __attribute__((weak)); void foo (void) { if (bar) bar (); } [hjl@gnu-cfl-1 lto-6]$ cat lib.c int FLAGS_verbose; [hjl@gnu-cfl-1 lto-6]$ cat x.c extern int FLAGS_verbose; extern void bar (void); int a(void) { return FLAGS_verbose; } void unused (void) { bar(); } int main() { return a (); } [hjl@gnu-cfl-1 lto-6]$ make gcc -B./ -O -flto -c -o x.o x.c gcc -B./ -O -c -o lib.o lib.c gcc -B./ -O -fpic -c -o foo.o foo.c gcc -B./ -shared -O -o libfoo.so foo.o gcc -B./ -shared -O -o libx.so lib.o libfoo.so gcc -B./ -o x x.o libx.so -Wl,--as-needed -L. -lfoo ./ld: ./libfoo.so: undefined reference to `bar' collect2: error: ld returned 1 exit status make: *** [Makefile:20: x] Error 1 [hjl@gnu-cfl-1 lto-6]$ readelf -s ./libfoo.so | grep bar 2: 0000000000000000 0 NOTYPE WEAK DEFAULT UND bar Weak undefined reference is OK. -- You are receiving this mail because: You are on the CC list for the bug. _______________________________________________ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils