[lld] r175038 - add merge strings option, this temporarily fixes the problem bringing up helloworld with glibc on x86_64

Shankar Easwaran shankare at codeaurora.org
Tue Feb 12 22:12:52 PST 2013


Author: shankare
Date: Wed Feb 13 00:12:52 2013
New Revision: 175038

URL: http://llvm.org/viewvc/llvm-project?rev=175038&view=rev
Log:
add merge strings option, this temporarily fixes the problem bringing up helloworld with glibc on x86_64

Modified:
    lld/trunk/include/lld/Core/LinkerOptions.h
    lld/trunk/lib/Driver/CoreOptions.td
    lld/trunk/lib/Driver/Drivers.cpp
    lld/trunk/lib/Driver/LDOptions.td
    lld/trunk/lib/ReaderWriter/ELF/File.h
    lld/trunk/test/elf/mergeatoms.objtxt
    lld/trunk/test/elf/mergeconstants.objtxt
    lld/trunk/test/elf/reloc.objtxt
    lld/trunk/tools/lld-core/lld-core.cpp

Modified: lld/trunk/include/lld/Core/LinkerOptions.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/LinkerOptions.h?rev=175038&r1=175037&r2=175038&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/LinkerOptions.h (original)
+++ lld/trunk/include/lld/Core/LinkerOptions.h Wed Feb 13 00:12:52 2013
@@ -157,6 +157,7 @@ struct LinkerOptions {
   unsigned _forceLoadArchives : 1;
   unsigned _textRelocations : 1;
   unsigned _relocatable : 1;
+  unsigned _mergeCommonStrings: 1;
 
 private:
   LinkerOptions(const LinkerOptions&) LLVM_DELETED_FUNCTION;

Modified: lld/trunk/lib/Driver/CoreOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/CoreOptions.td?rev=175038&r1=175037&r2=175038&view=diff
==============================================================================
--- lld/trunk/lib/Driver/CoreOptions.td (original)
+++ lld/trunk/lib/Driver/CoreOptions.td Wed Feb 13 00:12:52 2013
@@ -16,3 +16,6 @@ def emit_yaml : Flag<["-"], "emit-yaml">
 
 def noinhibit_exec : Flag<["-"], "noinhibit-exec">, 
     HelpText<"Retain the executable output file whenever it is still usable">;
+
+def merge_strings : Flag<["-"], "merge-strings">,
+    HelpText<"Merge common strings across mergeable sections">;

Modified: lld/trunk/lib/Driver/Drivers.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/Drivers.cpp?rev=175038&r1=175037&r2=175038&view=diff
==============================================================================
--- lld/trunk/lib/Driver/Drivers.cpp (original)
+++ lld/trunk/lib/Driver/Drivers.cpp Wed Feb 13 00:12:52 2013
@@ -148,6 +148,9 @@ public:
     if (llvm::opt::Arg *A = _inputArgs->getLastArg(ld::OPT_noinhibit_exec))
       newArgs->AddFlagArg(A, _core.getOption(core::OPT_noinhibit_exec));
 
+    if (llvm::opt::Arg *A = _inputArgs->getLastArg(ld::OPT_merge_strings))
+      newArgs->AddFlagArg(A, _core.getOption(core::OPT_merge_strings));
+
     // Copy search paths.
     for (llvm::opt::arg_iterator it = _inputArgs->filtered_begin(ld::OPT_L),
                                  ie = _inputArgs->filtered_end();
@@ -261,6 +264,7 @@ LinkerOptions lld::generateOptions(const
   ret._outputCommands = args.hasArg(core::OPT_OCTOTHORPE_OCTOTHORPE_OCTOTHORPE);
   ret._outputYAML = args.hasArg(core::OPT_emit_yaml);
   ret._noInhibitExec = args.hasArg(core::OPT_noinhibit_exec);
+  ret._mergeCommonStrings = args.hasArg(core::OPT_merge_strings);
 
   return std::move(ret);
 }

Modified: lld/trunk/lib/Driver/LDOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/LDOptions.td?rev=175038&r1=175037&r2=175038&view=diff
==============================================================================
--- lld/trunk/lib/Driver/LDOptions.td (original)
+++ lld/trunk/lib/Driver/LDOptions.td Wed Feb 13 00:12:52 2013
@@ -32,3 +32,6 @@ def hash_style : Joined <["--"], "hash-s
 
 def noinhibit_exec : Flag<["--"], "noinhibit-exec">,
     HelpText<"Retain the executable output file whenever it is still usable">;
+
+def merge_strings : Flag<["-"], "merge-strings">,
+    HelpText<"Merge common strings across mergeable sections">;

Modified: lld/trunk/lib/ReaderWriter/ELF/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/File.h?rev=175038&r1=175037&r2=175038&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/File.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/File.h Wed Feb 13 00:12:52 2013
@@ -143,6 +143,8 @@ public:
     // Sections that have merge string property
     std::vector<const Elf_Shdr *> mergeStringSections;
 
+    bool doStringsMerge = _elfTargetInfo.getLinkerOptions()._mergeCommonStrings;
+
     // Handle: SHT_REL and SHT_RELA sections:
     // Increment over the sections, when REL/RELA section types are found add
     // the contents to the RelocationReferences map.
@@ -163,16 +165,18 @@ public:
       if (section->sh_size == 0)
         continue;
 
-      int64_t sectionFlags = section->sh_flags;
-      sectionFlags &= ~llvm::ELF::SHF_ALLOC;
+      if (doStringsMerge) {
+        int64_t sectionFlags = section->sh_flags;
+        sectionFlags &= ~llvm::ELF::SHF_ALLOC;
 
-      // If the section have mergeable strings, the linker would 
-      // need to split the section into multiple atoms and mark them
-      // mergeByContent
-      if ((section->sh_entsize < 2) &&
-          (sectionFlags == (llvm::ELF::SHF_MERGE | llvm::ELF::SHF_STRINGS))) {
-        mergeStringSections.push_back(section);
-        continue;
+        // If the section have mergeable strings, the linker would 
+        // need to split the section into multiple atoms and mark them
+        // mergeByContent
+        if ((section->sh_entsize < 2) &&
+           (sectionFlags == (llvm::ELF::SHF_MERGE | llvm::ELF::SHF_STRINGS))) {
+          mergeStringSections.push_back(section);
+          continue;
+        }
       }
 
       // Create a sectionSymbols entry for every progbits section.
@@ -268,11 +272,13 @@ public:
 
       // If its a merge section, the atoms have already 
       // been created, lets not create the atoms again
-      int64_t sectionFlags = section->sh_flags;
-      sectionFlags &= ~llvm::ELF::SHF_ALLOC;
-      if ((section->sh_entsize < 2) &&
-          (sectionFlags == (llvm::ELF::SHF_MERGE | llvm::ELF::SHF_STRINGS))) {
-        continue;
+      if (doStringsMerge) {
+        int64_t sectionFlags = section->sh_flags;
+        sectionFlags &= ~llvm::ELF::SHF_ALLOC;
+        if ((section->sh_entsize < 2) &&
+            (sectionFlags == (llvm::ELF::SHF_MERGE | llvm::ELF::SHF_STRINGS))) {
+          continue;
+        }
       }
 
       StringRef symbolName;
@@ -456,7 +462,7 @@ public:
 
         // If the section has mergeable strings, then make the relocation
         // refer to the MergeAtom to allow deduping
-        if (shdr && (shdr->sh_entsize < 2) &&
+        if (doStringsMerge && shdr && (shdr->sh_entsize < 2) &&
             (sectionFlags == (llvm::ELF::SHF_MERGE | llvm::ELF::SHF_STRINGS))) {
           const MergeSectionKey ms(shdr, ri->addend());
           if (_mergedSectionMap.find(ms) == _mergedSectionMap.end()) {

Modified: lld/trunk/test/elf/mergeatoms.objtxt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/mergeatoms.objtxt?rev=175038&r1=175037&r2=175038&view=diff
==============================================================================
--- lld/trunk/test/elf/mergeatoms.objtxt (original)
+++ lld/trunk/test/elf/mergeatoms.objtxt Wed Feb 13 00:12:52 2013
@@ -1,5 +1,5 @@
-RUN: lld-core -reader ELF -writer ELF -o %t1 %p/Inputs/foo.o.x86-64 \
-RUN: %p/Inputs/bar.o.x86-64
+RUN: lld-core -merge-strings=true -reader ELF -writer ELF \
+RUN: -o %t1 %p/Inputs/foo.o.x86-64 %p/Inputs/bar.o.x86-64
 RUN: llvm-objdump -s %t1 |  FileCheck -check-prefix=mergeAtoms %s
 
 mergeAtoms:  1000 62617200 666f6f00                    bar.foo.

Modified: lld/trunk/test/elf/mergeconstants.objtxt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/mergeconstants.objtxt?rev=175038&r1=175037&r2=175038&view=diff
==============================================================================
--- lld/trunk/test/elf/mergeconstants.objtxt (original)
+++ lld/trunk/test/elf/mergeconstants.objtxt Wed Feb 13 00:12:52 2013
@@ -1,4 +1,4 @@
-RUN: lld-core -reader ELF %p/Inputs/constants-merge.x86-64 | FileCheck -check-prefix=mergeAtoms %s
+RUN: lld-core -merge-strings=true -reader ELF %p/Inputs/constants-merge.x86-64 | FileCheck -check-prefix=mergeAtoms %s
 
 mergeAtoms:  - name:            foo
 mergeAtoms:    scope:           global

Modified: lld/trunk/test/elf/reloc.objtxt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/reloc.objtxt?rev=175038&r1=175037&r2=175038&view=diff
==============================================================================
--- lld/trunk/test/elf/reloc.objtxt (original)
+++ lld/trunk/test/elf/reloc.objtxt Wed Feb 13 00:12:52 2013
@@ -1,4 +1,4 @@
-RUN: lld-core -reader ELF %p/Inputs/reloc-test.elf-i386 | FileCheck %s -check-prefix ELF-i386
+RUN: lld-core -merge-strings=true -reader ELF %p/Inputs/reloc-test.elf-i386 | FileCheck %s -check-prefix ELF-i386
 
 ELF-i386: defined-atoms:   
 ELF-i386:   - ref-name:        L000

Modified: lld/trunk/tools/lld-core/lld-core.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/tools/lld-core/lld-core.cpp?rev=175038&r1=175037&r2=175038&view=diff
==============================================================================
--- lld/trunk/tools/lld-core/lld-core.cpp (original)
+++ lld/trunk/tools/lld-core/lld-core.cpp Wed Feb 13 00:12:52 2013
@@ -70,6 +70,11 @@ cmdLineDoGotPass("got-pass", llvm::cl::d
 llvm::cl::opt<bool>
 cmdLineDoLayoutPass("layout-pass", llvm::cl::desc("Run pass to layout atoms"));
 
+llvm::cl::opt<bool>
+cmdLineDoMergeStrings(
+  "merge-strings", 
+  llvm::cl::desc("make common strings merge possible"));
+
 llvm::cl::opt<bool> cmdLineUndefinesIsError(
     "undefines-are-errors",
     llvm::cl::desc("Any undefined symbols at end is an error"));
@@ -230,6 +235,7 @@ int main(int argc, char *argv[]) {
   lo._forceLoadArchives = cmdLineForceLoad;
   lo._outputKind = OutputKind::Executable;
   lo._entrySymbol = cmdLineEntryPoint;
+  lo._mergeCommonStrings = cmdLineDoMergeStrings;
 
   switch (archSelected) {
   case i386:





More information about the llvm-commits mailing list