[llvm-branch-commits] [llvm] d53e260 - [AArch64] Allow .variant_pcs before the symbol is registered
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Apr 6 13:55:12 PDT 2022
Author: Fangrui Song
Date: 2022-04-06T11:58:31-07:00
New Revision: d53e2603383a1304c3ee081169b1bf8dac93f8e4
URL: https://github.com/llvm/llvm-project/commit/d53e2603383a1304c3ee081169b1bf8dac93f8e4
DIFF: https://github.com/llvm/llvm-project/commit/d53e2603383a1304c3ee081169b1bf8dac93f8e4.diff
LOG: [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
(cherry picked from commit cfbd5c8e4aa1ba3fc11fb408eeedbb05bd235956)
Added:
Modified:
llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp
llvm/test/MC/AArch64/directive-variant_pcs-err.s
llvm/test/MC/AArch64/directive-variant_pcs.s
Removed:
################################################################################
diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
index 33ed7ae9780e6..8f71eb3095cfe 100644
--- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
+++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
@@ -6515,21 +6515,13 @@ bool AArch64AsmParser::parseDirectiveCFIBKeyFrame() {
/// parseDirectiveVariantPCS
/// ::= .variant_pcs symbolname
bool AArch64AsmParser::parseDirectiveVariantPCS(SMLoc L) {
- const AsmToken &Tok = getTok();
- if (Tok.isNot(AsmToken::Identifier))
+ StringRef Name;
+ if (getParser().parseIdentifier(Name))
return TokError("expected symbol name");
-
- StringRef SymbolName = Tok.getIdentifier();
-
- MCSymbol *Sym = getContext().lookupSymbol(SymbolName);
- if (!Sym)
- return TokError("unknown symbol");
-
- Lex(); // Eat the symbol
-
if (parseEOL())
return true;
- getTargetStreamer().emitDirectiveVariantPCS(Sym);
+ getTargetStreamer().emitDirectiveVariantPCS(
+ getContext().getOrCreateSymbol(Name));
return false;
}
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp
index 78c0e90b13845..46edb12959d28 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFStreamer.cpp
@@ -254,6 +254,7 @@ void AArch64TargetELFStreamer::emitInst(uint32_t Inst) {
}
void AArch64TargetELFStreamer::emitDirectiveVariantPCS(MCSymbol *Symbol) {
+ getStreamer().getAssembler().registerSymbol(*Symbol);
cast<MCSymbolELF>(Symbol)->setOther(ELF::STO_AARCH64_VARIANT_PCS);
}
diff --git a/llvm/test/MC/AArch64/directive-variant_pcs-err.s b/llvm/test/MC/AArch64/directive-variant_pcs-err.s
index 70bb5451d3716..6aa63d8298776 100644
--- a/llvm/test/MC/AArch64/directive-variant_pcs-err.s
+++ b/llvm/test/MC/AArch64/directive-variant_pcs-err.s
@@ -3,9 +3,6 @@
// CHECK: [[#@LINE+1]]:13: error: expected symbol name
.variant_pcs
-// CHECK: [[#@LINE+1]]:14: error: unknown symbol
-.variant_pcs foo
-
.global foo
// CHECK: [[#@LINE+1]]:18: error: expected newline
.variant_pcs foo bar
diff --git a/llvm/test/MC/AArch64/directive-variant_pcs.s b/llvm/test/MC/AArch64/directive-variant_pcs.s
index f6f9c9c272f78..26ed7aef90cce 100644
--- a/llvm/test/MC/AArch64/directive-variant_pcs.s
+++ b/llvm/test/MC/AArch64/directive-variant_pcs.s
@@ -1,11 +1,37 @@
-// RUN: llvm-mc -triple aarch64-elf -filetype asm -o - %s | FileCheck %s
-// RUN: llvm-mc -triple aarch64-elf -filetype obj -o - %s \
-// RUN: | llvm-readobj --symbols - | FileCheck %s --check-prefix=CHECK-ST_OTHER
+// RUN: llvm-mc -triple aarch64-elf -filetype asm %s | FileCheck %s --check-prefix=ASM
+// RUN: llvm-mc -triple aarch64-elf -filetype obj %s \
+// RUN: | llvm-readelf -s - | FileCheck %s --check-prefix=OBJ
+// ASM: .variant_pcs local
+// ASM-NEXT: local:
.text
-.global foo
-.variant_pcs foo
-// CHECK: .variant_pcs foo
+.variant_pcs local
+local:
-// CHECK-ST_OTHER: Name: foo
-// CHECK-ST_OTHER: Other [ (0x80)
+/// Binding directive before .variant_pcs.
+// ASM: .globl def1
+// ASM-NEXT: .variant_pcs def1
+// ASM-NEXT: def1:
+.global def1
+.variant_pcs def1
+def1:
+
+/// .variant_pcs before binding directive.
+// ASM: .variant_pcs def2
+// ASM-NEXT: .weak def2
+// ASM-NEXT: def2:
+.variant_pcs def2
+.weak def2
+def2:
+
+.globl alias_def1
+.set alias_def1, def1
+
+// ASM: .variant_pcs undef
+.variant_pcs undef
+
+// OBJ: NOTYPE LOCAL DEFAULT [VARIANT_PCS] [[#]] local
+// OBJ-NEXT: NOTYPE GLOBAL DEFAULT [VARIANT_PCS] [[#]] def1
+// OBJ-NEXT: NOTYPE WEAK DEFAULT [VARIANT_PCS] [[#]] def2
+// OBJ-NEXT: NOTYPE GLOBAL DEFAULT [[#]] alias_def1
+// OBJ-NEXT: NOTYPE GLOBAL DEFAULT [VARIANT_PCS] UND undef
More information about the llvm-branch-commits
mailing list