[llvm] r226895 - Add STB_GNU_UNIQUE to the ELF writer.
Rafael Espindola
rafael.espindola at gmail.com
Thu Jan 22 20:44:36 PST 2015
Author: rafael
Date: Thu Jan 22 22:44:35 2015
New Revision: 226895
URL: http://llvm.org/viewvc/llvm-project?rev=226895&view=rev
Log:
Add STB_GNU_UNIQUE to the ELF writer.
This lets llvm-mc assemble files produced by gcc.
Modified:
llvm/trunk/include/llvm/Support/ELF.h
llvm/trunk/lib/MC/MCELF.cpp
llvm/trunk/lib/MC/MCELFStreamer.cpp
llvm/trunk/test/MC/ELF/type.s
llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
Modified: llvm/trunk/include/llvm/Support/ELF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ELF.h?rev=226895&r1=226894&r2=226895&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/ELF.h (original)
+++ llvm/trunk/include/llvm/Support/ELF.h Thu Jan 22 22:44:35 2015
@@ -761,6 +761,7 @@ enum {
STB_LOCAL = 0, // Local symbol, not visible outside obj file containing def
STB_GLOBAL = 1, // Global symbol, visible to all object files being combined
STB_WEAK = 2, // Weak symbol, like global but lower-precedence
+ STB_GNU_UNIQUE = 10,
STB_LOOS = 10, // Lowest operating system-specific binding type
STB_HIOS = 12, // Highest operating system-specific binding type
STB_LOPROC = 13, // Lowest processor-specific binding type
Modified: llvm/trunk/lib/MC/MCELF.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCELF.cpp?rev=226895&r1=226894&r2=226895&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCELF.cpp (original)
+++ llvm/trunk/lib/MC/MCELF.cpp Thu Jan 22 22:44:35 2015
@@ -21,7 +21,7 @@ namespace llvm {
void MCELF::SetBinding(MCSymbolData &SD, unsigned Binding) {
assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
- Binding == ELF::STB_WEAK);
+ Binding == ELF::STB_WEAK || Binding == ELF::STB_GNU_UNIQUE);
uint32_t OtherFlags = SD.getFlags() & ~(0xf << ELF_STB_Shift);
SD.setFlags(OtherFlags | (Binding << ELF_STB_Shift));
}
@@ -29,7 +29,7 @@ void MCELF::SetBinding(MCSymbolData &SD,
unsigned MCELF::GetBinding(const MCSymbolData &SD) {
uint32_t Binding = (SD.getFlags() & (0xf << ELF_STB_Shift)) >> ELF_STB_Shift;
assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
- Binding == ELF::STB_WEAK);
+ Binding == ELF::STB_WEAK || Binding == ELF::STB_GNU_UNIQUE);
return Binding;
}
Modified: llvm/trunk/lib/MC/MCELFStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCELFStreamer.cpp?rev=226895&r1=226894&r2=226895&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCELFStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCELFStreamer.cpp Thu Jan 22 22:44:35 2015
@@ -171,10 +171,16 @@ bool MCELFStreamer::EmitSymbolAttribute(
return false;
case MCSA_NoDeadStrip:
- case MCSA_ELF_TypeGnuUniqueObject:
// Ignore for now.
break;
+ case MCSA_ELF_TypeGnuUniqueObject:
+ MCELF::SetType(SD, CombineSymbolTypes(MCELF::GetType(SD), ELF::STT_OBJECT));
+ MCELF::SetBinding(SD, ELF::STB_GNU_UNIQUE);
+ SD.setExternal(true);
+ BindingExplicitlySet.insert(Symbol);
+ break;
+
case MCSA_Global:
MCELF::SetBinding(SD, ELF::STB_GLOBAL);
SD.setExternal(true);
Modified: llvm/trunk/test/MC/ELF/type.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/type.s?rev=226895&r1=226894&r2=226895&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/type.s (original)
+++ llvm/trunk/test/MC/ELF/type.s Thu Jan 22 22:44:35 2015
@@ -9,8 +9,8 @@ foo:
.type bar, at object
bar:
-// Test that gnu_unique_object is accepted.
.type zed, at gnu_unique_object
+zed:
obj:
.global obj
@@ -310,3 +310,13 @@ alias12:
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: .text (0x1)
// CHECK-NEXT: }
+// CHECK-NEXT: Symbol {
+// CHECK-NEXT: Name: zed (32)
+// CHECK-NEXT: Value: 0x0
+// CHECK-NEXT: Size: 0
+// CHECK-NEXT: Binding: Unique (0xA)
+// CHECK-NEXT: Type: Object (0x1)
+// CHECK-NEXT: Other: 0
+// CHECK-NEXT: Section: .text (0x1)
+// CHECK-NEXT: }
+// CHECK-NEXT: ]
Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=226895&r1=226894&r2=226895&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Thu Jan 22 22:44:35 2015
@@ -372,9 +372,10 @@ static const EnumEntry<unsigned> ElfMach
};
static const EnumEntry<unsigned> ElfSymbolBindings[] = {
- { "Local", ELF::STB_LOCAL },
- { "Global", ELF::STB_GLOBAL },
- { "Weak", ELF::STB_WEAK }
+ { "Local", ELF::STB_LOCAL },
+ { "Global", ELF::STB_GLOBAL },
+ { "Weak", ELF::STB_WEAK },
+ { "Unique", ELF::STB_GNU_UNIQUE }
};
static const EnumEntry<unsigned> ElfSymbolTypes[] = {
More information about the llvm-commits
mailing list