[lld] r306036 - Keep the original symbol name when renamed.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 22 10:30:20 PDT 2017
Author: ruiu
Date: Thu Jun 22 12:30:19 2017
New Revision: 306036
URL: http://llvm.org/viewvc/llvm-project?rev=306036&view=rev
Log:
Keep the original symbol name when renamed.
Previously, when symbol A is renamed B, both A and B end up having
the same name. This is because name is a symbol's attribute, and
we memcpy symbols for symbol renaming.
This pathc saves the original symbol name and restore it after memcpy
to keep the original name.
This patch shouldn't change program's meaning, but names in symbol
tables make more sense than before.
Modified:
lld/trunk/ELF/Config.h
lld/trunk/ELF/SymbolTable.cpp
lld/trunk/ELF/Symbols.h
lld/trunk/test/ELF/defsym.s
lld/trunk/test/ELF/lto/wrap-2.ll
lld/trunk/test/ELF/wrap.s
Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=306036&r1=306035&r2=306036&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Thu Jun 22 12:30:19 2017
@@ -70,7 +70,7 @@ struct VersionDefinition {
// Structure for mapping renamed symbols
struct RenamedSymbol {
Symbol *Target;
- uint8_t OrigBinding;
+ uint8_t OriginalBinding;
};
// This struct contains the global configuration for the linker.
Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=306036&r1=306035&r2=306036&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Thu Jun 22 12:30:19 2017
@@ -167,8 +167,8 @@ template <class ELFT> void SymbolTable<E
// Tell LTO not to eliminate this symbol
Wrap->IsUsedInRegularObj = true;
- Config->RenamedSymbols[Real] = RenamedSymbol{Sym, Real->Binding};
- Config->RenamedSymbols[Sym] = RenamedSymbol{Wrap, Sym->Binding};
+ Config->RenamedSymbols[Real] = {Sym, Real->Binding};
+ Config->RenamedSymbols[Sym] = {Wrap, Sym->Binding};
}
// Creates alias for symbol. Used to implement --defsym=ALIAS=SYM.
@@ -184,7 +184,7 @@ template <class ELFT> void SymbolTable<E
// Tell LTO not to eliminate this symbol
Sym->IsUsedInRegularObj = true;
- Config->RenamedSymbols[AliasSym] = RenamedSymbol{Sym, AliasSym->Binding};
+ Config->RenamedSymbols[AliasSym] = {Sym, AliasSym->Binding};
}
// Apply symbol renames created by -wrap and -defsym. The renames are created
@@ -193,14 +193,16 @@ template <class ELFT> void SymbolTable<E
// symbols are finalized, we can perform the replacement.
template <class ELFT> void SymbolTable<ELFT>::applySymbolRenames() {
for (auto &KV : Config->RenamedSymbols) {
- Symbol *Sym = KV.first;
- Symbol *Rename = KV.second.Target;
- Sym->Binding = KV.second.OrigBinding;
-
- // We rename symbols by replacing the old symbol's SymbolBody with the new
- // symbol's SymbolBody. This causes all SymbolBody pointers referring to the
- // old symbol to instead refer to the new symbol.
- memcpy(Sym->Body.buffer, Rename->Body.buffer, sizeof(Sym->Body));
+ Symbol *Dst = KV.first;
+ Symbol *Src = KV.second.Target;
+ Dst->Binding = KV.second.OriginalBinding;
+
+ // We rename symbols by replacing the old symbol's SymbolBody with
+ // the new symbol's SymbolBody. The only attribute we want to keep
+ // is the symbol name, so that two symbols don't have the same name.
+ StringRef S = Dst->body()->getName();
+ memcpy(Dst->Body.buffer, Src->Body.buffer, sizeof(Symbol::Body));
+ Dst->body()->setName(S);
}
}
Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=306036&r1=306035&r2=306036&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Thu Jun 22 12:30:19 2017
@@ -69,6 +69,7 @@ public:
bool isLocal() const { return IsLocal; }
bool isPreemptible() const;
StringRef getName() const { return Name; }
+ void setName(StringRef S) { Name = S; }
uint8_t getVisibility() const { return StOther & 0x3; }
void parseSymbolVersion();
Modified: lld/trunk/test/ELF/defsym.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/defsym.s?rev=306036&r1=306035&r2=306036&view=diff
==============================================================================
--- lld/trunk/test/ELF/defsym.s (original)
+++ lld/trunk/test/ELF/defsym.s Thu Jun 22 12:30:19 2017
@@ -21,7 +21,7 @@
# CHECK-NEXT: Section: Absolute
# CHECK-NEXT: }
# CHECK-NEXT: Symbol {
-# CHECK-NEXT: Name: foo1
+# CHECK-NEXT: Name: foo2
# CHECK-NEXT: Value: 0x123
# CHECK-NEXT: Size:
# CHECK-NEXT: Binding: Global
Modified: lld/trunk/test/ELF/lto/wrap-2.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/wrap-2.ll?rev=306036&r1=306035&r2=306036&view=diff
==============================================================================
--- lld/trunk/test/ELF/lto/wrap-2.ll (original)
+++ lld/trunk/test/ELF/lto/wrap-2.ll Thu Jun 22 12:30:19 2017
@@ -10,8 +10,8 @@
; CHECK: foo:
; CHECK-NEXT: pushq %rax
-; CHECK-NEXT: callq{{.*}}<__wrap_bar>
; CHECK-NEXT: callq{{.*}}<bar>
+; CHECK-NEXT: callq{{.*}}<__real_bar>
; Check that bar and __wrap_bar retain their original binding.
; BIND: Name: bar
Modified: lld/trunk/test/ELF/wrap.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/wrap.s?rev=306036&r1=306035&r2=306036&view=diff
==============================================================================
--- lld/trunk/test/ELF/wrap.s (original)
+++ lld/trunk/test/ELF/wrap.s Thu Jun 22 12:30:19 2017
@@ -12,6 +12,14 @@
// CHECK-NEXT: movl $0x11010, %edx
// CHECK-NEXT: movl $0x11000, %edx
+// RUN: llvm-readobj -t -s %t3 | FileCheck -check-prefix=SYM %s
+// SYM: Name: __real_foo
+// SYM-NEXT: Value: 0x11000
+// SYM: Name: __wrap_foo
+// SYM-NEXT: Value: 0x11010
+// SYM: Name: foo
+// SYM-NEXT: Value: 0x11010
+
.global _start
_start:
movl $foo, %edx
More information about the llvm-commits
mailing list