[mc] Fix ELF st_other flag.
authorLogan Chien <tzuhsiang.chien@gmail.com>
Thu, 5 Dec 2013 00:34:11 +0000 (00:34 +0000)
committerLogan Chien <tzuhsiang.chien@gmail.com>
Thu, 5 Dec 2013 00:34:11 +0000 (00:34 +0000)
ELF_Other_Weakref and ELF_Other_ThumbFunc seems to be LLVM
internal ELF symbol flags.  These should not be emitted to
object file.

This commit defines ELF_STO_Shift for the target-defined
flags for st_other, and increase the value of
ELF_Other_Shift to 16.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@196440 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCELFSymbolFlags.h
lib/MC/ELFObjectWriter.cpp
lib/MC/MCELF.cpp
test/MC/ELF/thumb-st_other.s [new file with mode: 0644]

index d0e1dace99d1a15bf3b5d630e84f48c51317916a..782e7d612677b9d8e721993be0d13134a985c898 100644 (file)
 
 namespace llvm {
   enum {
-    ELF_STT_Shift   = 0, // Shift value for STT_* flags.
-    ELF_STB_Shift   = 4, // Shift value for STB_* flags.
-    ELF_STV_Shift   = 8, // Shift value for STV_* flags.
-    ELF_Other_Shift = 10 // Shift value for other flags.
+    ELF_STT_Shift   = 0,  // Shift value for STT_* flags.
+    ELF_STB_Shift   = 4,  // Shift value for STB_* flags.
+    ELF_STV_Shift   = 8,  // Shift value for STV_* flags.
+    ELF_STO_Shift   = 10, // Shift value for STO_* flags.
+    ELF_Other_Shift = 16  // Shift value for llvm local flags,
+                          // not part of the final object file
   };
 
   enum ELFSymbolFlags {
index 9899bb2eac227c3f410d1f40af142b4b2bbf6a5a..972c64cc56579d7e4e22ad254f8c2c0fc2b4e6a7 100644 (file)
@@ -551,8 +551,7 @@ void ELFObjectWriter::WriteSymbol(MCDataFragment *SymtabF,
   // Other and Visibility share the same byte with Visibility using the lower
   // 2 bits
   uint8_t Visibility = MCELF::GetVisibility(OrigData);
-  uint8_t Other = MCELF::getOther(OrigData) <<
-    (ELF_Other_Shift - ELF_STV_Shift);
+  uint8_t Other = MCELF::getOther(OrigData) << (ELF_STO_Shift - ELF_STV_Shift);
   Other |= Visibility;
 
   uint64_t Value = SymbolValue(Data, Layout);
index ebb189e5439ee766acc33023a22184a056be0edb..0a9cd31dda00694fb5a0831c7b8eeb7839523b44 100644 (file)
@@ -72,13 +72,13 @@ unsigned MCELF::GetVisibility(MCSymbolData &SD) {
 // Other is stored in the last six bits of st_other
 // st_other values are stored in the second byte of get/setFlags
 void MCELF::setOther(MCSymbolData &SD, unsigned Other) {
-  uint32_t OtherFlags = SD.getFlags() & ~(0x3f << ELF_Other_Shift);
-  SD.setFlags(OtherFlags | (Other << ELF_Other_Shift));
+  uint32_t OtherFlags = SD.getFlags() & ~(0x3f << ELF_STO_Shift);
+  SD.setFlags(OtherFlags | (Other << ELF_STO_Shift));
 }
 
 unsigned MCELF::getOther(MCSymbolData &SD) {
   unsigned Other =
-    (SD.getFlags() & (0x3f << ELF_Other_Shift)) >> ELF_Other_Shift;
+    (SD.getFlags() & (0x3f << ELF_STO_Shift)) >> ELF_STO_Shift;
   return Other;
 }
 
diff --git a/test/MC/ELF/thumb-st_other.s b/test/MC/ELF/thumb-st_other.s
new file mode 100644 (file)
index 0000000..8750c2b
--- /dev/null
@@ -0,0 +1,19 @@
+@ Check the value of st_other for thumb function.
+
+@ ARM does not define any st_other flags for thumb function.  The value
+@ for st_other should always be 0.
+
+@ RUN: llvm-mc < %s -triple thumbv5-linux-gnueabi -filetype=obj -o - \
+@ RUN:   | llvm-readobj -t | FileCheck %s
+
+       .syntax unified
+       .text
+       .align  2
+       .thumb_func
+       .global main
+       .type   main,%function
+main:
+       bx      lr
+
+@ CHECK: Name: main
+@ CHECK: Other: 0