From a4819f54c0006554179631189131080be859eefb Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Sun, 6 Aug 2017 08:18:53 -0700 Subject: Treat common symbol as undefined for --no-define-common When --no-define-common is used to build shared library, treat common symbol as undefined so that common symbols that are referenced from a shared library to be assigned addresses only in the main program. This eliminates the unused duplicate space in the shared library, and also prevents any possible confusion over resolving to the wrong duplicate when there are many dynamic modules with specialized search paths for runtime symbol resolution. --no-define-common is only allowed when building a shared library. bfd/ PR ld/21903: * elflink.c (elf_link_add_object_symbols): Treat common symbol as undefined for --no-define-common. include/ PR ld/21903: * bfdlink.h (bfd_link_info): Add inhibit_common_definition. ld/ PR ld/21903: * ld.h (command_line): Remove inhibit_common_definition. * ldgram.y: Replace command_line.inhibit_common_definition with link_info.inhibit_common_definition. * ldlang.c (lang_common): Likewise. * lexsup.c (parse_args): Likewise. * ldmain.c (main): Only allow --no-define-common with -shared. * testsuite/ld-elf/pr21903.s: New file. * testsuite/ld-elf/pr21903a.d: Likewise. * testsuite/ld-elf/pr21903b.d: Likewise. * testsuite/ld-elf/pr21903c.d: Likewise. * testsuite/ld-elf/pr21903d.d: Likewise. * testsuite/ld-elf/pr21903e.d: Likewise. --- ld/ldmain.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'ld/ldmain.c') diff --git a/ld/ldmain.c b/ld/ldmain.c index 5d1a3f4..cb1e2d1 100644 --- a/ld/ldmain.c +++ b/ld/ldmain.c @@ -395,6 +395,9 @@ main (int argc, char **argv) if (argc == 2 && version_printed) xexit (0); + if (link_info.inhibit_common_definition && !bfd_link_dll (&link_info)) + einfo (_("%P%F: --no-define-common may not be used without -shared\n")); + if (!lang_has_input_file) { if (version_printed || command_line.print_output_format) -- cgit v1.1