[lld] r312757 - Revert "Revert r311468: If --dynamic-list is given, only those symbols are preemptible"
Evgenii Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 7 17:54:49 PDT 2017
CFI tests (simple check-cfi) are failing on my machine because of this change.
The binary is looking absolutely crazy: it defines a function
"atexit", which is not in the source code, and the new function, among
other things, jumps to a randomly-looking .tbss symbol.
Please revert.
On Thu, Sep 7, 2017 at 4:19 PM, Rafael Espindola via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: rafael
> Date: Thu Sep 7 16:19:09 2017
> New Revision: 312757
>
> URL: http://llvm.org/viewvc/llvm-project?rev=312757&view=rev
> Log:
> Revert "Revert r311468: If --dynamic-list is given, only those symbols are preemptible"
>
> If --dynamic-list is given, only those symbols are preemptible.
>
> This allows combining --dynamic-list and version scripts too. The
> version script controls which symbols are visible, and --dynamic-list
> controls which of those are preemptible.
>
> This fixes pr34053.
>
> Added:
> lld/trunk/test/ELF/dynamic-list-preempt.s
> Modified:
> lld/trunk/ELF/Config.h
> lld/trunk/ELF/ScriptParser.cpp
> lld/trunk/ELF/SymbolTable.cpp
> lld/trunk/ELF/SymbolTable.h
> lld/trunk/ELF/Writer.cpp
>
> Modified: lld/trunk/ELF/Config.h
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=312757&r1=312756&r2=312757&view=diff
> ==============================================================================
> --- lld/trunk/ELF/Config.h (original)
> +++ lld/trunk/ELF/Config.h Thu Sep 7 16:19:09 2017
> @@ -104,6 +104,7 @@ struct Configuration {
> std::vector<llvm::StringRef> SearchPaths;
> std::vector<llvm::StringRef> SymbolOrderingFile;
> std::vector<llvm::StringRef> Undefined;
> + std::vector<SymbolVersion> DynamicList;
> std::vector<SymbolVersion> VersionScriptGlobals;
> std::vector<SymbolVersion> VersionScriptLocals;
> std::vector<uint8_t> BuildIdVector;
>
> Modified: lld/trunk/ELF/ScriptParser.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=312757&r1=312756&r2=312757&view=diff
> ==============================================================================
> --- lld/trunk/ELF/ScriptParser.cpp (original)
> +++ lld/trunk/ELF/ScriptParser.cpp Thu Sep 7 16:19:09 2017
> @@ -180,9 +180,22 @@ static ExprValue bitOr(ExprValue A, Expr
>
> void ScriptParser::readDynamicList() {
> expect("{");
> - readAnonymousDeclaration();
> - if (!atEOF())
> + std::vector<SymbolVersion> Locals;
> + std::vector<SymbolVersion> Globals;
> + std::tie(Locals, Globals) = readSymbols();
> + expect(";");
> +
> + if (!atEOF()) {
> setError("EOF expected, but got " + next());
> + return;
> + }
> + if (!Locals.empty()) {
> + setError("\"local:\" scope not supported in --dynamic-list");
> + return;
> + }
> +
> + for (SymbolVersion V : Globals)
> + Config->DynamicList.push_back(V);
> }
>
> void ScriptParser::readVersionScript() {
>
> Modified: lld/trunk/ELF/SymbolTable.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=312757&r1=312756&r2=312757&view=diff
> ==============================================================================
> --- lld/trunk/ELF/SymbolTable.cpp (original)
> +++ lld/trunk/ELF/SymbolTable.cpp Thu Sep 7 16:19:09 2017
> @@ -680,6 +680,24 @@ void SymbolTable::handleAnonymousVersion
> assignWildcardVersion(Ver, VER_NDX_LOCAL);
> }
>
> +// Handles -dynamic-list.
> +void SymbolTable::handleDynamicList() {
> + for (SymbolVersion &Ver : Config->DynamicList) {
> + std::vector<SymbolBody *> Syms;
> + if (Ver.HasWildcard)
> + Syms = findByVersion(Ver);
> + else
> + Syms = findAllByVersion(Ver);
> +
> + for (SymbolBody *B : Syms) {
> + if (!Config->Shared)
> + B->symbol()->VersionId = VER_NDX_GLOBAL;
> + else if (B->symbol()->includeInDynsym())
> + B->IsPreemptible = true;
> + }
> + }
> +}
> +
> // Set symbol versions to symbols. This function handles patterns
> // containing no wildcard characters.
> void SymbolTable::assignExactVersion(SymbolVersion Ver, uint16_t VersionId,
> @@ -729,6 +747,7 @@ void SymbolTable::assignWildcardVersion(
> void SymbolTable::scanVersionScript() {
> // Handle edge cases first.
> handleAnonymousVersion();
> + handleDynamicList();
>
> // Now we have version definitions, so we need to set version ids to symbols.
> // Each version definition has a glob pattern, and all symbols that match
>
> Modified: lld/trunk/ELF/SymbolTable.h
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=312757&r1=312756&r2=312757&view=diff
> ==============================================================================
> --- lld/trunk/ELF/SymbolTable.h (original)
> +++ lld/trunk/ELF/SymbolTable.h Thu Sep 7 16:19:09 2017
> @@ -90,6 +90,8 @@ public:
>
> void trace(StringRef Name);
>
> + void handleDynamicList();
> +
> private:
> std::vector<SymbolBody *> findByVersion(SymbolVersion Ver);
> std::vector<SymbolBody *> findAllByVersion(SymbolVersion Ver);
>
> Modified: lld/trunk/ELF/Writer.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=312757&r1=312756&r2=312757&view=diff
> ==============================================================================
> --- lld/trunk/ELF/Writer.cpp (original)
> +++ lld/trunk/ELF/Writer.cpp Thu Sep 7 16:19:09 2017
> @@ -1294,8 +1294,9 @@ template <class ELFT> void Writer<ELFT>:
> applySynthetic({In<ELFT>::EhFrame},
> [](SyntheticSection *SS) { SS->finalizeContents(); });
>
> - for (Symbol *S : Symtab->getSymbols())
> - S->body()->IsPreemptible = computeIsPreemptible(*S->body());
> + if (Config->DynamicList.empty())
> + for (Symbol *S : Symtab->getSymbols())
> + S->body()->IsPreemptible = computeIsPreemptible(*S->body());
>
> // Scan relocations. This must be done after every symbol is declared so that
> // we can correctly decide if a dynamic relocation is needed.
>
> Added: lld/trunk/test/ELF/dynamic-list-preempt.s
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/dynamic-list-preempt.s?rev=312757&view=auto
> ==============================================================================
> --- lld/trunk/test/ELF/dynamic-list-preempt.s (added)
> +++ lld/trunk/test/ELF/dynamic-list-preempt.s Thu Sep 7 16:19:09 2017
> @@ -0,0 +1,65 @@
> +# REQUIRES: x86
> +
> +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
> +# RUN: echo "{ foo; zed; };" > %t.list
> +# RUN: echo "{ global: foo; bar; local: *; };" > %t.vers
> +# RUN: ld.lld -fatal-warnings -dynamic-list %t.list -version-script %t.vers -shared %t.o -o %t.so
> +# RUN: llvm-readobj -r %t.so | FileCheck --check-prefix=RELOCS %s
> +# RUN: llvm-readobj -dyn-symbols %t.so | FileCheck --check-prefix=DYNSYMS %s
> +
> +# RELOCS: Relocations [
> +# RELOCS-NEXT: Section ({{.*}}) .rela.plt {
> +# RELOCS-NEXT: R_X86_64_JUMP_SLOT foo 0x0
> +# RELOCS-NEXT: }
> +# RELOCS-NEXT: ]
> +
> +# DYNSYMS: DynamicSymbols [
> +# DYNSYMS-NEXT: Symbol {
> +# DYNSYMS-NEXT: Name: @ (0)
> +# DYNSYMS-NEXT: Value: 0x0
> +# DYNSYMS-NEXT: Size: 0
> +# DYNSYMS-NEXT: Binding: Local
> +# DYNSYMS-NEXT: Type: None
> +# DYNSYMS-NEXT: Other: 0
> +# DYNSYMS-NEXT: Section: Undefined
> +# DYNSYMS-NEXT: }
> +# DYNSYMS-NEXT: Symbol {
> +# DYNSYMS-NEXT: Name: bar@
> +# DYNSYMS-NEXT: Value:
> +# DYNSYMS-NEXT: Size:
> +# DYNSYMS-NEXT: Binding: Global
> +# DYNSYMS-NEXT: Type:
> +# DYNSYMS-NEXT: Other:
> +# DYNSYMS-NEXT: Section:
> +# DYNSYMS-NEXT: }
> +# DYNSYMS-NEXT: Symbol {
> +# DYNSYMS-NEXT: Name: foo@
> +# DYNSYMS-NEXT: Value:
> +# DYNSYMS-NEXT: Size:
> +# DYNSYMS-NEXT: Binding: Global
> +# DYNSYMS-NEXT: Type:
> +# DYNSYMS-NEXT: Other:
> +# DYNSYMS-NEXT: Section:
> +# DYNSYMS-NEXT: }
> +# DYNSYMS-NEXT: ]
> +
> + .globl foo
> +foo:
> + ret
> +
> + .globl bar
> +bar:
> + ret
> +
> + .globl baz
> +baz:
> + ret
> +
> + .globl zed
> +zed:
> + ret
> +
> + call foo at PLT
> + call bar at PLT
> + call baz at PLT
> + call zed at PLT
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list