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

via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 4 05:42:13 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-mc

Author: Jiaxun Yang (FlyGoat)

<details>
<summary>Changes</summary>

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 # Testcases


Validation: `git diff --check` passes. Tests were not rerun for this cherry-pick.


---
Full diff: https://github.com/llvm/llvm-project/pull/228882.diff


1 Files Affected:

- (modified) llvm/lib/MC/MCSymbolELF.cpp (+11-12) 


``````````diff
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 {

``````````

</details>


https://github.com/llvm/llvm-project/pull/228882


More information about the llvm-commits mailing list