[lld] r245049 - ELF: Set the correct symbol binding.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 14 06:52:37 PDT 2015
Author: rafael
Date: Fri Aug 14 08:52:36 2015
New Revision: 245049
URL: http://llvm.org/viewvc/llvm-project?rev=245049&view=rev
Log:
ELF: Set the correct symbol binding.
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/elf2/symbols.s
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=245049&r1=245048&r2=245049&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Aug 14 08:52:36 2015
@@ -12,6 +12,7 @@
#include "Error.h"
#include "SymbolTable.h"
#include "Writer.h"
+#include "Symbols.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/FileOutputBuffer.h"
@@ -214,8 +215,24 @@ template <class ELFT> void SymbolTableSe
llvm::StringTableBuilder &Builder = Table.getStringBuilder();
for (auto &P : Table.getSymbols()) {
StringRef Name = P.first;
- auto *S = reinterpret_cast<Elf_Sym *>(Buf);
- S->st_name = Builder.getOffset(Name);
+ Symbol *Sym = P.second;
+
+ auto *ESym = reinterpret_cast<Elf_Sym *>(Buf);
+ ESym->st_name = Builder.getOffset(Name);
+ uint8_t Binding;
+ switch (Sym->Body->kind()) {
+ case SymbolBody::UndefinedKind:
+ llvm_unreachable("Should be defined by now");
+ case SymbolBody::DefinedRegularKind:
+ Binding = STB_GLOBAL;
+ break;
+ case SymbolBody::UndefinedWeakKind:
+ case SymbolBody::DefinedWeakKind:
+ Binding = STB_WEAK;
+ break;
+ }
+ ESym->setBindingAndType(Binding, 0);
+
Buf += sizeof(Elf_Sym);
}
}
Modified: lld/trunk/test/elf2/symbols.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/symbols.s?rev=245049&r1=245048&r2=245049&view=diff
==============================================================================
--- lld/trunk/test/elf2/symbols.s (original)
+++ lld/trunk/test/elf2/symbols.s Fri Aug 14 08:52:36 2015
@@ -23,7 +23,7 @@ foo:
// CHECK-NEXT: Name: _start
// CHECK-NEXT: Value: 0x0
// CHECK-NEXT: Size: 0
-// CHECK-NEXT: Binding: Local (0x0)
+// CHECK-NEXT: Binding: Global (0x1)
// CHECK-NEXT: Type: None (0x0)
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: Undefined (0x0)
@@ -32,7 +32,7 @@ foo:
// CHECK-NEXT: Name: foo
// CHECK-NEXT: Value: 0x0
// CHECK-NEXT: Size: 0
-// CHECK-NEXT: Binding: Local (0x0)
+// CHECK-NEXT: Binding: Weak (0x2)
// CHECK-NEXT: Type: None (0x0)
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: Undefined (0x0)
More information about the llvm-commits
mailing list