Skip to content

Commit 4e53afa

Browse files
committed
Address several review comments
1 parent aff3a96 commit 4e53afa

File tree

5 files changed

+85
-93
lines changed

5 files changed

+85
-93
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -971,28 +971,27 @@ static void readAArch64PauthAbiTag(const InputSection &sec, ObjFile<ELFT> &f) {
971971
using Elf_Nhdr = typename ELFT::Nhdr;
972972
using Elf_Note = typename ELFT::Note;
973973
ArrayRef<uint8_t> data = sec.content();
974-
auto reportError = [&](const Twine &msg) {
975-
errorOrWarn(toString(sec.file) + ":(" + sec.name + "): " + msg);
976-
};
977974

978975
auto *nhdr = reinterpret_cast<const Elf_Nhdr *>(data.data());
979976
if (data.size() < sizeof(Elf_Nhdr) ||
980977
data.size() < nhdr->getSize(sec.addralign)) {
981-
reportError("section is too short");
978+
errorOrWarn(toString(&sec) + ": section is too short");
982979
return;
983980
}
984981

985982
Elf_Note note(*nhdr);
986983
if (nhdr->n_type != NT_ARM_TYPE_PAUTH_ABI_TAG)
987-
reportError("invalid type field value " + Twine(nhdr->n_type) + " (" +
988-
Twine(NT_ARM_TYPE_PAUTH_ABI_TAG) + " expected)");
984+
errorOrWarn(toString(&sec) + ": invalid type field value " +
985+
Twine(nhdr->n_type) + " (" + Twine(NT_ARM_TYPE_PAUTH_ABI_TAG) +
986+
" expected)");
989987
if (note.getName() != "ARM")
990-
reportError("invalid name field value " + note.getName() +
991-
" (ARM expected)");
988+
errorOrWarn(toString(&sec) + ": invalid name field value " +
989+
note.getName() + " (ARM expected)");
992990

993991
ArrayRef<uint8_t> desc = note.getDesc(sec.addralign);
994992
if (desc.size() < 16) {
995-
reportError("AArch64 PAuth compatibility info is too short "
993+
errorOrWarn(toString(&sec) +
994+
": AArch64 PAuth compatibility info is too short "
996995
"(at least 16 bytes expected)");
997996
return;
998997
}

lld/ELF/Relocations.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,8 +1194,9 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
11941194
}
11951195

11961196
if (config->emachine == EM_AARCH64 && type == R_AARCH64_AUTH_ABS64) {
1197-
error("relocation " + toString(type) + " against symbol '" + toString(sym) +
1198-
"'" + " in read-only section" + getLocation(*sec, sym, offset));
1197+
errorOrWarn("relocation " + toString(type) + " against symbol '" +
1198+
toString(sym) + "'" + " in read-only section" +
1199+
getLocation(*sec, sym, offset));
11991200
return;
12001201
}
12011202

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
# RUN: rm -rf %t && split-file %s %t && cd %t
44

5-
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu abi-tag1.s -o tag11.o
6-
# RUN: cp tag11.o tag12.o
7-
# RUN: ld.lld -shared tag11.o tag12.o -o tagok.so
5+
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu abi-tag1.s -o tag1.o
6+
# RUN: cp tag1.o tag1a.o
7+
# RUN: ld.lld -shared tag1.o tag1a.o -o tagok.so
88
# RUN: llvm-readelf -n tagok.so | FileCheck --check-prefix OK %s
99

1010
# OK: AArch64 PAuth ABI tag: platform 0x2a, version 0x1
1111

1212
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu abi-tag2.s -o tag2.o
13-
# RUN: not ld.lld tag11.o tag12.o tag2.o -o /dev/null 2>&1 | FileCheck --check-prefix ERR1 %s
13+
# RUN: not ld.lld tag1.o tag1a.o tag2.o -o /dev/null 2>&1 | FileCheck --check-prefix ERR1 %s
1414

1515
# ERR1: error: incompatible values of AArch64 PAuth compatibility info found
16-
# ERR1: tag11.o: 0x2A000000000000000{{1|2}}00000000000000
16+
# ERR1: tag1.o: 0x2A000000000000000{{1|2}}00000000000000
1717
# ERR1: tag2.o: 0x2A000000000000000{{1|2}}00000000000000
1818

1919
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu abi-tag-errs.s -o errs.o
@@ -30,15 +30,14 @@
3030

3131
# RUN: llvm-mc -filetype=obj -triple=aarch64-linux-gnu no-info.s -o noinfo1.o
3232
# RUN: cp noinfo1.o noinfo2.o
33-
# RUN: not ld.lld -z pauth-report=error tag11.o noinfo1.o noinfo2.o -o /dev/null 2>&1 | FileCheck --check-prefix ERR4 %s
34-
# RUN: ld.lld -z pauth-report=warning tag11.o noinfo1.o noinfo2.o -o /dev/null 2>&1 | FileCheck --check-prefix WARN %s
35-
# RUN: ld.lld -z pauth-report=none tag11.o noinfo1.o noinfo2.o -o /dev/null 2>&1 | FileCheck --check-prefix NONE %s
33+
# RUN: not ld.lld -z pauth-report=error tag1.o noinfo1.o noinfo2.o -o /dev/null 2>&1 | FileCheck --check-prefix ERR4 %s
34+
# RUN: ld.lld -z pauth-report=warning tag1.o noinfo1.o noinfo2.o -o /dev/null 2>&1 | FileCheck --check-prefix WARN %s
35+
# RUN: ld.lld -z pauth-report=none tag1.o noinfo1.o noinfo2.o --fatal-warnings -o /dev/null
3636

37-
# ERR4: error: noinfo1.o has no AArch64 PAuth compatibility info while tag11.o has one; either all or no input files must have it
38-
# ERR4-NEXT: error: noinfo2.o has no AArch64 PAuth compatibility info while tag11.o has one; either all or no input files must have it
39-
# WARN: warning: noinfo1.o has no AArch64 PAuth compatibility info while tag11.o has one; either all or no input files must have it
40-
# WARN-NEXT: warning: noinfo2.o has no AArch64 PAuth compatibility info while tag11.o has one; either all or no input files must have it
41-
# NONE-NOT: {{.*}} has no AArch64 PAuth compatibility info while {{.*}} has one; either all or no input files must have it
37+
# ERR4: error: noinfo1.o has no AArch64 PAuth compatibility info while tag1.o has one; either all or no input files must have it
38+
# ERR4-NEXT: error: noinfo2.o has no AArch64 PAuth compatibility info while tag1.o has one; either all or no input files must have it
39+
# WARN: warning: noinfo1.o has no AArch64 PAuth compatibility info while tag1.o has one; either all or no input files must have it
40+
# WARN-NEXT: warning: noinfo2.o has no AArch64 PAuth compatibility info while tag1.o has one; either all or no input files must have it
4241

4342
#--- abi-tag-short.s
4443

@@ -80,4 +79,8 @@
8079

8180
#--- no-info.s
8281

82+
.globl _start; // define _start to avoid missing entry warning and use --fatal-warnings to assert no diagnostic
83+
.weak _start; // allow multiple definitions of _start for simplicity
84+
_start:
85+
8386
.section ".test", "a"

lld/test/ELF/aarch64-reloc-pauth-ro.s

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
// REQUIRES: aarch64
1+
# REQUIRES: aarch64
22

3-
// RUN: llvm-mc -filetype=obj -triple=aarch64 %p/Inputs/shared2.s -o %t.so.o
4-
// RUN: ld.lld -shared %t.so.o -soname=so -o %t.so
5-
// RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o
6-
// RUN: not ld.lld -pie %t.o %t.so -o %t2 2>&1 | FileCheck -DFILE=%t %s
3+
# RUN: llvm-mc -filetype=obj -triple=aarch64 %p/Inputs/shared2.s -o %t.so.o
4+
# RUN: ld.lld -shared %t.so.o -soname=so -o %t.so
5+
# RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o
6+
# RUN: not ld.lld -pie %t.o %t.so -o %t2 2>&1 | FileCheck -DFILE=%t %s
77

8-
// CHECK: error: relocation R_AARCH64_AUTH_ABS64 against symbol 'zed2' in read-only section
9-
// CHECK-NEXT: defined in [[FILE]].so
10-
// CHECK-NEXT: referenced by [[FILE]].o:(.test+0x0)
8+
# CHECK: error: relocation R_AARCH64_AUTH_ABS64 against symbol 'zed2' in read-only section
9+
# CHECK-NEXT: defined in [[FILE]].so
10+
# CHECK-NEXT: referenced by [[FILE]].o:(.test+0x0)
1111

12-
// CHECK: error: relocation R_AARCH64_AUTH_ABS64 against symbol 'bar2' in read-only section
13-
// CHECK-NEXT: defined in [[FILE]].so
14-
// CHECK-NEXT: referenced by [[FILE]].o:(.test+0x8)
12+
# CHECK: error: relocation R_AARCH64_AUTH_ABS64 against symbol 'bar2' in read-only section
13+
# CHECK-NEXT: defined in [[FILE]].so
14+
# CHECK-NEXT: referenced by [[FILE]].o:(.test+0x8)
1515

1616
.section .test, "a"
1717
.p2align 3

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

Lines changed: 47 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,50 @@
1-
// REQUIRES: aarch64
2-
3-
// RUN: llvm-mc -filetype=obj -triple=aarch64 %p/Inputs/shared2.s -o %t.so.o
4-
// RUN: ld.lld -shared %t.so.o -soname=so -o %t.so
5-
// RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o
6-
// RUN: ld.lld -pie -z nopack-relative-relocs %t.o %t.so -o %t2
7-
// RUN: llvm-readobj -r %t2 | FileCheck --check-prefix=UNPACKED %s
8-
9-
// UNPACKED: Section ({{.+}}) .rela.dyn {
10-
// UNPACKED-NEXT: 0x303C8 R_AARCH64_AUTH_RELATIVE - 0x1
11-
// UNPACKED-NEXT: 0x303E1 R_AARCH64_AUTH_RELATIVE - 0x2
12-
// UNPACKED-NEXT: 0x303D0 R_AARCH64_AUTH_ABS64 zed2 0x0
13-
// UNPACKED-NEXT: 0x303D8 R_AARCH64_AUTH_ABS64 bar2 0x0
14-
// UNPACKED-NEXT: }
15-
16-
// RUN: ld.lld -pie -z pack-relative-relocs %t.o %t.so -o %t2
17-
// RUN: llvm-readobj -S --dynamic-table %t2 | FileCheck --check-prefix=RELR-HEADERS %s
18-
// RUN: llvm-readobj -r --raw-relr %t2 | FileCheck --check-prefix=RAW-RELR %s
19-
// RUN: llvm-readobj -r %t2 | FileCheck --check-prefix=RELR %s
20-
21-
// RELR-HEADERS: Index: 1
22-
// RELR-HEADERS-NEXT: Name: .dynsym
23-
24-
// RELR-HEADERS: Name: .relr.auth.dyn
25-
// RELR-HEADERS-NEXT: Type: SHT_AARCH64_AUTH_RELR
26-
// RELR-HEADERS-NEXT: Flags [ (0x2)
27-
// RELR-HEADERS-NEXT: SHF_ALLOC (0x2)
28-
// RELR-HEADERS-NEXT: ]
29-
// RELR-HEADERS-NEXT: Address: [[ADDR:.*]]
30-
// RELR-HEADERS-NEXT: Offset: [[ADDR]]
31-
// RELR-HEADERS-NEXT: Size: 8
32-
// RELR-HEADERS-NEXT: Link: 0
33-
// RELR-HEADERS-NEXT: Info: 0
34-
// RELR-HEADERS-NEXT: AddressAlignment: 8
35-
// RELR-HEADERS-NEXT: EntrySize: 8
36-
37-
// RELR-HEADERS: 0x0000000070000012 AARCH64_AUTH_RELR [[ADDR]]
38-
// RELR-HEADERS: 0x0000000070000011 AARCH64_AUTH_RELRSZ 8 (bytes)
39-
// RELR-HEADERS: 0x0000000070000013 AARCH64_AUTH_RELRENT 8 (bytes)
40-
41-
/// SHT_RELR section contains address/bitmap entries
42-
/// encoding the offsets for relative relocation.
43-
// RAW-RELR: Section ({{.+}}) .relr.auth.dyn {
44-
// RAW-RELR-NEXT: 0x303E8
45-
// RAW-RELR-NEXT: }
46-
47-
/// Decoded SHT_RELR section is same as UNPACKED,
48-
/// but contains only the relative relocations.
49-
/// Any relative relocations with odd offset stay in SHT_RELA.
50-
51-
// RELR: Section ({{.+}}) .rela.dyn {
52-
// RELR-NEXT: 0x30401 R_AARCH64_AUTH_RELATIVE - 0x2
53-
// RELR-NEXT: 0x303F0 R_AARCH64_AUTH_ABS64 zed2 0x0
54-
// RELR-NEXT: 0x303F8 R_AARCH64_AUTH_ABS64 bar2 0x0
55-
// RELR-NEXT: }
56-
// RELR-NEXT: Section ({{.+}}) .relr.auth.dyn {
57-
// RELR-NEXT: 0x303E8 R_AARCH64_RELATIVE -
58-
// RELR-NEXT: }
1+
# REQUIRES: aarch64
2+
3+
# RUN: llvm-mc -filetype=obj -triple=aarch64 %p/Inputs/shared2.s -o %t.so.o
4+
# RUN: ld.lld -shared %t.so.o -soname=so -o %t.so
5+
# RUN: llvm-mc -filetype=obj -triple=aarch64 %s -o %t.o
6+
# RUN: ld.lld -pie -z nopack-relative-relocs %t.o %t.so -o %t2
7+
# RUN: llvm-readobj -r %t2 | FileCheck --check-prefix=UNPACKED %s
8+
9+
# UNPACKED: Section ({{.+}}) .rela.dyn {
10+
# UNPACKED-NEXT: 0x303C8 R_AARCH64_AUTH_RELATIVE - 0x1
11+
# UNPACKED-NEXT: 0x303E1 R_AARCH64_AUTH_RELATIVE - 0x2
12+
# UNPACKED-NEXT: 0x303D0 R_AARCH64_AUTH_ABS64 zed2 0x0
13+
# UNPACKED-NEXT: 0x303D8 R_AARCH64_AUTH_ABS64 bar2 0x0
14+
# UNPACKED-NEXT: }
15+
16+
# RUN: ld.lld -pie -z pack-relative-relocs %t.o %t.so -o %t2
17+
# RUN: llvm-readelf -S --dynamic-table %t2 | FileCheck --check-prefix=RELR-HEADERS %s
18+
# RUN: llvm-readobj -r --raw-relr %t2 | FileCheck --check-prefix=RAW-RELR %s
19+
# RUN: llvm-readobj -r %t2 | FileCheck --check-prefix=RELR %s
20+
21+
# RELR-HEADERS: Section Headers:
22+
# RELR-HEADERS-NEXT: Name Type Address Off Size ES Flg Lk Inf Al
23+
# RELR-HEADERS: .relr.auth.dyn AARCH64_AUTH_RELR 0000000000[[ADDR:.*]] [[ADDR]] 000008 08 A 0 0 8
24+
25+
# RELR-HEADERS: Dynamic section at offset 0x2e8 contains 16 entries
26+
# RELR-HEADERS: 0x0000000070000012 (AARCH64_AUTH_RELR) 0x2e0
27+
# RELR-HEADERS-NEXT: 0x0000000070000011 (AARCH64_AUTH_RELRSZ) 8 (bytes)
28+
# RELR-HEADERS-NEXT: 0x0000000070000013 (AARCH64_AUTH_RELRENT) 8 (bytes)
29+
30+
## SHT_RELR section contains address/bitmap entries
31+
## encoding the offsets for relative relocation.
32+
# RAW-RELR: Section ({{.+}}) .relr.auth.dyn {
33+
# RAW-RELR-NEXT: 0x303E8
34+
# RAW-RELR-NEXT: }
35+
36+
## Decoded SHT_RELR section is same as UNPACKED,
37+
## but contains only the relative relocations.
38+
## Any relative relocations with odd offset stay in SHT_RELA.
39+
40+
# RELR: Section ({{.+}}) .rela.dyn {
41+
# RELR-NEXT: 0x30401 R_AARCH64_AUTH_RELATIVE - 0x2
42+
# RELR-NEXT: 0x303F0 R_AARCH64_AUTH_ABS64 zed2 0x0
43+
# RELR-NEXT: 0x303F8 R_AARCH64_AUTH_ABS64 bar2 0x0
44+
# RELR-NEXT: }
45+
# RELR-NEXT: Section ({{.+}}) .relr.auth.dyn {
46+
# RELR-NEXT: 0x303E8 R_AARCH64_RELATIVE -
47+
# RELR-NEXT: }
5948

6049
.section .test, "aw"
6150
.p2align 3

0 commit comments

Comments
 (0)