Skip to content

Commit f9103d5

Browse files
committed
Process SHT_AARCH64_AUTH_RELR as target-specific section type
1 parent b0c9a28 commit f9103d5

File tree

6 files changed

+31
-33
lines changed

6 files changed

+31
-33
lines changed

llvm/lib/Object/ELF.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ StringRef llvm::object::getELFSectionTypeName(uint32_t Machine, unsigned Type) {
273273
break;
274274
case ELF::EM_AARCH64:
275275
switch (Type) {
276+
STRINGIFY_ENUM_CASE(ELF, SHT_AARCH64_AUTH_RELR);
276277
STRINGIFY_ENUM_CASE(ELF, SHT_AARCH64_MEMTAG_GLOBALS_DYNAMIC);
277278
STRINGIFY_ENUM_CASE(ELF, SHT_AARCH64_MEMTAG_GLOBALS_STATIC);
278279
}
@@ -299,7 +300,6 @@ StringRef llvm::object::getELFSectionTypeName(uint32_t Machine, unsigned Type) {
299300
STRINGIFY_ENUM_CASE(ELF, SHT_GROUP);
300301
STRINGIFY_ENUM_CASE(ELF, SHT_SYMTAB_SHNDX);
301302
STRINGIFY_ENUM_CASE(ELF, SHT_RELR);
302-
STRINGIFY_ENUM_CASE(ELF, SHT_AARCH64_AUTH_RELR);
303303
STRINGIFY_ENUM_CASE(ELF, SHT_ANDROID_REL);
304304
STRINGIFY_ENUM_CASE(ELF, SHT_ANDROID_RELA);
305305
STRINGIFY_ENUM_CASE(ELF, SHT_ANDROID_RELR);

llvm/lib/ObjectYAML/ELFYAML.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,6 @@ void ScalarEnumerationTraits<ELFYAML::ELF_SHT>::enumeration(
672672
ECase(SHT_GROUP);
673673
ECase(SHT_SYMTAB_SHNDX);
674674
ECase(SHT_RELR);
675-
ECase(SHT_AARCH64_AUTH_RELR);
676675
ECase(SHT_ANDROID_REL);
677676
ECase(SHT_ANDROID_RELA);
678677
ECase(SHT_ANDROID_RELR);
@@ -720,6 +719,7 @@ void ScalarEnumerationTraits<ELFYAML::ELF_SHT>::enumeration(
720719
ECase(SHT_MSP430_ATTRIBUTES);
721720
break;
722721
case ELF::EM_AARCH64:
722+
ECase(SHT_AARCH64_AUTH_RELR);
723723
ECase(SHT_AARCH64_MEMTAG_GLOBALS_STATIC);
724724
ECase(SHT_AARCH64_MEMTAG_GLOBALS_DYNAMIC);
725725
break;

llvm/test/tools/llvm-readobj/ELF/machine-specific-section-types.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@
5353
# MIPS-GNU: abiflags MIPS_ABIFLAGS
5454
# MIPS-GNU: dwarf MIPS_DWARF
5555

56+
# AARCH64-LLVM: Name: aarch64_auth_relr
57+
# AARCH64-LLVM: Type: SHT_AARCH64_AUTH_RELR
5658
# AARCH64-LLVM: Name: .memtag.globals.dynamic
5759
# AARCH64-LLVM: Type: SHT_AARCH64_MEMTAG_GLOBALS_DYNAMIC
5860
# AARCH64-LLVM: Name: .memtag.globals.static
5961
# AARCH64-LLVM: Type: SHT_AARCH64_MEMTAG_GLOBALS_STATIC
6062

63+
# AARCH64-GNU: aarch64_auth_relr AARCH64_AUTH_RELR
6164
# AARCH64-GNU: .memtag.globals.dynamic AARCH64_MEMTAG_GLOBALS_DYNAMIC
6265
# AARCH64-GNU: .memtag.globals.static AARCH64_MEMTAG_GLOBALS_STATIC
6366

@@ -113,6 +116,8 @@ FileHeader:
113116
Type: ET_REL
114117
Machine: EM_AARCH64
115118
Sections:
119+
- Name: aarch64_auth_relr
120+
Type: SHT_AARCH64_AUTH_RELR
116121
- Name: .memtag.globals.dynamic
117122
Type: SHT_AARCH64_MEMTAG_GLOBALS_DYNAMIC
118123
- Name: .memtag.globals.static

llvm/test/tools/llvm-readobj/ELF/relr-relocs.test

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,23 +186,18 @@ Sections:
186186
# RUN: llvm-readelf --relocations %t2.broken.android 2>&1 | \
187187
# RUN: FileCheck -DFILE=%t2.broken.android --check-prefix=BROKEN-GNU %s -DSECNAME=SHT_ANDROID_RELR
188188

189-
## Case C: check the case when relocations can't be read from an SHT_AARCH64_AUTH_RELR section.
189+
## Case C: check the case when we have an SHT_AARCH64_AUTH_RELR section in non-AArch64 ELF.
190190
## SHT_AARCH64_AUTH_RELR = 0x70000004.
191191
# RUN: yaml2obj --docnum=2 -DENTSIZE=1 -DSHTYPE=0x70000004 %s -o %t2.broken.aarch64auth
192192
# RUN: llvm-readobj --relocations %t2.broken.aarch64auth 2>&1 | \
193-
# RUN: FileCheck -DFILE=%t2.broken.aarch64auth --check-prefix=BROKEN-LLVM-AARCH64-AUTH %s -DSECNAME=SHT_AARCH64_AUTH_RELR
193+
# RUN: FileCheck -DFILE=%t2.broken.aarch64auth --check-prefix=WRONGARCH-LLVM-AARCH64-AUTH %s -DSECNAME=SHT_AARCH64_AUTH_RELR
194194
# RUN: llvm-readelf --relocations %t2.broken.aarch64auth 2>&1 | \
195-
# RUN: FileCheck -DFILE=%t2.broken.aarch64auth --check-prefix=BROKEN-GNU-AARCH64-AUTH %s -DSECNAME=SHT_AARCH64_AUTH_RELR
195+
# RUN: FileCheck -DFILE=%t2.broken.aarch64auth --check-prefix=WRONGARCH-GNU-AARCH64-AUTH %s -DSECNAME=SHT_AARCH64_AUTH_RELR
196196

197-
# BROKEN-LLVM-AARCH64-AUTH: Relocations [
198-
# BROKEN-LLVM-AARCH64-AUTH-NEXT: Section (1) .relr.dyn {
199-
# BROKEN-LLVM-AARCH64-AUTH-NEXT: warning: '[[FILE]]': SHT_AARCH64_AUTH_RELR section in non-AArch64 ELF found, skipping
200-
# BROKEN-LLVM-AARCH64-AUTH-NEXT: }
201-
# BROKEN-LLVM-AARCH64-AUTH-NEXT: ]
197+
# WRONGARCH-LLVM-AARCH64-AUTH: Relocations [
198+
# WRONGARCH-LLVM-AARCH64-AUTH-NEXT: ]
202199

203-
# BROKEN-GNU-AARCH64-AUTH: Relocation section '.relr.dyn' at offset 0x34 contains <?> entries:
204-
# BROKEN-GNU-AARCH64-AUTH-NEXT: Offset Info Type Sym. Value Symbol's Name
205-
# BROKEN-GNU-AARCH64-AUTH-NEXT: warning: '[[FILE]]': SHT_AARCH64_AUTH_RELR section in non-AArch64 ELF found, skipping
200+
# WRONGARCH-GNU-AARCH64-AUTH-NOT: Relocation section
206201

207202
## Check the behavior when the sh_link field of the SHT_RELR/SHT_ANDROID_RELR/SHT_AARCH64_AUTH_RELR section
208203
## is set to an arbitrary value. Normally, it is set to 0, because such sections contains

llvm/test/tools/llvm-readobj/ELF/section-types.test

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
# LLVM: Type: SHT_ANDROID_RELA
4444
# LLVM: Name: android_relr
4545
# LLVM: Type: SHT_ANDROID_RELR
46-
# LLVM: Name: aarch64_auth_relr
47-
# LLVM: Type: SHT_AARCH64_AUTH_RELR
4846
# LLVM: Name: llvm_odrtab
4947
# LLVM: Type: SHT_LLVM_ODRTAB
5048
# LLVM: Name: linker_options
@@ -115,7 +113,6 @@
115113
# GNU-NEXT: android_rel ANDROID_REL
116114
# GNU-NEXT: android_rela ANDROID_RELA
117115
# GNU-NEXT: android_relr ANDROID_RELR
118-
# GNU-NEXT: aarch64_auth_relr AARCH64_AUTH_RELR
119116
# GNU-NEXT: llvm_odrtab LLVM_ODRTAB
120117
# GNU-NEXT: linker_options LLVM_LINKER_OPTIONS
121118
# GNU-NEXT: llvm_call_graph_profile LLVM_CALL_GRAPH_PROFILE
@@ -194,8 +191,6 @@ Sections:
194191
Type: SHT_ANDROID_RELA
195192
- Name: android_relr
196193
Type: SHT_ANDROID_RELR
197-
- Name: aarch64_auth_relr
198-
Type: SHT_AARCH64_AUTH_RELR
199194
- Name: llvm_odrtab
200195
Type: SHT_LLVM_ODRTAB
201196
- Name: linker_options

llvm/tools/llvm-readobj/ELFDumper.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3816,10 +3816,12 @@ void GNUELFDumper<ELFT>::printRelRelaReloc(const Relocation<ELFT> &R,
38163816
}
38173817

38183818
template <class ELFT>
3819-
static void printRelocHeaderFields(formatted_raw_ostream &OS, unsigned SType) {
3819+
static void printRelocHeaderFields(formatted_raw_ostream &OS, unsigned SType,
3820+
const typename ELFT::Ehdr &EHeader) {
38203821
bool IsRela = SType == ELF::SHT_RELA || SType == ELF::SHT_ANDROID_RELA;
3821-
bool IsRelr = SType == ELF::SHT_RELR || SType == ELF::SHT_ANDROID_RELR ||
3822-
SType == ELF::SHT_AARCH64_AUTH_RELR;
3822+
bool IsRelr =
3823+
SType == ELF::SHT_RELR || SType == ELF::SHT_ANDROID_RELR ||
3824+
(EHeader.e_machine == EM_AARCH64 && SType == ELF::SHT_AARCH64_AUTH_RELR);
38233825
if (ELFT::Is64Bits)
38243826
OS << " ";
38253827
else
@@ -3844,16 +3846,18 @@ void GNUELFDumper<ELFT>::printDynamicRelocHeader(unsigned Type, StringRef Name,
38443846
uint64_t Offset = Reg.Addr - this->Obj.base();
38453847
OS << "\n'" << Name.str().c_str() << "' relocation section at offset 0x"
38463848
<< utohexstr(Offset, /*LowerCase=*/true) << " contains " << Reg.Size << " bytes:\n";
3847-
printRelocHeaderFields<ELFT>(OS, Type);
3849+
printRelocHeaderFields<ELFT>(OS, Type, this->Obj.getHeader());
38483850
}
38493851

38503852
template <class ELFT>
3851-
static bool isRelocationSec(const typename ELFT::Shdr &Sec) {
3853+
static bool isRelocationSec(const typename ELFT::Shdr &Sec,
3854+
const typename ELFT::Ehdr &EHeader) {
38523855
return Sec.sh_type == ELF::SHT_REL || Sec.sh_type == ELF::SHT_RELA ||
38533856
Sec.sh_type == ELF::SHT_RELR || Sec.sh_type == ELF::SHT_ANDROID_REL ||
38543857
Sec.sh_type == ELF::SHT_ANDROID_RELA ||
38553858
Sec.sh_type == ELF::SHT_ANDROID_RELR ||
3856-
Sec.sh_type == ELF::SHT_AARCH64_AUTH_RELR;
3859+
(EHeader.e_machine == EM_AARCH64 &&
3860+
Sec.sh_type == ELF::SHT_AARCH64_AUTH_RELR);
38573861
}
38583862

38593863
template <class ELFT> void GNUELFDumper<ELFT>::printRelocations() {
@@ -3871,7 +3875,8 @@ template <class ELFT> void GNUELFDumper<ELFT>::printRelocations() {
38713875

38723876
if (!opts::RawRelr &&
38733877
(Sec.sh_type == ELF::SHT_RELR || Sec.sh_type == ELF::SHT_ANDROID_RELR ||
3874-
Sec.sh_type == ELF::SHT_AARCH64_AUTH_RELR)) {
3878+
(this->Obj.getHeader().e_machine == EM_AARCH64 &&
3879+
Sec.sh_type == ELF::SHT_AARCH64_AUTH_RELR))) {
38753880
Expected<Elf_Relr_Range> RelrsOrErr = this->Obj.relrs(Sec);
38763881
if (!RelrsOrErr)
38773882
return RelrsOrErr.takeError();
@@ -3883,7 +3888,7 @@ template <class ELFT> void GNUELFDumper<ELFT>::printRelocations() {
38833888

38843889
bool HasRelocSections = false;
38853890
for (const Elf_Shdr &Sec : cantFail(this->Obj.sections())) {
3886-
if (!isRelocationSec<ELFT>(Sec))
3891+
if (!isRelocationSec<ELFT>(Sec, this->Obj.getHeader()))
38873892
continue;
38883893
HasRelocSections = true;
38893894

@@ -3900,7 +3905,7 @@ template <class ELFT> void GNUELFDumper<ELFT>::printRelocations() {
39003905
OS << "\nRelocation section '" << Name << "' at offset 0x"
39013906
<< utohexstr(Offset, /*LowerCase=*/true) << " contains " << EntriesNum
39023907
<< " entries:\n";
3903-
printRelocHeaderFields<ELFT>(OS, Sec.sh_type);
3908+
printRelocHeaderFields<ELFT>(OS, Sec.sh_type, this->Obj.getHeader());
39043909
this->printRelocationsHelper(Sec);
39053910
}
39063911
if (!HasRelocSections)
@@ -6235,7 +6240,8 @@ void ELFDumper<ELFT>::forEachRelocationDo(
62356240
// sh_link field as an index of a symbol table.
62366241
const Elf_Shdr *SymTab;
62376242
if (Sec.sh_type != ELF::SHT_RELR && Sec.sh_type != ELF::SHT_ANDROID_RELR &&
6238-
Sec.sh_type != ELF::SHT_AARCH64_AUTH_RELR) {
6243+
!(Obj.getHeader().e_machine == EM_AARCH64 &&
6244+
Sec.sh_type == ELF::SHT_AARCH64_AUTH_RELR)) {
62396245
Expected<const Elf_Shdr *> SymTabOrErr = Obj.getSection(Sec.sh_link);
62406246
if (!SymTabOrErr) {
62416247
Warn(SymTabOrErr.takeError(), "unable to locate a symbol table for");
@@ -6264,11 +6270,8 @@ void ELFDumper<ELFT>::forEachRelocationDo(
62646270
}
62656271
break;
62666272
case ELF::SHT_AARCH64_AUTH_RELR:
6267-
if (Obj.getHeader().e_machine != EM_AARCH64) {
6268-
this->reportUniqueWarning(
6269-
"SHT_AARCH64_AUTH_RELR section in non-AArch64 ELF found, skipping");
6273+
if (Obj.getHeader().e_machine != EM_AARCH64)
62706274
break;
6271-
}
62726275
[[fallthrough]];
62736276
case ELF::SHT_RELR:
62746277
case ELF::SHT_ANDROID_RELR: {
@@ -6966,7 +6969,7 @@ template <class ELFT> void LLVMELFDumper<ELFT>::printRelocations() {
69666969
ListScope D(W, "Relocations");
69676970

69686971
for (const Elf_Shdr &Sec : cantFail(this->Obj.sections())) {
6969-
if (!isRelocationSec<ELFT>(Sec))
6972+
if (!isRelocationSec<ELFT>(Sec, this->Obj.getHeader()))
69706973
continue;
69716974

69726975
StringRef Name = this->getPrintableSectionName(Sec);

0 commit comments

Comments
 (0)