[llvm-commits] [llvm] r114285 - in /llvm/trunk: lib/MC/ELFObjectWriter.cpp test/MC/ELF/file.s
Rafael Espindola
rafael.espindola at gmail.com
Sat Sep 18 08:03:21 PDT 2010
Author: rafael
Date: Sat Sep 18 10:03:21 2010
New Revision: 114285
URL: http://llvm.org/viewvc/llvm-project?rev=114285&view=rev
Log:
Make sure the STT_FILE symbol is the first one in the symbol table.
Added:
llvm/trunk/test/MC/ELF/file.s
Modified:
llvm/trunk/lib/MC/ELFObjectWriter.cpp
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=114285&r1=114284&r2=114285&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Sat Sep 18 10:03:21 2010
@@ -34,6 +34,15 @@
#include <vector>
using namespace llvm;
+static unsigned GetType(const MCSymbolData &SD) {
+ uint32_t Type = (SD.getFlags() & (0xf << ELF_STT_Shift)) >> ELF_STT_Shift;
+ assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT ||
+ Type == ELF::STT_FUNC || Type == ELF::STT_SECTION ||
+ Type == ELF::STT_FILE || Type == ELF::STT_COMMON ||
+ Type == ELF::STT_TLS);
+ return Type;
+}
+
namespace {
class ELFObjectWriterImpl {
@@ -64,6 +73,10 @@
// Support lexicographic sorting.
bool operator<(const ELFSymbolData &RHS) const {
+ if (GetType(*SymbolData) == ELF::STT_FILE)
+ return true;
+ if (GetType(*RHS.SymbolData) == ELF::STT_FILE)
+ return false;
return SymbolData->getSymbol().getName() <
RHS.SymbolData->getSymbol().getName();
}
Added: llvm/trunk/test/MC/ELF/file.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/file.s?rev=114285&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/file.s (added)
+++ llvm/trunk/test/MC/ELF/file.s Sat Sep 18 10:03:21 2010
@@ -0,0 +1,23 @@
+// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s
+
+// Test that the STT_FILE symbol precedes the other local symbols.
+
+.file "foo"
+foa:
+// CHECK: # Symbol 1
+// CHECK-NEXT: (('st_name', 1) # 'foo'
+// CHECK-NEXT: ('st_bind', 0)
+// CHECK-NEXT: ('st_type', 4)
+// CHECK-NEXT: ('st_other', 0)
+// CHECK-NEXT: ('st_shndx', 65521)
+// CHECK-NEXT: ('st_value', 0)
+// CHECK-NEXT: ('st_size', 0)
+// CHECK-NEXT: ),
+// CHECK-NEXT: # Symbol 2
+// CHECK-NEXT: (('st_name', 5) # 'foa'
+// CHECK-NEXT: ('st_bind', 0)
+// CHECK-NEXT: ('st_type', 0)
+// CHECK-NEXT: ('st_other', 0)
+// CHECK-NEXT: ('st_shndx', 1)
+// CHECK-NEXT: ('st_value', 0)
+// CHECK-NEXT: ('st_size', 0)
More information about the llvm-commits
mailing list