aboutsummaryrefslogtreecommitdiff
path: root/bfd/elflink.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2017-08-06 08:18:53 -0700
committerH.J. Lu <hjl.tools@gmail.com>2017-08-06 08:19:04 -0700
commita4819f54c0006554179631189131080be859eefb (patch)
treef6058c1da96aa3065bba0be6352946163aa5186d /bfd/elflink.c
parente2a084f2c152f6358ba926df22a313d3ef8d8509 (diff)
downloadgdb-a4819f54c0006554179631189131080be859eefb.zip
gdb-a4819f54c0006554179631189131080be859eefb.tar.gz
gdb-a4819f54c0006554179631189131080be859eefb.tar.bz2
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.
Diffstat (limited to 'bfd/elflink.c')
-rw-r--r--bfd/elflink.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/bfd/elflink.c b/bfd/elflink.c
index eff53ac..0cc5f87 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -4250,6 +4250,11 @@ error_free_dyn:
override = FALSE;
+ /* Treat common symbol as undefined for --no-define-common. */
+ if (isym->st_shndx == SHN_COMMON
+ && info->inhibit_common_definition)
+ isym->st_shndx = SHN_UNDEF;
+
flags = BSF_NO_FLAGS;
sec = NULL;
value = isym->st_value;