[llvm] 9ff30d4 - MCParse: Disallow @ specifier in symbol equating
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 1 15:20:22 PDT 2025
Author: Fangrui Song
Date: 2025-06-01T15:20:16-07:00
New Revision: 9ff30d4f1c2595f038c4c0cf873387a0c32c7c7b
URL: https://github.com/llvm/llvm-project/commit/9ff30d4f1c2595f038c4c0cf873387a0c32c7c7b
DIFF: https://github.com/llvm/llvm-project/commit/9ff30d4f1c2595f038c4c0cf873387a0c32c7c7b.diff
LOG: MCParse: Disallow @ specifier in symbol equating
Relocation specifiers are attached to an instruction and cannot be used
in equating. GAS rejects `a = b at plt`. For now, handle just
MCSymbolRefExpr.
Added:
Modified:
llvm/lib/MC/MCParser/AsmParser.cpp
llvm/test/MC/ELF/relocation-alias.s
Removed:
################################################################################
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 4e56931387ed3..145f909b58e8e 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -6334,6 +6334,11 @@ bool parseAssignmentExpression(StringRef Name, bool allow_redef,
return Parser.TokError("missing expression");
if (Parser.parseEOL())
return true;
+ // Relocation specifiers are not permitted. For now, handle just
+ // MCSymbolRefExpr.
+ if (auto *S = dyn_cast<MCSymbolRefExpr>(Value); S && S->getSpecifier())
+ return Parser.Error(
+ EqualLoc, "relocation specifier not permitted in symbol equating");
// Validate that the LHS is allowed to be a variable (either it has not been
// used as a symbol, or it is an absolute symbol).
diff --git a/llvm/test/MC/ELF/relocation-alias.s b/llvm/test/MC/ELF/relocation-alias.s
index 7701f1107e5a6..9720a55556ed0 100644
--- a/llvm/test/MC/ELF/relocation-alias.s
+++ b/llvm/test/MC/ELF/relocation-alias.s
@@ -2,6 +2,7 @@
# RUN: llvm-objdump --no-print-imm-hex -dr %t | FileCheck %s
# RUN: llvm-readelf -s %t | FileCheck %s --check-prefix=SYM
+# RUN: not llvm-mc -filetype=obj -triple x86_64 --defsym ERR0=1 %s 2>&1 | FileCheck %s --check-prefix=ERR0 --implicit-check-not=error:
# RUN: not llvm-mc -filetype=obj -triple x86_64 --defsym ERR=1 %s 2>&1 | FileCheck %s --check-prefix=ERR
## If a fixup symbol is equated to an undefined symbol, convert the fixup
@@ -39,6 +40,14 @@ movabsq $data_alias_l, %rbx
.globl data
data:
+.ifdef ERR0
+# ERR0: {{.*}}.s:[[#@LINE+1]]:15: error: relocation specifier not permitted in symbol equating
+memcpy_spec = __GI_memcpy at PLT
+
+## Should be rejected as well
+memcpy_spec1 = __GI_memcpy at PLT+1
+.endif
+
.ifdef ERR
.text
## Note, GNU as emits a relocation for this erroneous fixup.
More information about the llvm-commits
mailing list