[lld] r293835 - Merging r292878:

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 1 14:45:57 PST 2017


Author: hans
Date: Wed Feb  1 16:45:57 2017
New Revision: 293835

URL: http://llvm.org/viewvc/llvm-project?rev=293835&view=rev
Log:
Merging r292878:
------------------------------------------------------------------------
r292878 | ruiu | 2017-01-23 19:41:20 -0800 (Mon, 23 Jan 2017) | 12 lines

Do not allocate space for common symbols with -r

Currently ld.lld -r allocates space for common symbols, whereas ld.bfd
-r doesn't.  As a result the OpenBSD makefile bits for creating libraries
fail as they use ld -X -r to strip local symbols, which results in
duplicate symbol errors because space for the common symbols has been
allocated.

The diff also implements the --define-commons option such that allocation
of commons can be forced even if -r is used.

Patch by Mark Kettenis.
------------------------------------------------------------------------

Added:
    lld/branches/release_40/test/ELF/relocatable-common.s
      - copied unchanged from r292878, lld/trunk/test/ELF/relocatable-common.s
Modified:
    lld/branches/release_40/   (props changed)
    lld/branches/release_40/ELF/Config.h
    lld/branches/release_40/ELF/Driver.cpp
    lld/branches/release_40/ELF/Options.td
    lld/branches/release_40/ELF/Symbols.cpp
    lld/branches/release_40/ELF/SyntheticSections.cpp

Propchange: lld/branches/release_40/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Feb  1 16:45:57 2017
@@ -1 +1 @@
-/lld/trunk:292909,293078
+/lld/trunk:292878,292909,293078

