Bug 12761 - .gnu.warning.* doesn't work when building shared library
Summary: .gnu.warning.* doesn't work when building shared library
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.22
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-14 16:58 UTC by H.J. Lu
Modified: 2013-07-25 00:54 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Generate warnings when .gnu.warning sections are encountered when building shared libraries (1.48 KB, patch)
2011-05-18 13:41 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2011-05-14 16:58:44 UTC
[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]$
Comment 1 Nick Clifton 2011-05-18 13:41:37 UTC
Created attachment 5735 [details]
Generate warnings when .gnu.warning sections are encountered when building shared libraries
Comment 2 Nick Clifton 2011-05-18 13:42:53 UTC
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
Comment 3 H.J. Lu 2011-05-18 13:52:13 UTC
(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.
Comment 4 Sourceware Commits 2011-05-18 14:04:36 UTC
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
Comment 5 Nick Clifton 2011-05-18 14:07:06 UTC
Patch checked in.
Comment 6 Alan Modra 2013-07-20 08:41:55 UTC
This patch means we now build glibc libc.so.6 without .gnu.warning.* sections.
Comment 7 Sourceware Commits 2013-07-20 09:50:18 UTC
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
Comment 8 Sourceware Commits 2013-07-20 09:57:18 UTC
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
Comment 9 Sourceware Commits 2013-07-25 00:14:13 UTC
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
Comment 10 Sourceware Commits 2013-07-25 00:54:09 UTC
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