From: Shankar Easwaran Date: Wed, 13 Feb 2013 06:12:52 +0000 (+0000) Subject: add merge strings option, this temporarily fixes the problem bringing up helloworld... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=96d594b14e6892d28e2700730a6cf31db6028c81;p=platform%2Fupstream%2Fllvm.git add merge strings option, this temporarily fixes the problem bringing up helloworld with glibc on x86_64 llvm-svn: 175038 --- diff --git a/lld/include/lld/Core/LinkerOptions.h b/lld/include/lld/Core/LinkerOptions.h index 3f3b38a..bcc2f7b 100644 --- a/lld/include/lld/Core/LinkerOptions.h +++ b/lld/include/lld/Core/LinkerOptions.h @@ -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; diff --git a/lld/lib/Driver/CoreOptions.td b/lld/lib/Driver/CoreOptions.td index 34ba224e..9360ce5 100644 --- a/lld/lib/Driver/CoreOptions.td +++ b/lld/lib/Driver/CoreOptions.td @@ -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">; diff --git a/lld/lib/Driver/Drivers.cpp b/lld/lib/Driver/Drivers.cpp index 55bb6b0..fcb6472 100644 --- a/lld/lib/Driver/Drivers.cpp +++ b/lld/lib/Driver/Drivers.cpp @@ -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 llvm::opt::ArgList &args) { 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); } diff --git a/lld/lib/Driver/LDOptions.td b/lld/lib/Driver/LDOptions.td index 5ae82bb..a57c8be 100644 --- a/lld/lib/Driver/LDOptions.td +++ b/lld/lib/Driver/LDOptions.td @@ -32,3 +32,6 @@ def hash_style : Joined <["--"], "hash-style=">; 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">; diff --git a/lld/lib/ReaderWriter/ELF/File.h b/lld/lib/ReaderWriter/ELF/File.h index c68742d..0c6d5f6 100644 --- a/lld/lib/ReaderWriter/ELF/File.h +++ b/lld/lib/ReaderWriter/ELF/File.h @@ -143,6 +143,8 @@ public: // Sections that have merge string property std::vector 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()) { diff --git a/lld/test/elf/mergeatoms.objtxt b/lld/test/elf/mergeatoms.objtxt index f36c6c2..a097e05 100644 --- a/lld/test/elf/mergeatoms.objtxt +++ b/lld/test/elf/mergeatoms.objtxt @@ -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. diff --git a/lld/test/elf/mergeconstants.objtxt b/lld/test/elf/mergeconstants.objtxt index bf5c8cf..75284ac 100644 --- a/lld/test/elf/mergeconstants.objtxt +++ b/lld/test/elf/mergeconstants.objtxt @@ -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 diff --git a/lld/test/elf/reloc.objtxt b/lld/test/elf/reloc.objtxt index 3eb2267..1afbcba 100644 --- a/lld/test/elf/reloc.objtxt +++ b/lld/test/elf/reloc.objtxt @@ -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 diff --git a/lld/tools/lld-core/lld-core.cpp b/lld/tools/lld-core/lld-core.cpp index 74f6df5..bbaedcb 100644 --- a/lld/tools/lld-core/lld-core.cpp +++ b/lld/tools/lld-core/lld-core.cpp @@ -70,6 +70,11 @@ cmdLineDoGotPass("got-pass", llvm::cl::desc("Run pass to create GOT atoms")); llvm::cl::opt cmdLineDoLayoutPass("layout-pass", llvm::cl::desc("Run pass to layout atoms")); +llvm::cl::opt +cmdLineDoMergeStrings( + "merge-strings", + llvm::cl::desc("make common strings merge possible")); + llvm::cl::opt 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: