Skip to content

Commit 57d7ff9

Browse files
committed
do not wrtie pauth data when both values are 0
1 parent 98dc05f commit 57d7ff9

File tree

5 files changed

+206
-53
lines changed

5 files changed

+206
-53
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -719,22 +719,23 @@ template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {
719719
if (!hasGnuProperties) {
720720
KnownAArch64BuildAttrSubsections subSections =
721721
extractBuildAttributesSubsections(attributes);
722-
auto serializeUnsigned = [&](unsigned value, size_t offset,
723-
bool isBE) {
724-
for (size_t i = 0; i < 8; ++i) {
725-
this->aarch64PauthAbiCoreInfoStorage[i + offset] =
726-
static_cast<uint8_t>((static_cast<uint64_t>(value) >>
727-
(8 * (isBE ? (7 - i) : i))) &
728-
0xFF);
722+
if (subSections.pauth.tagPlatform || subSections.pauth.tagSchema) {
723+
auto serializeUnsigned = [&](unsigned value, size_t offset,
724+
bool isBE) {
725+
for (size_t i = 0; i < 8; ++i) {
726+
this->aarch64PauthAbiCoreInfoStorage[i + offset] =
727+
static_cast<uint8_t>((static_cast<uint64_t>(value) >>
728+
(8 * (isBE ? (7 - i) : i))) &
729+
0xFF);
730+
};
729731
};
730-
};
731-
serializeUnsigned(subSections.pauth.tagPlatform, 0,
732-
ELFT::Endianness == llvm::endianness::big);
733-
serializeUnsigned(subSections.pauth.tagSchema, 8,
734-
ELFT::Endianness == llvm::endianness::big);
735-
this->aarch64PauthAbiCoreInfo =
736-
this->aarch64PauthAbiCoreInfoStorage;
737-
732+
serializeUnsigned(subSections.pauth.tagPlatform, 0,
733+
ELFT::Endianness == llvm::endianness::big);
734+
serializeUnsigned(subSections.pauth.tagSchema, 8,
735+
ELFT::Endianness == llvm::endianness::big);
736+
this->aarch64PauthAbiCoreInfo =
737+
this->aarch64PauthAbiCoreInfoStorage;
738+
}
738739
this->andFeatures = 0;
739740
this->andFeatures |= (subSections.fAndB.tagBTI) << 0;
740741
this->andFeatures |= (subSections.fAndB.tagPAC) << 1;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This file replace gnu properties with aarch64 build attributes.
2+
3+
.aeabi_subsection aeabi_feature_and_bits, optional, uleb128
4+
.aeabi_attribute Tag_Feature_PAC, 1
5+
6+
.text
7+
.globl func3
8+
.type func3,@function
9+
func3:
10+
ret
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This file replace gnu properties with aarch64 build attributes.
2+
3+
.aeabi_subsection aeabi_feature_and_bits, optional, uleb128
4+
.aeabi_attribute Tag_Feature_PAC, 1
5+
6+
.text
7+
.globl func2
8+
.type func2,@function
9+
func2:
10+
.globl func3
11+
.type func3, @function
12+
bl func3
13+
ret
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
### This file replace .note.gnu.property with aarch64 build attributes in order to confirm
2+
### interoperability.
3+
4+
# REQUIRES: aarch64
5+
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %s -o %t.o
6+
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-pac1-replace.s -o %t1.o
7+
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-func3.s -o %t2.o
8+
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-func3-pac-replace.s -o %t3.o
9+
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %p/Inputs/aarch64-func2.s -o %tno.o
10+
11+
## We do not add PAC support when the inputs don't have the .note.gnu.property
12+
## field.
13+
14+
# RUN: ld.lld %tno.o %t3.o --shared -o %tno.so
15+
# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+v8.3a --no-show-raw-insn %tno.so | FileCheck --check-prefix=NOPAC %s
16+
# RUN: llvm-readelf -x .got.plt %tno.so | FileCheck --check-prefix SOGOTPLT %s
17+
# RUN: llvm-readelf --dynamic-table %tno.so | FileCheck --check-prefix NOPACDYN %s
18+
19+
# NOPAC: 00000000000102b8 <func2>:
20+
# NOPAC-NEXT: 102b8: bl 0x102f0 <func3@plt>
21+
# NOPAC-NEXT: ret
22+
# NOPAC: Disassembly of section .plt:
23+
# NOPAC: 00000000000102d0 <.plt>:
24+
# NOPAC-NEXT: 102d0: stp x16, x30, [sp, #-16]!
25+
# NOPAC-NEXT: adrp x16, 0x30000
26+
# NOPAC-NEXT: ldr x17, [x16, #960]
27+
# NOPAC-NEXT: add x16, x16, #960
28+
# NOPAC-NEXT: br x17
29+
# NOPAC-NEXT: nop
30+
# NOPAC-NEXT: nop
31+
# NOPAC-NEXT: nop
32+
# NOPAC: 00000000000102f0 <func3@plt>:
33+
# NOPAC-NEXT: 102f0: adrp x16, 0x30000
34+
# NOPAC-NEXT: ldr x17, [x16, #968]
35+
# NOPAC-NEXT: add x16, x16, #968
36+
# NOPAC-NEXT: br x17
37+
38+
# SOGOTPLT: Hex dump of section '.got.plt':
39+
# SOGOTPLT-NEXT: 0x000303b0 00000000 00000000 00000000 00000000
40+
# SOGOTPLT-NEXT: 0x000303c0 00000000 00000000 d0020100 00000000
41+
42+
# NOPACDYN-NOT: 0x0000000070000001 (AARCH64_BTI_PLT)
43+
# NOPACDYN-NOT: 0x0000000070000003 (AARCH64_PAC_PLT)
44+
45+
46+
# RUN: ld.lld %t1.o %t3.o --shared --soname=t.so -o %t.so
47+
# RUN: llvm-readelf -n %t.so | FileCheck --check-prefix PACPROP %s
48+
# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+v8.3a --no-show-raw-insn %t.so | FileCheck --check-prefix PACSO %s
49+
# RUN: llvm-readelf -x .got.plt %t.so | FileCheck --check-prefix SOGOTPLT2 %s
50+
# RUN: llvm-readelf --dynamic-table %t.so | FileCheck --check-prefix PACDYN %s
51+
52+
# PACPROP: Properties: aarch64 feature: PAC
53+
54+
# PACSO: Disassembly of section .text:
55+
# PACSO: 0000000000010348 <func2>:
56+
# PACSO-NEXT: 10348: bl 0x10380 <func3@plt>
57+
# PACSO-NEXT: 1034c: ret
58+
# PACSO: 0000000000010350 <func3>:
59+
# PACSO-NEXT: 10350: ret
60+
# PACSO: Disassembly of section .plt:
61+
# PACSO: 0000000000010360 <.plt>:
62+
# PACSO-NEXT: 10360: stp x16, x30, [sp, #-16]!
63+
# PACSO-NEXT: 10364: adrp x16, 0x30000
64+
# PACSO-NEXT: 10368: ldr x17, [x16, #1120]
65+
# PACSO-NEXT: 1036c: add x16, x16, #1120
66+
# PACSO-NEXT: 10370: br x17
67+
# PACSO-NEXT: 10374: nop
68+
# PACSO-NEXT: 10378: nop
69+
# PACSO-NEXT: 1037c: nop
70+
# PACSO: 0000000000010380 <func3@plt>:
71+
# PACSO-NEXT: 10380: adrp x16, 0x30000
72+
# PACSO-NEXT: 10384: ldr x17, [x16, #1128]
73+
# PACSO-NEXT: 10388: add x16, x16, #1128
74+
# PACSO-NEXT: 1038c: br x17
75+
76+
# SOGOTPLT2: Hex dump of section '.got.plt':
77+
# SOGOTPLT2-NEXT: 0x00030450 00000000 00000000 00000000 00000000
78+
# SOGOTPLT2-NEXT: 0x00030460 00000000 00000000 60030100 00000000
79+
80+
# PACDYN-NOT: 0x0000000070000001 (AARCH64_BTI_PLT)
81+
# PACDYN-NOT: 0x0000000070000003 (AARCH64_PAC_PLT)
82+
83+
84+
# 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
85+
86+
# 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
87+
88+
89+
# RUN: llvm-readelf -n %tpacplt.exe | FileCheck --check-prefix=PACPROP %s
90+
# RUN: llvm-readelf --dynamic-table %tpacplt.exe | FileCheck --check-prefix PACDYN2 %s
91+
# RUN: llvm-objdump --no-print-imm-hex -d --mattr=+v8.3a --no-show-raw-insn %tpacplt.exe | FileCheck --check-prefix PACPLT %s
92+
93+
# PACDYN2-NOT: 0x0000000070000001 (AARCH64_BTI_PLT)
94+
# PACDYN2: 0x0000000070000003 (AARCH64_PAC_PLT)
95+
96+
# PACPLT: Disassembly of section .text:
97+
# PACPLT: 0000000000210370 <func1>:
98+
# PACPLT-NEXT: 210370: bl 0x2103a0 <func2@plt>
99+
# PACPLT-NEXT: ret
100+
# PACPLT: 0000000000210378 <func3>:
101+
# PACPLT-NEXT: 210378: ret
102+
# PACPLT: Disassembly of section .plt:
103+
# PACPLT: 0000000000210380 <.plt>:
104+
# PACPLT-NEXT: 210380: stp x16, x30, [sp, #-16]!
105+
# PACPLT-NEXT: adrp x16, 0x230000
106+
# PACPLT-NEXT: ldr x17, [x16, #1192]
107+
# PACPLT-NEXT: add x16, x16, #1192
108+
# PACPLT-NEXT: br x17
109+
# PACPLT-NEXT: nop
110+
# PACPLT-NEXT: nop
111+
# PACPLT-NEXT: nop
112+
# PACPLT: 00000000002103a0 <func2@plt>:
113+
# PACPLT-NEXT: 2103a0: adrp x16, 0x230000
114+
# PACPLT-NEXT: ldr x17, [x16, #1200]
115+
# PACPLT-NEXT: add x16, x16, #1200
116+
# PACPLT-NEXT: autia1716
117+
# PACPLT-NEXT: br x17
118+
# PACPLT-NEXT: nop
119+
120+
121+
.aeabi_subsection aeabi_feature_and_bits, optional, uleb128
122+
.aeabi_attribute Tag_Feature_BTI, 0
123+
.aeabi_attribute Tag_Feature_PAC, 1
124+
.aeabi_attribute Tag_Feature_GCS, 0
125+
126+
.text
127+
.globl _start
128+
.type func1,%function
129+
func1:
130+
bl func2
131+
ret

lld/test/ELF/aarch64-feature-pac-replace.s renamed to lld/test/ELF/aarch64-feature-pac-replace-one.s

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### This file replace .note.gnu.property with aarch64 build attributes in order to confirm
22
### interoperability.
3+
### (Still using gnu properties in the helper files)
34

45
# REQUIRES: aarch64
56
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu %s -o %t.o
@@ -16,27 +17,24 @@
1617
# RUN: llvm-readelf -x .got.plt %tno.so | FileCheck --check-prefix SOGOTPLT %s
1718
# RUN: llvm-readelf --dynamic-table %tno.so | FileCheck --check-prefix NOPACDYN %s
1819

19-
# NOPAC: Disassembly of section .text:
2020
# NOPAC: 00000000000102b8 <func2>:
21-
# NOPAC-NEXT: 102b8: bl 0x102f0 <func3@plt>
22-
# NOPAC-NEXT: 102bc: ret
23-
# NOPAC: 00000000000102c0 <func3>:
24-
# NOPAC-NEXT: 102c0: ret
21+
# NOPAC-NEXT: 102b8: bl 0x102f0 <func3@plt>
22+
# NOPAC-NEXT: ret
2523
# NOPAC: Disassembly of section .plt:
2624
# NOPAC: 00000000000102d0 <.plt>:
27-
# NOPAC-NEXT: 102d0: stp x16, x30, [sp, #-16]!
28-
# NOPAC-NEXT: 102d4: adrp x16, 0x30000
29-
# NOPAC-NEXT: 102d8: ldr x17, [x16, #960]
30-
# NOPAC-NEXT: 102dc: add x16, x16, #960
31-
# NOPAC-NEXT: 102e0: br x17
32-
# NOPAC-NEXT: 102e4: nop
33-
# NOPAC-NEXT: 102e8: nop
34-
# NOPAC-NEXT: 102ec: nop
25+
# NOPAC-NEXT: 102d0: stp x16, x30, [sp, #-16]!
26+
# NOPAC-NEXT: adrp x16, 0x30000
27+
# NOPAC-NEXT: ldr x17, [x16, #960]
28+
# NOPAC-NEXT: add x16, x16, #960
29+
# NOPAC-NEXT: br x17
30+
# NOPAC-NEXT: nop
31+
# NOPAC-NEXT: nop
32+
# NOPAC-NEXT: nop
3533
# NOPAC: 00000000000102f0 <func3@plt>:
36-
# NOPAC-NEXT: 102f0: adrp x16, 0x30000
37-
# NOPAC-NEXT: 102f4: ldr x17, [x16, #968]
38-
# NOPAC-NEXT: 102f8: add x16, x16, #968
39-
# NOPAC-NEXT: 102fc: br x17
34+
# NOPAC-NEXT: 102f0: adrp x16, 0x30000
35+
# NOPAC-NEXT: ldr x17, [x16, #968]
36+
# NOPAC-NEXT: add x16, x16, #968
37+
# NOPAC-NEXT: br x17
4038

4139
# SOGOTPLT: Hex dump of section '.got.plt':
4240
# SOGOTPLT-NEXT: 0x000303b0 00000000 00000000 00000000 00000000
@@ -97,28 +95,28 @@
9795
# PACDYN2: 0x0000000070000003 (AARCH64_PAC_PLT)
9896

9997
# PACPLT: Disassembly of section .text:
100-
# PACPLT: 0000000000210388 <func1>:
101-
# PACPLT-NEXT: 210388: bl 0x2103c0 <func2@plt>
102-
# PACPLT-NEXT: 21038c: ret
103-
# PACPLT: 0000000000210390 <func3>:
104-
# PACPLT-NEXT: 210390: ret
98+
# PACPLT: 0000000000210370 <func1>:
99+
# PACPLT-NEXT: 210370: bl 0x2103a0 <func2@plt>
100+
# PACPLT-NEXT: ret
101+
# PACPLT: 0000000000210378 <func3>:
102+
# PACPLT-NEXT: 210378: ret
105103
# PACPLT: Disassembly of section .plt:
106-
# PACPLT: 00000000002103a0 <.plt>:
107-
# PACPLT-NEXT: 2103a0: stp x16, x30, [sp, #-16]!
108-
# PACPLT-NEXT: 2103a4: adrp x16, 0x230000 <func2+0x230000>
109-
# PACPLT-NEXT: 2103a8: ldr x17, [x16, #1224]
110-
# PACPLT-NEXT: 2103ac: add x16, x16, #1224
111-
# PACPLT-NEXT: 2103b0: br x17
112-
# PACPLT-NEXT: 2103b4: nop
113-
# PACPLT-NEXT: 2103b8: nop
114-
# PACPLT-NEXT: 2103bc: nop
115-
# PACPLT: 00000000002103c0 <func2@plt>:
116-
# PACPLT-NEXT: 2103c0: adrp x16, 0x230000 <func2+0x230000>
117-
# PACPLT-NEXT: 2103c4: ldr x17, [x16, #1232]
118-
# PACPLT-NEXT: 2103c8: add x16, x16, #1232
119-
# PACPLT-NEXT: 2103cc: autia1716
120-
# PACPLT-NEXT: 2103d0: br x17
121-
# PACPLT-NEXT: 2103d4: nop
104+
# PACPLT: 0000000000210380 <.plt>:
105+
# PACPLT-NEXT: 210380: stp x16, x30, [sp, #-16]!
106+
# PACPLT-NEXT: adrp x16, 0x230000
107+
# PACPLT-NEXT: ldr x17, [x16, #1192]
108+
# PACPLT-NEXT: add x16, x16, #1192
109+
# PACPLT-NEXT: br x17
110+
# PACPLT-NEXT: nop
111+
# PACPLT-NEXT: nop
112+
# PACPLT-NEXT: nop
113+
# PACPLT: 00000000002103a0 <func2@plt>:
114+
# PACPLT-NEXT: 2103a0: adrp x16, 0x230000
115+
# PACPLT-NEXT: ldr x17, [x16, #1200]
116+
# PACPLT-NEXT: add x16, x16, #1200
117+
# PACPLT-NEXT: autia1716
118+
# PACPLT-NEXT: br x17
119+
# PACPLT-NEXT: nop
122120

123121

124122
.aeabi_subsection aeabi_feature_and_bits, optional, uleb128

0 commit comments

Comments
 (0)