Skip to content

Commit cfbd5c8

Browse files
committed
[AArch64] Allow .variant_pcs before the symbol is registered
glibc sysdeps/aarch64/tst-vpcs-mod.S has something like: ``` .variant_pcs vpcs_call .global vpcs_call ``` This is supported by GNU as but leads to an error in MC. Use getOrCreateSymbol to support a not-yet-registered symbol: call `registerSymbol` to ensure the symbol exists even if there is no binding directive/label, to match GNU as. While here, improve tests to check (1) a local symbol can get STO_AARCH64_VARIANT_PCS (2) undefined .variant_pcs (3) an alias does not inherit STO_AARCH64_VARIANT_PCS. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D122507
1 parent a427e18 commit cfbd5c8

File tree

4 files changed

+39
-23
lines changed

4 files changed

+39
-23
lines changed

llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6526,21 +6526,13 @@ bool AArch64AsmParser::parseDirectiveCFIBKeyFrame() {
65266526
/// parseDirectiveVariantPCS
65276527
/// ::= .variant_pcs symbolname
65286528
bool AArch64AsmParser::parseDirectiveVariantPCS(SMLoc L) {
6529-
const AsmToken &Tok = getTok();
6530-
if (Tok.isNot(AsmToken::Identifier))
6529+
StringRef Name;
6530+
if (getParser().parseIdentifier(Name))
65316531
return TokError("expected symbol name");
6532-
6533-
StringRef SymbolName = Tok.getIdentifier();
6534-
6535-
MCSymbol *Sym = getContext().lookupSymbol(SymbolName);
6536-
if (!Sym)
6537-
return TokError("unknown symbol");
6538-
6539-
Lex(); // Eat the symbol
6540-
65416532
if (parseEOL())
65426533
return true;
6543-
getTargetStreamer().emitDirectiveVariantPCS(Sym);
6534+
getTargetStreamer().emitDirectiveVariantPCS(
6535+
getContext().getOrCreateSymbol(Name));
65446536
return false;
65456537
}
65466538

llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ void AArch64TargetELFStreamer::emitInst(uint32_t Inst) {
254254
}
255255

256256
void AArch64TargetELFStreamer::emitDirectiveVariantPCS(MCSymbol *Symbol) {
257+
getStreamer().getAssembler().registerSymbol(*Symbol);
257258
cast<MCSymbolELF>(Symbol)->setOther(ELF::STO_AARCH64_VARIANT_PCS);
258259
}
259260

llvm/test/MC/AArch64/directive-variant_pcs-err.s

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
// CHECK: [[#@LINE+1]]:13: error: expected symbol name
44
.variant_pcs
55

6-
// CHECK: [[#@LINE+1]]:14: error: unknown symbol
7-
.variant_pcs foo
8-
96
.global foo
107
// CHECK: [[#@LINE+1]]:18: error: expected newline
118
.variant_pcs foo bar
Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
1-
// RUN: llvm-mc -triple aarch64-elf -filetype asm -o - %s | FileCheck %s
2-
// RUN: llvm-mc -triple aarch64-elf -filetype obj -o - %s \
3-
// RUN: | llvm-readobj --symbols - | FileCheck %s --check-prefix=CHECK-ST_OTHER
1+
// RUN: llvm-mc -triple aarch64-elf -filetype asm %s | FileCheck %s --check-prefix=ASM
2+
// RUN: llvm-mc -triple aarch64-elf -filetype obj %s \
3+
// RUN: | llvm-readelf -s - | FileCheck %s --check-prefix=OBJ
44

5+
// ASM: .variant_pcs local
6+
// ASM-NEXT: local:
57
.text
6-
.global foo
7-
.variant_pcs foo
8-
// CHECK: .variant_pcs foo
8+
.variant_pcs local
9+
local:
910

10-
// CHECK-ST_OTHER: Name: foo
11-
// CHECK-ST_OTHER: Other [ (0x80)
11+
/// Binding directive before .variant_pcs.
12+
// ASM: .globl def1
13+
// ASM-NEXT: .variant_pcs def1
14+
// ASM-NEXT: def1:
15+
.global def1
16+
.variant_pcs def1
17+
def1:
18+
19+
/// .variant_pcs before binding directive.
20+
// ASM: .variant_pcs def2
21+
// ASM-NEXT: .weak def2
22+
// ASM-NEXT: def2:
23+
.variant_pcs def2
24+
.weak def2
25+
def2:
26+
27+
.globl alias_def1
28+
.set alias_def1, def1
29+
30+
// ASM: .variant_pcs undef
31+
.variant_pcs undef
32+
33+
// OBJ: NOTYPE LOCAL DEFAULT [VARIANT_PCS] [[#]] local
34+
// OBJ-NEXT: NOTYPE GLOBAL DEFAULT [VARIANT_PCS] [[#]] def1
35+
// OBJ-NEXT: NOTYPE WEAK DEFAULT [VARIANT_PCS] [[#]] def2
36+
// OBJ-NEXT: NOTYPE GLOBAL DEFAULT [[#]] alias_def1
37+
// OBJ-NEXT: NOTYPE GLOBAL DEFAULT [VARIANT_PCS] UND undef

0 commit comments

Comments
 (0)