1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 20:23:11 +01:00

[yaml2obj] Handle NT_* string values in for ELF note types

This is required for D74393.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D95953
This commit is contained in:
Alex Richardson 2021-02-09 16:23:46 +00:00
parent 6da083491b
commit a58c63fcac
5 changed files with 144 additions and 18 deletions

View File

@ -1372,21 +1372,9 @@ enum {
// ElfXX_VerNeed structure version (GNU versioning) // ElfXX_VerNeed structure version (GNU versioning)
enum { VER_NEED_NONE = 0, VER_NEED_CURRENT = 1 }; enum { VER_NEED_NONE = 0, VER_NEED_CURRENT = 1 };
// SHT_NOTE section types // SHT_NOTE section types.
enum {
NT_FREEBSD_THRMISC = 7,
NT_FREEBSD_PROCSTAT_PROC = 8,
NT_FREEBSD_PROCSTAT_FILES = 9,
NT_FREEBSD_PROCSTAT_VMMAP = 10,
NT_FREEBSD_PROCSTAT_GROUPS = 11,
NT_FREEBSD_PROCSTAT_UMASK = 12,
NT_FREEBSD_PROCSTAT_RLIMIT = 13,
NT_FREEBSD_PROCSTAT_OSREL = 14,
NT_FREEBSD_PROCSTAT_PSSTRINGS = 15,
NT_FREEBSD_PROCSTAT_AUXV = 16,
};
// Generic note types // Generic note types.
enum : unsigned { enum : unsigned {
NT_VERSION = 1, NT_VERSION = 1,
NT_ARCH = 2, NT_ARCH = 2,
@ -1394,7 +1382,7 @@ enum : unsigned {
NT_GNU_BUILD_ATTRIBUTE_FUNC = 0x101, NT_GNU_BUILD_ATTRIBUTE_FUNC = 0x101,
}; };
// Core note types // Core note types.
enum : unsigned { enum : unsigned {
NT_PRSTATUS = 1, NT_PRSTATUS = 1,
NT_FPREGSET = 2, NT_FPREGSET = 2,
@ -1459,7 +1447,7 @@ enum {
NT_LLVM_HWASAN_GLOBALS = 3, NT_LLVM_HWASAN_GLOBALS = 3,
}; };
// GNU note types // GNU note types.
enum { enum {
NT_GNU_ABI_TAG = 1, NT_GNU_ABI_TAG = 1,
NT_GNU_HWCAP = 2, NT_GNU_HWCAP = 2,
@ -1528,6 +1516,20 @@ enum : unsigned {
GNU_PROPERTY_X86_FEATURE_2_XSAVEC = 1 << 9, GNU_PROPERTY_X86_FEATURE_2_XSAVEC = 1 << 9,
}; };
// FreeBSD core note types.
enum {
NT_FREEBSD_THRMISC = 7,
NT_FREEBSD_PROCSTAT_PROC = 8,
NT_FREEBSD_PROCSTAT_FILES = 9,
NT_FREEBSD_PROCSTAT_VMMAP = 10,
NT_FREEBSD_PROCSTAT_GROUPS = 11,
NT_FREEBSD_PROCSTAT_UMASK = 12,
NT_FREEBSD_PROCSTAT_RLIMIT = 13,
NT_FREEBSD_PROCSTAT_OSREL = 14,
NT_FREEBSD_PROCSTAT_PSSTRINGS = 15,
NT_FREEBSD_PROCSTAT_AUXV = 16,
};
// AMDGPU-specific section indices. // AMDGPU-specific section indices.
enum { enum {
SHN_AMDGPU_LDS = 0xff00, // Variable in LDS; symbol encoded like SHN_COMMON SHN_AMDGPU_LDS = 0xff00, // Variable in LDS; symbol encoded like SHN_COMMON

View File

@ -60,6 +60,7 @@ LLVM_YAML_STRONG_TYPEDEF(uint64_t, ELF_SHF)
LLVM_YAML_STRONG_TYPEDEF(uint16_t, ELF_SHN) LLVM_YAML_STRONG_TYPEDEF(uint16_t, ELF_SHN)
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STB) LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STB)
LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT) LLVM_YAML_STRONG_TYPEDEF(uint8_t, ELF_STT)
LLVM_YAML_STRONG_TYPEDEF(uint32_t, ELF_NT)
LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG) LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_AFL_REG)
LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP) LLVM_YAML_STRONG_TYPEDEF(uint8_t, MIPS_ABI_FP)
@ -171,7 +172,7 @@ struct StackSizeEntry {
struct NoteEntry { struct NoteEntry {
StringRef Name; StringRef Name;
yaml::BinaryRef Desc; yaml::BinaryRef Desc;
llvm::yaml::Hex32 Type; ELF_NT Type;
}; };
struct Chunk { struct Chunk {
@ -768,6 +769,10 @@ template <> struct ScalarEnumerationTraits<ELFYAML::ELF_PT> {
static void enumeration(IO &IO, ELFYAML::ELF_PT &Value); static void enumeration(IO &IO, ELFYAML::ELF_PT &Value);
}; };
template <> struct ScalarEnumerationTraits<ELFYAML::ELF_NT> {
static void enumeration(IO &IO, ELFYAML::ELF_NT &Value);
};
template <> template <>
struct ScalarEnumerationTraits<ELFYAML::ELF_EM> { struct ScalarEnumerationTraits<ELFYAML::ELF_EM> {
static void enumeration(IO &IO, ELFYAML::ELF_EM &Value); static void enumeration(IO &IO, ELFYAML::ELF_EM &Value);

View File

@ -70,6 +70,95 @@ void ScalarEnumerationTraits<ELFYAML::ELF_PT>::enumeration(
IO.enumFallback<Hex32>(Value); IO.enumFallback<Hex32>(Value);
} }
void ScalarEnumerationTraits<ELFYAML::ELF_NT>::enumeration(
IO &IO, ELFYAML::ELF_NT &Value) {
#define ECase(X) IO.enumCase(Value, #X, ELF::X)
// Generic note types.
ECase(NT_VERSION);
ECase(NT_ARCH);
ECase(NT_GNU_BUILD_ATTRIBUTE_OPEN);
ECase(NT_GNU_BUILD_ATTRIBUTE_FUNC);
// Core note types.
ECase(NT_PRSTATUS);
ECase(NT_FPREGSET);
ECase(NT_PRPSINFO);
ECase(NT_TASKSTRUCT);
ECase(NT_AUXV);
ECase(NT_PSTATUS);
ECase(NT_FPREGS);
ECase(NT_PSINFO);
ECase(NT_LWPSTATUS);
ECase(NT_LWPSINFO);
ECase(NT_WIN32PSTATUS);
ECase(NT_PPC_VMX);
ECase(NT_PPC_VSX);
ECase(NT_PPC_TAR);
ECase(NT_PPC_PPR);
ECase(NT_PPC_DSCR);
ECase(NT_PPC_EBB);
ECase(NT_PPC_PMU);
ECase(NT_PPC_TM_CGPR);
ECase(NT_PPC_TM_CFPR);
ECase(NT_PPC_TM_CVMX);
ECase(NT_PPC_TM_CVSX);
ECase(NT_PPC_TM_SPR);
ECase(NT_PPC_TM_CTAR);
ECase(NT_PPC_TM_CPPR);
ECase(NT_PPC_TM_CDSCR);
ECase(NT_386_TLS);
ECase(NT_386_IOPERM);
ECase(NT_X86_XSTATE);
ECase(NT_S390_HIGH_GPRS);
ECase(NT_S390_TIMER);
ECase(NT_S390_TODCMP);
ECase(NT_S390_TODPREG);
ECase(NT_S390_CTRS);
ECase(NT_S390_PREFIX);
ECase(NT_S390_LAST_BREAK);
ECase(NT_S390_SYSTEM_CALL);
ECase(NT_S390_TDB);
ECase(NT_S390_VXRS_LOW);
ECase(NT_S390_VXRS_HIGH);
ECase(NT_S390_GS_CB);
ECase(NT_S390_GS_BC);
ECase(NT_ARM_VFP);
ECase(NT_ARM_TLS);
ECase(NT_ARM_HW_BREAK);
ECase(NT_ARM_HW_WATCH);
ECase(NT_ARM_SVE);
ECase(NT_ARM_PAC_MASK);
ECase(NT_FILE);
ECase(NT_PRXFPREG);
ECase(NT_SIGINFO);
// LLVM-specific notes.
ECase(NT_LLVM_HWASAN_GLOBALS);
// GNU note types
ECase(NT_GNU_ABI_TAG);
ECase(NT_GNU_HWCAP);
ECase(NT_GNU_BUILD_ID);
ECase(NT_GNU_GOLD_VERSION);
ECase(NT_GNU_PROPERTY_TYPE_0);
// FreeBSD core note types.
ECase(NT_FREEBSD_THRMISC);
ECase(NT_FREEBSD_PROCSTAT_PROC);
ECase(NT_FREEBSD_PROCSTAT_FILES);
ECase(NT_FREEBSD_PROCSTAT_VMMAP);
ECase(NT_FREEBSD_PROCSTAT_GROUPS);
ECase(NT_FREEBSD_PROCSTAT_UMASK);
ECase(NT_FREEBSD_PROCSTAT_RLIMIT);
ECase(NT_FREEBSD_PROCSTAT_OSREL);
ECase(NT_FREEBSD_PROCSTAT_PSSTRINGS);
ECase(NT_FREEBSD_PROCSTAT_AUXV);
// AMD specific notes. (Code Object V2)
ECase(NT_AMD_AMDGPU_HSA_METADATA);
ECase(NT_AMD_AMDGPU_ISA);
ECase(NT_AMD_AMDGPU_PAL_METADATA);
// AMDGPU specific notes. (Code Object V3)
ECase(NT_AMDGPU_METADATA);
#undef ECase
IO.enumFallback<Hex32>(Value);
}
void ScalarEnumerationTraits<ELFYAML::ELF_EM>::enumeration( void ScalarEnumerationTraits<ELFYAML::ELF_EM>::enumeration(
IO &IO, ELFYAML::ELF_EM &Value) { IO &IO, ELFYAML::ELF_EM &Value) {
#define ECase(X) IO.enumCase(Value, #X, ELF::X) #define ECase(X) IO.enumCase(Value, #X, ELF::X)

View File

@ -303,3 +303,33 @@ Sections:
Type: SHT_NOTE Type: SHT_NOTE
Size: 0x1 Size: 0x1
Notes: [] Notes: []
## Check that we can use NT_* names for the note type.
# RUN: yaml2obj --docnum=15 %s -o %t15
# RUN: llvm-readobj --sections --section-data %t15 | FileCheck %s --check-prefix=TEXTUAL-TYPE
# TEXTUAL-TYPE: Name: .note.foo
# TEXTUAL-TYPE: SectionData (
# TEXTUAL-TYPE-NEXT: 0000: 03000000 00000000 03000000 41420000 |............AB..|
# TEXTUAL-TYPE-NEXT: 0010: 04000000 03000000 01000000 41424300 |............ABC.|
# TEXTUAL-TYPE-NEXT: 0020: 12345600 |.4V.|
# TEXTUAL-TYPE-NEXT: )
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
Sections:
- Name: .note.foo
Type: SHT_NOTE
Flags: [ SHF_ALLOC ]
Notes:
- Name: AB
Desc: ''
Type: NT_GNU_BUILD_ID
- Name: ABC
Desc: '123456'
Type: NT_VERSION

View File

@ -1191,7 +1191,7 @@ ELFDumper<ELFT>::dumpNoteSection(const Elf_Shdr *Shdr) {
Elf_Note Note(*Header); Elf_Note Note(*Header);
Entries.push_back( Entries.push_back(
{Note.getName(), Note.getDesc(), (llvm::yaml::Hex32)Note.getType()}); {Note.getName(), Note.getDesc(), (ELFYAML::ELF_NT)Note.getType()});
Content = Content.drop_front(Header->getSize()); Content = Content.drop_front(Header->getSize());
} }