Skip to content

Commit 9ff30d4

Browse files
committed
MCParse: Disallow @ specifier in symbol equating
Relocation specifiers are attached to an instruction and cannot be used in equating. GAS rejects `a = b@plt`. For now, handle just MCSymbolRefExpr.
1 parent 9297af1 commit 9ff30d4

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6334,6 +6334,11 @@ bool parseAssignmentExpression(StringRef Name, bool allow_redef,
63346334
return Parser.TokError("missing expression");
63356335
if (Parser.parseEOL())
63366336
return true;
6337+
// Relocation specifiers are not permitted. For now, handle just
6338+
// MCSymbolRefExpr.
6339+
if (auto *S = dyn_cast<MCSymbolRefExpr>(Value); S && S->getSpecifier())
6340+
return Parser.Error(
6341+
EqualLoc, "relocation specifier not permitted in symbol equating");
63376342

63386343
// Validate that the LHS is allowed to be a variable (either it has not been
63396344
// used as a symbol, or it is an absolute symbol).

llvm/test/MC/ELF/relocation-alias.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# RUN: llvm-objdump --no-print-imm-hex -dr %t | FileCheck %s
33
# RUN: llvm-readelf -s %t | FileCheck %s --check-prefix=SYM
44

5+
# RUN: not llvm-mc -filetype=obj -triple x86_64 --defsym ERR0=1 %s 2>&1 | FileCheck %s --check-prefix=ERR0 --implicit-check-not=error:
56
# RUN: not llvm-mc -filetype=obj -triple x86_64 --defsym ERR=1 %s 2>&1 | FileCheck %s --check-prefix=ERR
67

78
## If a fixup symbol is equated to an undefined symbol, convert the fixup
@@ -39,6 +40,14 @@ movabsq $data_alias_l, %rbx
3940
.globl data
4041
data:
4142

43+
.ifdef ERR0
44+
# ERR0: {{.*}}.s:[[#@LINE+1]]:15: error: relocation specifier not permitted in symbol equating
45+
memcpy_spec = __GI_memcpy@PLT
46+
47+
## Should be rejected as well
48+
memcpy_spec1 = __GI_memcpy@PLT+1
49+
.endif
50+
4251
.ifdef ERR
4352
.text
4453
## Note, GNU as emits a relocation for this erroneous fixup.

0 commit comments

Comments
 (0)