[llvm] 9e3c7d1 - [MC][ELF] Preserve bits 7:4 of st_other (#228882)

via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 4 11:34:28 PDT 2026


Author: Jiaxun Yang
Date: 2026-10-04T18:34:22Z
New Revision: 9e3c7d1d64c719874b309a3ecafc51508a1a9290

URL: https://github.com/llvm/llvm-project/commit/9e3c7d1d64c719874b309a3ecafc51508a1a9290
DIFF: https://github.com/llvm/llvm-project/commit/9e3c7d1d64c719874b309a3ecafc51508a1a9290.diff

LOG: [MC][ELF] Preserve bits 7:4 of st_other (#228882)

The ELF gABI defines visibility in the low bits of st_other and leaves
the upper bits without a generic meaning [1]. Architecture-specific ELF
extensions use these upper bits. MIPS uses bits 7:4 to identify MIPS16
code symbols with STO_MIPS_MIPS16 (0xf0).

MCSymbolELF currently accepts only bits 7:5, so setting STO_MIPS_MIPS16
triggers an assertion. Expand the storage to preserve bits 7:4 and shift
the adjacent internal flags accordingly.

[1] ELF gABI, Section 5.1, Symbol Table Entry:
    https://gabi.xinuos.com/elf/05-symtab.html#symbol-table-entry

Assisted-by: OpenAI Codex

Added: 
    

Modified: 
    llvm/lib/MC/MCSymbolELF.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCSymbolELF.cpp b/llvm/lib/MC/MCSymbolELF.cpp
index 79774db0cc8e6..7fed80f0c8ade 100644
--- a/llvm/lib/MC/MCSymbolELF.cpp
+++ b/llvm/lib/MC/MCSymbolELF.cpp
@@ -22,21 +22,20 @@ enum {
   // Shift value for STV_* flags. 4 possible values, 2 bits.
   ELF_STV_Shift = 5,
 
-  // Shift value for STO_* flags. 3 bits. All the values are between 0x20 and
-  // 0xe0, so we shift right by 5 before storing.
+  // Shift value for the target-specific high four bits of st_other.
   ELF_STO_Shift = 7,
 
   // One bit.
-  ELF_IsSignature_Shift = 10,
+  ELF_IsSignature_Shift = 11,
 
   // One bit.
-  ELF_Weakref_Shift = 11,
+  ELF_Weakref_Shift = 12,
 
   // One bit.
-  ELF_BindingSet_Shift = 12,
+  ELF_BindingSet_Shift = 13,
 
   // One bit.
-  ELF_IsMemoryTagged_Shift = 13,
+  ELF_IsMemoryTagged_Shift = 14,
 };
 }
 
@@ -156,16 +155,16 @@ unsigned MCSymbolELF::getVisibility() const {
 }
 
 void MCSymbolELF::setOther(unsigned Other) {
-  assert((Other & 0x1f) == 0);
-  Other >>= 5;
-  assert(Other <= 0x7);
-  uint32_t OtherFlags = getFlags() & ~(0x7 << ELF_STO_Shift);
+  assert((Other & 0xf) == 0);
+  Other >>= 4;
+  assert(Other <= 0xf);
+  uint32_t OtherFlags = getFlags() & ~(0xf << ELF_STO_Shift);
   setFlags(OtherFlags | (Other << ELF_STO_Shift));
 }
 
 unsigned MCSymbolELF::getOther() const {
-  unsigned Other = (Flags >> ELF_STO_Shift) & 7;
-  return Other << 5;
+  unsigned Other = (Flags >> ELF_STO_Shift) & 0xf;
+  return Other << 4;
 }
 
 void MCSymbolELF::setIsWeakref() const {


        


More information about the llvm-commits mailing list