llvm.org GIT mirror llvm / 28ef347
[AArch64][ELF][llvm-readobj] Add support for BTI and PAC dynamic tags ELF for the 64-bit Arm Architecture defines two processor-specific dynamic tags: DT_AARCH64_BTI_PLT 0x70000001, d_val DT_AARCH64_PAC_PLT 0x70000003, d_val These presence of these tags indicate that PLT sequences have been protected using Branch Target Identification and Pointer Authentication respectively. The presence of both indicates that the PLT sequences have been protected with both Branch Target Identification and Pointer Authentication. This patch adds the tags and tests for llvm-readobj and yaml2obj. As some of the processor specific dynamic tags overlap, this patch splits them up, keeping their original default value if they were not previously mentioned explicitly in a switch case. Differential Revision: https://reviews.llvm.org/D62596 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362493 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Smith 2 months ago
7 changed file(s) with 217 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
44 // Add separate macros for the architecture specific tags and the markers
55 // such as DT_HIOS, etc. to allow using this file to in other contexts.
66 // For example we can use it to generate a stringification switch statement.
7
8 #ifndef AARCH64_DYNAMIC_TAG
9 #define AARCH64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
10 #define AARCH64_DYNAMIC_TAG_DEFINED
11 #endif
712
813 #ifndef HEXAGON_DYNAMIC_TAG
914 #define HEXAGON_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
105110 DYNAMIC_TAG(VERNEED, 0X6FFFFFFE) // The address of the version dependency
106111 // table.
107112 DYNAMIC_TAG(VERNEEDNUM, 0X6FFFFFFF) // The number of entries in DT_VERNEED.
113
114 // AArch64 specific dynamic table entries
115 AARCH64_DYNAMIC_TAG(AARCH64_BTI_PLT, 0x70000001)
116 AARCH64_DYNAMIC_TAG(AARCH64_PAC_PLT, 0x70000003)
108117
109118 // Hexagon specific dynamic table entries
110119 HEXAGON_DYNAMIC_TAG(HEXAGON_SYMSZ, 0x70000000)
203212 #undef DYNAMIC_TAG_MARKER
204213 #undef DYNAMIC_TAG_MARKER_DEFINED
205214 #endif
215 #ifdef AARCH64_DYNAMIC_TAG_DEFINED
216 #undef AARCH64_DYNAMIC_TAG
217 #undef AARCH64_DYNAMIC_TAG_DEFINED
218 #endif
206219 #ifdef MIPS_DYNAMIC_TAG_DEFINED
207220 #undef MIPS_DYNAMIC_TAG
208221 #undef MIPS_DYNAMIC_TAG_DEFINED
433433
434434 #define DYNAMIC_TAG(n, v)
435435 switch (Arch) {
436 case ELF::EM_AARCH64:
437 switch (Type) {
438 #define AARCH64_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value)
439 #include "llvm/BinaryFormat/DynamicTags.def"
440 #undef AARCH64_DYNAMIC_TAG
441 }
442 break;
443
436444 case ELF::EM_HEXAGON:
437445 switch (Type) {
438446 #define HEXAGON_DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value)
460468 #undef DYNAMIC_TAG
461469 switch (Type) {
462470 // Now handle all dynamic tags except the architecture specific ones
471 #define AARCH64_DYNAMIC_TAG(name, value)
463472 #define MIPS_DYNAMIC_TAG(name, value)
464473 #define HEXAGON_DYNAMIC_TAG(name, value)
465474 #define PPC64_DYNAMIC_TAG(name, value)
468477 #define DYNAMIC_TAG(name, value) DYNAMIC_STRINGIFY_ENUM(name, value)
469478 #include "llvm/BinaryFormat/DynamicTags.def"
470479 #undef DYNAMIC_TAG
480 #undef AARCH64_DYNAMIC_TAG
471481 #undef MIPS_DYNAMIC_TAG
472482 #undef HEXAGON_DYNAMIC_TAG
473483 #undef PPC64_DYNAMIC_TAG
679679 assert(Object && "The IO context is not initialized");
680680
681681 // Disable architecture specific tags by default. We might enable them below.
682 #define AARCH64_DYNAMIC_TAG(name, value)
682683 #define MIPS_DYNAMIC_TAG(name, value)
683684 #define HEXAGON_DYNAMIC_TAG(name, value)
684685 #define PPC64_DYNAMIC_TAG(name, value)
688689 #define STRINGIFY(X) (#X)
689690 #define DYNAMIC_TAG(X, Y) IO.enumCase(Value, STRINGIFY(DT_##X), ELF::DT_##X);
690691 switch (Object->Header.Machine) {
692 case ELF::EM_AARCH64:
693 #undef AARCH64_DYNAMIC_TAG
694 #define AARCH64_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
695 #include "llvm/BinaryFormat/DynamicTags.def"
696 #undef AARCH64_DYNAMIC_TAG
697 #define AARCH64_DYNAMIC_TAG(name, value)
698 break;
691699 case ELF::EM_MIPS:
692700 #undef MIPS_DYNAMIC_TAG
693701 #define MIPS_DYNAMIC_TAG(name, value) DYNAMIC_TAG(name, value)
713721 #include "llvm/BinaryFormat/DynamicTags.def"
714722 break;
715723 }
716
724 #undef AARCH64_DYNAMIC_TAG
717725 #undef MIPS_DYNAMIC_TAG
718726 #undef HEXAGON_DYNAMIC_TAG
719727 #undef PPC64_DYNAMIC_TAG
199199 VAddr: 0x1010
200200 Sections:
201201 - Section: .dynamic
202
203 # Fourth document: AARCH64
204 --- !ELF
205 FileHeader:
206 Class: ELFCLASS64
207 Data: ELFDATA2LSB
208 Type: ET_EXEC
209 Machine: EM_AARCH64
210 Sections:
211 - Name: .dynstr
212 Type: SHT_STRTAB
213 Address: 0x1000
214 Size: 0x10
215 Content: "004400550066007700"
216 - Name: .dynamic
217 Type: SHT_DYNAMIC
218 Address: 0x1010
219 Entries:
220 - Tag: DT_HASH
221 Value: 0x1000
222 - Tag: DT_AARCH64_BTI_PLT
223 Value: 0
224 - Tag: DT_AARCH64_PAC_PLT
225 Value: 0
226 - Tag: 0x1234abcd
227 Value: 0x1
228 - Tag: DT_NULL
229 Value: 0
230 ProgramHeaders:
231 - Type: PT_LOAD
232 VAddr: 0x1000
233 Sections:
234 - Section: .dynstr
235 - Section: .dynamic
236 - Type: PT_DYNAMIC
237 VAddr: 0x1010
238 Sections:
239 - Section: .dynamic
150150 # GNU-PPC-NEXT: 0x0000000070000000 (PPC64_GLINK) 0x1000
151151 # GNU-PPC-NEXT: 0x000000001234abcd (unknown) 0x1
152152 # GNU-PPC-NEXT: 0x0000000000000000 (NULL) 0x0
153
154 # Test that AARCH64 machine-specific tags can be dumped.
155 # RUN: yaml2obj --docnum=4 %S/Inputs/elf-dynamic-tags-machine-specific.yaml -o %t.aarch64
156 # RUN: llvm-readobj --dynamic-table %t.aarch64 | FileCheck %s --check-prefix=LLVM-AARCH64
157 # RUN: llvm-readelf --dynamic-table %t.aarch64 | FileCheck %s --check-prefix=GNU-AARCH64
158
159 # LLVM-AARCH64: DynamicSection [ (5 entries)
160 # LLVM-AARCH64-NEXT: Tag Type Name/Value
161 # LLVM-AARCH64-NEXT: 0x0000000000000004 HASH 0x1000
162 # LLVM-AARCH64-NEXT: 0x0000000070000001 AARCH64_BTI_PLT 0
163 # LLVM-AARCH64-NEXT: 0x0000000070000003 AARCH64_PAC_PLT 0
164 # LLVM-AARCH64-NEXT: 0x000000001234ABCD unknown 0x1
165 # LLVM-AARCH64-NEXT: 0x0000000000000000 NULL 0x0
166 # LLVM-AARCH64-NEXT:]
167
168 # GNU-AARCH64: Dynamic section at offset {{.*}} contains 5 entries:
169 # GNU-AARCH64-NEXT: Tag Type Name/Value
170 # GNU-AARCH64-NEXT: 0x0000000000000004 (HASH) 0x1000
171 # GNU-AARCH64-NEXT: 0x0000000070000001 (AARCH64_BTI_PLT) 0
172 # GNU-AARCH64-NEXT: 0x0000000070000003 (AARCH64_PAC_PLT) 0
173 # GNU-AARCH64-NEXT: 0x000000001234abcd (unknown) 0x1
174 # GNU-AARCH64-NEXT: 0x0000000000000000 (NULL) 0x0
248248 - Tag: DT_PPC64_GLINK
249249 Value: 0x0000000000000001
250250
251 ## Check we can handle AARCH64 specific tags.
252 # RUN: yaml2obj -docnum=4 %s -o %t2
253 # RUN: obj2yaml %t2 | FileCheck %s --check-prefix=AARCH64
254
255 # AARCH64: - Tag: DT_AARCH64_BTI_PLT
256 # AARCH64-NEXT: Value: 0x0000000000000000
257 # AARCH64-NEXT: - Tag: DT_AARCH64_PAC_PLT
258 # AARCH64-NEXT: Value: 0x0000000000000000
259
260 --- !ELF
261 FileHeader:
262 Class: ELFCLASS64
263 Data: ELFDATA2LSB
264 Type: ET_REL
265 Machine: EM_AARCH64
266 Sections:
267 - Name: .dynamic
268 Type: SHT_DYNAMIC
269 Entries:
270 - Tag: DT_AARCH64_BTI_PLT
271 Value: 0x0000000000000000
272 - Tag: DT_AARCH64_PAC_PLT
273 Value: 0x0000000000000000
274
251275 ## Check we can't use a tag from a different architecture,
252276 ## even if it has the same numeric value as a valid tag.
253277 ## Here for EM_PPC64 we are trying to use DT_HEXAGON_SYMSZ
254278 ## instead of DT_PPC64_GLINK. They both have value of 0x70000000.
255279
256 # RUN: not yaml2obj -docnum=4 %s 2>&1 | FileCheck %s --check-prefix=ERR
280 # RUN: not yaml2obj -docnum=5 %s 2>&1 | FileCheck %s --check-prefix=ERR
257281 # ERR: error: invalid hex64 number
258282 # ERR-NEXT: - Tag: DT_HEXAGON_SYMSZ
259283
14621462 static const char *getTypeString(unsigned Arch, uint64_t Type) {
14631463 #define DYNAMIC_TAG(n, v)
14641464 switch (Arch) {
1465
1466 case EM_AARCH64:
1467 switch (Type) {
1468 #define AARCH64_DYNAMIC_TAG(name, value) \
1469 case DT_##name: \
1470 return #name;
1471 #include "llvm/BinaryFormat/DynamicTags.def"
1472 #undef AARCH64_DYNAMIC_TAG
1473 }
1474 break;
1475
14651476 case EM_HEXAGON:
14661477 switch (Type) {
14671478 #define HEXAGON_DYNAMIC_TAG(name, value) \
14951506 #undef DYNAMIC_TAG
14961507 switch (Type) {
14971508 // Now handle all dynamic tags except the architecture specific ones
1509 #define AARCH64_DYNAMIC_TAG(name, value)
14981510 #define MIPS_DYNAMIC_TAG(name, value)
14991511 #define HEXAGON_DYNAMIC_TAG(name, value)
15001512 #define PPC64_DYNAMIC_TAG(name, value)
15051517 return #name;
15061518 #include "llvm/BinaryFormat/DynamicTags.def"
15071519 #undef DYNAMIC_TAG
1520 #undef AARCH64_DYNAMIC_TAG
15081521 #undef MIPS_DYNAMIC_TAG
15091522 #undef HEXAGON_DYNAMIC_TAG
15101523 #undef PPC64_DYNAMIC_TAG
17821795 uint64_t Value) const {
17831796 const char *ConvChar =
17841797 (opts::Output == opts::GNU) ? "0x%" PRIx64 : "0x%" PRIX64;
1798
1799 // Handle custom printing of architecture specific tags
1800 switch (ObjF->getELFFile()->getHeader()->e_machine) {
1801 case EM_AARCH64:
1802 switch (Type) {
1803 case DT_AARCH64_BTI_PLT:
1804 case DT_AARCH64_PAC_PLT:
1805 OS << Value;
1806 return;
1807 default:
1808 break;
1809 }
1810 break;
1811 case EM_HEXAGON:
1812 switch (Type) {
1813 case DT_HEXAGON_VER:
1814 OS << Value;
1815 return;
1816 case DT_HEXAGON_SYMSZ:
1817 case DT_HEXAGON_PLT:
1818 OS << format(ConvChar, Value);
1819 return;
1820 default:
1821 break;
1822 }
1823 break;
1824 case EM_MIPS:
1825 switch (Type) {
1826 case DT_MIPS_RLD_VERSION:
1827 case DT_MIPS_LOCAL_GOTNO:
1828 case DT_MIPS_SYMTABNO:
1829 case DT_MIPS_UNREFEXTNO:
1830 OS << Value;
1831 return;
1832 case DT_MIPS_TIME_STAMP:
1833 case DT_MIPS_ICHECKSUM:
1834 case DT_MIPS_IVERSION:
1835 case DT_MIPS_BASE_ADDRESS:
1836 case DT_MIPS_MSYM:
1837 case DT_MIPS_CONFLICT:
1838 case DT_MIPS_LIBLIST:
1839 case DT_MIPS_CONFLICTNO:
1840 case DT_MIPS_LIBLISTNO:
1841 case DT_MIPS_GOTSYM:
1842 case DT_MIPS_HIPAGENO:
1843 case DT_MIPS_RLD_MAP:
1844 case DT_MIPS_DELTA_CLASS:
1845 case DT_MIPS_DELTA_CLASS_NO:
1846 case DT_MIPS_DELTA_INSTANCE:
1847 case DT_MIPS_DELTA_RELOC:
1848 case DT_MIPS_DELTA_RELOC_NO:
1849 case DT_MIPS_DELTA_SYM:
1850 case DT_MIPS_DELTA_SYM_NO:
1851 case DT_MIPS_DELTA_CLASSSYM:
1852 case DT_MIPS_DELTA_CLASSSYM_NO:
1853 case DT_MIPS_CXX_FLAGS:
1854 case DT_MIPS_PIXIE_INIT:
1855 case DT_MIPS_SYMBOL_LIB:
1856 case DT_MIPS_LOCALPAGE_GOTIDX:
1857 case DT_MIPS_LOCAL_GOTIDX:
1858 case DT_MIPS_HIDDEN_GOTIDX:
1859 case DT_MIPS_PROTECTED_GOTIDX:
1860 case DT_MIPS_OPTIONS:
1861 case DT_MIPS_INTERFACE:
1862 case DT_MIPS_DYNSTR_ALIGN:
1863 case DT_MIPS_INTERFACE_SIZE:
1864 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR:
1865 case DT_MIPS_PERF_SUFFIX:
1866 case DT_MIPS_COMPACT_SIZE:
1867 case DT_MIPS_GP_VALUE:
1868 case DT_MIPS_AUX_DYNAMIC:
1869 case DT_MIPS_PLTGOT:
1870 case DT_MIPS_RWPLT:
1871 case DT_MIPS_RLD_MAP_REL:
1872 OS << format(ConvChar, Value);
1873 return;
1874 case DT_MIPS_FLAGS:
1875 printFlags(Value, makeArrayRef(ElfDynamicDTMipsFlags), OS);
1876 return;
1877 default:
1878 break;
1879 }
1880 break;
1881 default:
1882 break;
1883 }
1884
17851885 switch (Type) {
17861886 case DT_PLTREL:
17871887 if (Value == DT_REL) {
18101910 case DT_VERSYM:
18111911 case DT_GNU_HASH:
18121912 case DT_NULL:
1813 case DT_MIPS_BASE_ADDRESS:
1814 case DT_MIPS_GOTSYM:
1815 case DT_MIPS_RLD_MAP:
1816 case DT_MIPS_RLD_MAP_REL:
1817 case DT_MIPS_PLTGOT:
1818 case DT_MIPS_OPTIONS:
18191913 OS << format(ConvChar, Value);
18201914 break;
18211915 case DT_RELACOUNT:
18221916 case DT_RELCOUNT:
18231917 case DT_VERDEFNUM:
18241918 case DT_VERNEEDNUM:
1825 case DT_MIPS_RLD_VERSION:
1826 case DT_MIPS_LOCAL_GOTNO:
1827 case DT_MIPS_SYMTABNO:
1828 case DT_MIPS_UNREFEXTNO:
18291919 OS << Value;
18301920 break;
18311921 case DT_PLTRELSZ:
18601950 case DT_RPATH:
18611951 case DT_RUNPATH:
18621952 OS << getDynamicString(Value);
1863 break;
1864 case DT_MIPS_FLAGS:
1865 printFlags(Value, makeArrayRef(ElfDynamicDTMipsFlags), OS);
18661953 break;
18671954 case DT_FLAGS:
18681955 printFlags(Value, makeArrayRef(ElfDynamicDTFlags), OS);