[hjl@gnu-mic-1 warn-5]$ cat foo.c extern void bar (); void foo () { bar (); } [hjl@gnu-mic-1 warn-5]$ cat bar.c #define linker_warning(x, msg) \ static const char __warn_##x[] \ __attribute__((used, section(".gnu.warning." #x))) \ = msg void bar (void) {} linker_warning(bar, "Bad bar"); [hjl@gnu-mic-1 warn-5]$ make /usr/gcc-4.6/bin/gcc -O2 -fPIC -c -o foo.o foo.c /usr/gcc-4.6/bin/gcc -O2 -fPIC -c -o bar.o bar.c /usr/gcc-4.6/bin/gcc -Wl,-e,foo -nostdlib -o x1 foo.o bar.o foo.o: In function `foo': foo.c:(.text+0x3): warning: Bad bar /usr/gcc-4.6/bin/gcc -shared -nostdlib -o x2 foo.o bar.o [hjl@gnu-mic-1 warn-5]$ ./ld.gold -shared -o x2 foo.o bar.o foo.o:foo.c:function foo: warning: Bad bar [hjl@gnu-mic-1 warn-5]$
Created attachment 5735 [details] Generate warnings when .gnu.warning sections are encountered when building shared libraries
Hi H.J. What do you think of the uploaded patch ? The change to allow the warning messages to be generated when building shared libraries is very simple. But it took a bit of work to update the linker testsuite to cope with the new behaviour. Cheers Nick
(In reply to comment #2) > Hi H.J. > > What do you think of the uploaded patch ? > > The change to allow the warning messages to be generated when building shared > libraries is very simple. But it took a bit of work to update the linker > testsuite to cope with the new behaviour. > Very nice. Thanks.
CVSROOT: /cvs/src Module name: src Changes by: nickc@sourceware.org 2011-05-18 14:04:33 Modified files: bfd : ChangeLog elflink.c ld/testsuite : ChangeLog ld/testsuite/ld-elf: shared.exp ld/testsuite/lib: ld-lib.exp Log message: PR ld/12761 * elflink.c (elf_link_add_object_symbols): Process .gnu.warning sections when building shared libraries. * lib/ld-lib.exp (run_cc_link_tests): Add an optional 8th parameter - an expected warning message from the linker. * ld-elf/shared.exp (build_tests): Expect a warning message when building the libbarw.so library. * ld-elf/shared.exp: Run library building tests even when not building a native toolchain. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.5349&r2=1.5350 http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elflink.c.diff?cvsroot=src&r1=1.404&r2=1.405 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1407&r2=1.1408 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-elf/shared.exp.diff?cvsroot=src&r1=1.15&r2=1.16 http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/lib/ld-lib.exp.diff?cvsroot=src&r1=1.82&r2=1.83
Patch checked in.
This patch means we now build glibc libc.so.6 without .gnu.warning.* sections.
CVSROOT: /cvs/src Module name: src Changes by: amodra@sourceware.org 2013-07-20 09:50:16 Modified files: bfd : ChangeLog elflink.c Log message: PR ld/15762 PR ld/12761 * elflink.c (elf_link_add_object_symbols): Don't clobber .gnu.warning.symbol sections when shared. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.6114&r2=1.6115 http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elflink.c.diff?cvsroot=src&r1=1.494&r2=1.495
CVSROOT: /cvs/src Module name: src Branch: binutils-2_23-branch Changes by: amodra@sourceware.org 2013-07-20 09:57:17 Modified files: bfd : ChangeLog elflink.c Log message: PR ld/15762 PR ld/12761 * elflink.c (elf_link_add_object_symbols): Don't clobber .gnu.warning.symbol sections when shared. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_23-branch&r1=1.5758.2.53&r2=1.5758.2.54 http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elflink.c.diff?cvsroot=src&only_with_tag=binutils-2_23-branch&r1=1.450.4.4&r2=1.450.4.5
CVSROOT: /cvs/src Module name: src Changes by: amodra@sourceware.org 2013-07-25 00:14:11 Modified files: bfd : ChangeLog elflink.c Log message: PR ld/15762 PR ld/12761 * elflink.c (elf_link_add_object_symbols): Correct test in last patch. Remove unnecessary code. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.6116&r2=1.6117 http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elflink.c.diff?cvsroot=src&r1=1.495&r2=1.496
CVSROOT: /cvs/src Module name: src Branch: binutils-2_23-branch Changes by: amodra@sourceware.org 2013-07-25 00:54:07 Modified files: bfd : ChangeLog elflink.c Log message: PR ld/15762 PR ld/12761 * elflink.c (elf_link_add_object_symbols): Correct test in last patch. Remove unnecessary code. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_23-branch&r1=1.5758.2.54&r2=1.5758.2.55 http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elflink.c.diff?cvsroot=src&only_with_tag=binutils-2_23-branch&r1=1.450.4.5&r2=1.450.4.6