diff options
author | Rui Ueyama <ruiu@google.com> | 2016-02-12 21:47:28 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2016-02-12 21:47:28 +0000 |
commit | 1ebc8ed78ac5df1ad5ba68eb8d8974c1cea1bffa (patch) | |
tree | 76d7ab09c995345f315b6b62ce3a2a43c789d31b /lld/ELF/LinkerScript.h | |
parent | 595c13771d4bfdeea5f2e95a0bc82c5049f65f11 (diff) | |
download | bcm5719-llvm-1ebc8ed78ac5df1ad5ba68eb8d8974c1cea1bffa.tar.gz bcm5719-llvm-1ebc8ed78ac5df1ad5ba68eb8d8974c1cea1bffa.zip |
ELF: Add wildcard pattern matching to SECTIONS linker script command.
Each rule in SECTIONS commands is something like ".foo *(.baz.*)",
which instructs the linker to collect all sections whose name matches
".baz.*" from all files and put them into .foo section.
Previously, we didn't recognize the wildcard character. This patch
adds that feature.
Performance impact is a bit concerning because a linker script can
contain hundreds of SECTIONS rules, and doing pattern matching against
each rule would be too expensive. We could merge all patterns into
single DFA so that it takes O(n) to the input size. However, it is
probably too much at this moment -- we don't know whether the
performance of pattern matching matters or not. So I chose to
implement the simplest algorithm in this patch. I hope this simple
pattern matcher is sufficient.
llvm-svn: 260745
Diffstat (limited to 'lld/ELF/LinkerScript.h')
-rw-r--r-- | lld/ELF/LinkerScript.h | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h index bdfcb7d4256..edda27bdb94 100644 --- a/lld/ELF/LinkerScript.h +++ b/lld/ELF/LinkerScript.h @@ -20,7 +20,23 @@ namespace lld { namespace elf2 { class ScriptParser; +template <class ELFT> class InputSectionBase; +// This class represents each rule in SECTIONS command. +class SectionRule { +public: + SectionRule(StringRef D, StringRef S) : Dest(D), SectionPattern(S) {} + + // Returns true if S should be in Dest section. + template <class ELFT> bool match(InputSectionBase<ELFT> *S); + + StringRef Dest; + +private: + StringRef SectionPattern; +}; + +// This is a runner of the linker script. class LinkerScript { friend class ScriptParser; @@ -29,14 +45,13 @@ public: // this object and Config. void read(MemoryBufferRef MB); - StringRef getOutputSection(StringRef InputSection); - bool isDiscarded(StringRef InputSection); + template <class ELFT> StringRef getOutputSection(InputSectionBase<ELFT> *S); + template <class ELFT> bool isDiscarded(InputSectionBase<ELFT> *S); int compareSections(StringRef A, StringRef B); private: - // A map for SECTIONS command. The key is input section name - // and the value is the corresponding output section name. - llvm::DenseMap<StringRef, StringRef> Sections; + // SECTIONS commands. + std::vector<SectionRule> Sections; // Output sections are sorted by this order. std::vector<StringRef> SectionOrder; |