Skip to content

Commit ac30a0f

Browse files
authored
[PAC][lld] Do not emit warnings for -z pac-plt with valid PAuth core info (#112959)
When PAuth core info is present and (platform,version) is not (0,0), treat input files as pac-enabled and do not emit a warning with `-z pac-plt` passed.
1 parent 7085ac8 commit ac30a0f

File tree

3 files changed

+62
-6
lines changed

3 files changed

+62
-6
lines changed

lld/ELF/Driver.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2792,6 +2792,8 @@ static void readSecurityNotes(Ctx &ctx) {
27922792
referenceFileName = (*it)->getName();
27932793
}
27942794
}
2795+
bool hasValidPauthAbiCoreInfo = llvm::any_of(
2796+
ctx.aarch64PauthAbiCoreInfo, [](uint8_t c) { return c != 0; });
27952797

27962798
for (ELFFileBase *f : ctx.objectFiles) {
27972799
uint32_t features = f->andFeatures;
@@ -2830,10 +2832,12 @@ static void readSecurityNotes(Ctx &ctx) {
28302832
"GNU_PROPERTY_X86_FEATURE_1_IBT property";
28312833
features |= GNU_PROPERTY_X86_FEATURE_1_IBT;
28322834
}
2833-
if (ctx.arg.zPacPlt && !(features & GNU_PROPERTY_AARCH64_FEATURE_1_PAC)) {
2835+
if (ctx.arg.zPacPlt && !(hasValidPauthAbiCoreInfo ||
2836+
(features & GNU_PROPERTY_AARCH64_FEATURE_1_PAC))) {
28342837
Warn(ctx) << f
28352838
<< ": -z pac-plt: file does not have "
2836-
"GNU_PROPERTY_AARCH64_FEATURE_1_PAC property";
2839+
"GNU_PROPERTY_AARCH64_FEATURE_1_PAC property and no valid "
2840+
"PAuth core info present for this link job";
28372841
features |= GNU_PROPERTY_AARCH64_FEATURE_1_PAC;
28382842
}
28392843
ctx.arg.andFeatures &= features;

lld/test/ELF/aarch64-feature-pac.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282

8383
# RUN: ld.lld %t.o %t2.o -z pac-plt %t.so -o %tpacplt.exe 2>&1 | FileCheck -DFILE=%t2.o --check-prefix WARN %s
8484

85-
# WARN: warning: [[FILE]]: -z pac-plt: file does not have GNU_PROPERTY_AARCH64_FEATURE_1_PAC property
85+
# WARN: warning: [[FILE]]: -z pac-plt: file does not have GNU_PROPERTY_AARCH64_FEATURE_1_PAC property and no valid PAuth core info present for this link job
8686

8787
# RUN: llvm-readelf -n %tpacplt.exe | FileCheck --check-prefix=PACPROP %s
8888
# RUN: llvm-readelf --dynamic-table %tpacplt.exe | FileCheck --check-prefix PACDYN2 %s

lld/test/ELF/aarch64-feature-pauth.s

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,53 @@
3333
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu no-info.s -o noinfo1.o
3434
# RUN: cp noinfo1.o noinfo2.o
3535
# RUN: not ld.lld -z pauth-report=error noinfo1.o tag1.o noinfo2.o -o /dev/null 2>&1 | FileCheck --check-prefix ERR5 %s
36-
# RUN: ld.lld -z pauth-report=warning noinfo1.o tag1.o noinfo2.o -o /dev/null 2>&1 | FileCheck --check-prefix WARN %s
36+
# RUN: ld.lld -z pauth-report=warning noinfo1.o tag1.o noinfo2.o -o /dev/null 2>&1 | FileCheck --check-prefix WARN1 %s
3737
# RUN: ld.lld -z pauth-report=none noinfo1.o tag1.o noinfo2.o --fatal-warnings -o /dev/null
3838

3939
# ERR5: error: noinfo1.o: -z pauth-report: file does not have AArch64 PAuth core info while 'tag1.o' has one
4040
# ERR5-NEXT: error: noinfo2.o: -z pauth-report: file does not have AArch64 PAuth core info while 'tag1.o' has one
41-
# WARN: warning: noinfo1.o: -z pauth-report: file does not have AArch64 PAuth core info while 'tag1.o' has one
42-
# WARN-NEXT: warning: noinfo2.o: -z pauth-report: file does not have AArch64 PAuth core info while 'tag1.o' has one
41+
# WARN1: warning: noinfo1.o: -z pauth-report: file does not have AArch64 PAuth core info while 'tag1.o' has one
42+
# WARN1-NEXT: warning: noinfo2.o: -z pauth-report: file does not have AArch64 PAuth core info while 'tag1.o' has one
43+
44+
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu abi-tag-zero.s -o tag-zero.o
45+
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-func2.s -o func2.o
46+
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-func3.s -o func3.o
47+
# RUN: ld.lld func3.o --shared -o func3.so
48+
# RUN: ld.lld tag1.o func2.o func3.so -z pac-plt --shared -o pacplt-nowarn --fatal-warnings
49+
# RUN: ld.lld tag-zero.o func2.o func3.so -z pac-plt --shared -o pacplt-warn 2>&1 | FileCheck --check-prefix WARN2 %s
50+
51+
# WARN2: warning: tag-zero.o: -z pac-plt: file does not have GNU_PROPERTY_AARCH64_FEATURE_1_PAC property and no valid PAuth core info present for this link job
52+
# WARN2-NEXT: warning: func2.o: -z pac-plt: file does not have GNU_PROPERTY_AARCH64_FEATURE_1_PAC property and no valid PAuth core info present for this link job
53+
54+
# RUN: llvm-readelf -d pacplt-nowarn | FileCheck --check-prefix=PACPLTTAG %s
55+
# RUN: llvm-readelf -d pacplt-warn | FileCheck --check-prefix=PACPLTTAG %s
56+
57+
# PACPLTTAG: 0x0000000070000003 (AARCH64_PAC_PLT)
58+
59+
# RUN: llvm-objdump -d pacplt-nowarn | FileCheck --check-prefix PACPLT -DA=10380 -DB=478 -DC=480 %s
60+
# RUN: llvm-objdump -d pacplt-warn | FileCheck --check-prefix PACPLT -DA=10390 -DB=488 -DC=490 %s
61+
62+
# PACPLT: Disassembly of section .text:
63+
# PACPLT: <func2>:
64+
# PACPLT-NEXT: bl 0x[[A]] <func3@plt>
65+
# PACPLT-NEXT: ret
66+
# PACPLT: Disassembly of section .plt:
67+
# PACPLT: <.plt>:
68+
# PACPLT-NEXT: stp x16, x30, [sp, #-0x10]!
69+
# PACPLT-NEXT: adrp x16, 0x30000 <func3+0x30000>
70+
# PACPLT-NEXT: ldr x17, [x16, #0x[[B]]]
71+
# PACPLT-NEXT: add x16, x16, #0x[[B]]
72+
# PACPLT-NEXT: br x17
73+
# PACPLT-NEXT: nop
74+
# PACPLT-NEXT: nop
75+
# PACPLT-NEXT: nop
76+
# PACPLT: <func3@plt>:
77+
# PACPLT-NEXT: adrp x16, 0x30000 <func3+0x30000>
78+
# PACPLT-NEXT: ldr x17, [x16, #0x[[C]]]
79+
# PACPLT-NEXT: add x16, x16, #0x[[C]]
80+
# PACPLT-NEXT: autia1716
81+
# PACPLT-NEXT: br x17
82+
# PACPLT-NEXT: nop
4383

4484
#--- abi-tag-short.s
4585

@@ -106,6 +146,18 @@
106146
.quad 42 // platform
107147
.quad 2 // version
108148

149+
#--- abi-tag-zero.s
150+
151+
.section ".note.gnu.property", "a"
152+
.long 4
153+
.long 24
154+
.long 5
155+
.asciz "GNU"
156+
.long 0xc0000001
157+
.long 16
158+
.quad 0 // platform
159+
.quad 0 // version
160+
109161
#--- no-info.s
110162

111163
## define _start to avoid missing entry warning and use --fatal-warnings to assert no diagnostic

0 commit comments

Comments
 (0)