Modified: lld/branches/release_40/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_40/ELF/Config.h?rev=293835&r1=293834&r2=293835&view=diff
==============================================================================
--- lld/branches/release_40/ELF/Config.h (original)
+++ lld/branches/release_40/ELF/Config.h Wed Feb  1 16:45:57 2017
@@ -98,6 +98,7 @@ struct Configuration {
   bool Bsymbolic;
   bool BsymbolicFunctions;
   bool ColorDiagnostics = false;
+  bool DefineCommon;
   bool Demangle = true;
   bool DisableVerify;
   bool EhFrameHdr;

Modified: lld/branches/release_40/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_40/ELF/Driver.cpp?rev=293835&r1=293834&r2=293835&view=diff
==============================================================================
--- lld/branches/release_40/ELF/Driver.cpp (original)
+++ lld/branches/release_40/ELF/Driver.cpp Wed Feb  1 16:45:57 2017
@@ -496,6 +496,8 @@ void LinkerDriver::readConfigs(opt::Inpu
   Config->Pie = getArg(Args, OPT_pie, OPT_nopie, false);
   Config->PrintGcSections = Args.hasArg(OPT_print_gc_sections);
   Config->Relocatable = Args.hasArg(OPT_relocatable);
+  Config->DefineCommon = getArg(Args, OPT_define_common, OPT_no_define_common,
+                                !Config->Relocatable);
   Config->Discard = getDiscardOption(Args);
   Config->SaveTemps = Args.hasArg(OPT_save_temps);
   Config->SingleRoRx = Args.hasArg(OPT_no_rosegment);

Modified: lld/branches/release_40/ELF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_40/ELF/Options.td?rev=293835&r1=293834&r2=293835&view=diff
==============================================================================
--- lld/branches/release_40/ELF/Options.td (original)
+++ lld/branches/release_40/ELF/Options.td Wed Feb  1 16:45:57 2017
@@ -45,6 +45,9 @@ def color_diagnostics: F<"color-diagnost
 def color_diagnostics_eq: J<"color-diagnostics=">,
   HelpText<"Use colors in diagnostics">;
 
+def define_common: F<"define-common">,
+  HelpText<"Assign space to common symbols">;
+
 def disable_new_dtags: F<"disable-new-dtags">,
   HelpText<"Disable new dynamic tags">;
 
@@ -130,6 +133,9 @@ def no_as_needed: F<"no-as-needed">,
 def no_color_diagnostics: F<"no-color-diagnostics">,
   HelpText<"Do not use colors in diagnostics">;
 
+def no_define_common: F<"no-define-common">,
+  HelpText<"Do not assign space to common symbols">;
+
 def no_demangle: F<"no-demangle">,
   HelpText<"Do not demangle symbol names">;
 
@@ -255,6 +261,9 @@ def alias_Bstatic_dn: F<"dn">, Alias<Bst
 def alias_Bstatic_non_shared: F<"non_shared">, Alias<Bstatic>;
 def alias_Bstatic_static: F<"static">, Alias<Bstatic>;
 def alias_L__library_path: J<"library-path=">, Alias<L>;
+def alias_define_common_d: Flag<["-"], "d">, Alias<define_common>;
+def alias_define_common_dc: F<"dc">, Alias<define_common>;
+def alias_define_common_dp: F<"dp">, Alias<define_common>;
 def alias_discard_all_x: Flag<["-"], "x">, Alias<discard_all>;
 def alias_discard_locals_X: Flag<["-"], "X">, Alias<discard_locals>;
 def alias_dynamic_list: J<"dynamic-list=">, Alias<dynamic_list>;
@@ -320,7 +329,6 @@ def plugin_opt_eq: J<"plugin-opt=">;
 // Options listed below are silently ignored for now for compatibility.
 def allow_shlib_undefined: F<"allow-shlib-undefined">;
 def cref: Flag<["--"], "cref">;
-def define_common: F<"define-common">;
 def demangle: F<"demangle">;
 def detect_odr_violations: F<"detect-odr-violations">;
 def g: Flag<["-"], "g">;
@@ -347,9 +355,6 @@ def G: JoinedOrSeparate<["-"], "G">;
 def Qy : F<"Qy">;
 
 // Aliases for ignored options
-def alias_define_common_d: Flag<["-"], "d">, Alias<define_common>;
-def alias_define_common_dc: F<"dc">, Alias<define_common>;
-def alias_define_common_dp: F<"dp">, Alias<define_common>;
 def alias_Map_eq: J<"Map=">, Alias<Map>;
 def alias_version_script_version_script: J<"version-script=">,
   Alias<version_script>;

Modified: lld/branches/release_40/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_40/ELF/Symbols.cpp?rev=293835&r1=293834&r2=293835&view=diff
==============================================================================
--- lld/branches/release_40/ELF/Symbols.cpp (original)
+++ lld/branches/release_40/ELF/Symbols.cpp Wed Feb  1 16:45:57 2017
@@ -73,6 +73,8 @@ static typename ELFT::uint getSymVA(cons
     return VA;
   }
   case SymbolBody::DefinedCommonKind:
+    if (!Config->DefineCommon)
+      return 0;
     return In<ELFT>::Common->OutSec->Addr + In<ELFT>::Common->OutSecOff +
            cast<DefinedCommon>(Body).Offset;
   case SymbolBody::SharedKind: {

Modified: lld/branches/release_40/ELF/SyntheticSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/branches/release_40/ELF/SyntheticSections.cpp?rev=293835&r1=293834&r2=293835&view=diff
==============================================================================
--- lld/branches/release_40/ELF/SyntheticSections.cpp (original)
+++ lld/branches/release_40/ELF/SyntheticSections.cpp Wed Feb  1 16:45:57 2017
@@ -59,6 +59,9 @@ template <class ELFT> InputSection<ELFT>
                                        ArrayRef<uint8_t>(), "COMMON");
   Ret->Live = true;
 
+  if (!Config->DefineCommon)
+    return Ret;
+
   // Sort the common symbols by alignment as an heuristic to pack them better.
   std::vector<DefinedCommon *> Syms = getCommonSymbols<ELFT>();
   std::stable_sort(Syms.begin(), Syms.end(),
@@ -1168,10 +1171,14 @@ void SymbolTableSection<ELFT>::writeGlob
     ESym->setVisibility(Body->symbol()->Visibility);
     ESym->st_value = Body->getVA<ELFT>();
 
-    if (const OutputSectionBase *OutSec = getOutputSection(Body))
+    if (const OutputSectionBase *OutSec = getOutputSection(Body)) {
       ESym->st_shndx = OutSec->SectionIndex;
-    else if (isa<DefinedRegular<ELFT>>(Body))
+    } else if (isa<DefinedRegular<ELFT>>(Body)) {
       ESym->st_shndx = SHN_ABS;
+    } else if (isa<DefinedCommon>(Body)) {
+      ESym->st_shndx = SHN_COMMON;
+      ESym->st_value = cast<DefinedCommon>(Body)->Alignment;
+    }
 
     if (Config->EMachine == EM_MIPS) {
       // On MIPS we need to mark symbol which has a PLT entry and requires
@@ -1203,6 +1210,8 @@ SymbolTableSection<ELFT>::getOutputSecti
     break;
   }
   case SymbolBody::DefinedCommonKind:
+    if (!Config->DefineCommon)
+      return nullptr;
     return In<ELFT>::Common->OutSec;
   case SymbolBody::SharedKind: {
     auto &SS = cast<SharedSymbol<ELFT>>(*Sym);




More information about the llvm-commits mailing list