From: Matthew Malcomson Date: Mon, 7 Feb 2022 16:19:41 +0000 (+0000) Subject: Fixing cap_meta X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46025ce7452514c931b00f2d0be3684fd669514d;p=thirdparty%2Fbinutils-gdb.git Fixing cap_meta It had two problems: 1) The linker was storing permission flags in the bottom byte and the size in the top 56 bits. Newlib was looking for the permission flags in the top byte and the length in the bottom 56 bits of a uint64_t stored as bytes 8:16 of the fragment. N.b. The ABI requires a given storage order between the size and permission flags (as opposed to requiring a given uint64_t value be stored in the relevant position). This means that our current implementation would not work for a hypothetical big-endian Morello. 2) The linker prioritised SEC_READONLY flags over SEC_CODE ones on the section, this meant that function symbols into the .text section (which has both flags on it) would be given read-only permissions rather than executable permissions. This patch also must update all tests to account for this change. --- diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index 96ac304b0b6..490f74c9a4a 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -6373,18 +6373,27 @@ cap_meta (size_t size, const asection *sec) if (size >= (1ULL << 56)) return (bfd_vma) -1; - size <<= 8; - if (sec->flags & SEC_READONLY - || sec->flags & SEC_ROM) - return size | 1; + /* N.b. We are only ever using this function for Morello. + Morello is little-endian. + We are returning a 64bit sized integer. + The format this metadata is supposed to fit is + | 56 bit length | 8 bit permissions | + This means that (in little endian layout) we need to put the 56 bit size + in the *lower* bits of the uint64_t. */ + uint64_t flags = 0; if (sec->flags & SEC_CODE) - return size | 4; - if (sec->flags & SEC_ALLOC) - return size | 2; + flags = 4; + else if (sec->flags & SEC_READONLY + || sec->flags & SEC_ROM) + flags = 1; + else if (sec->flags & SEC_ALLOC) + flags = 2; /* We should always be able to derive a valid set of permissions from the section flags. */ - abort (); + if (flags == 0) + abort (); + return size | (flags << 56); } enum c64_section_perm_type { diff --git a/ld/testsuite/ld-aarch64/emit-relocs-morello-1.d b/ld/testsuite/ld-aarch64/emit-relocs-morello-1.d index ee272150263..127311445b9 100644 --- a/ld/testsuite/ld-aarch64/emit-relocs-morello-1.d +++ b/ld/testsuite/ld-aarch64/emit-relocs-morello-1.d @@ -19,8 +19,8 @@ Disassembly of section .got: .*: [0-9a-f]+ .* .*: R_MORELLO_RELATIVE \*ABS\* .*: 00000000 .* - .*: 00000302 .* - .*: 00000000 .* + .*: 00000003 .* + .*: 02000000 .* Disassembly of section .data: @@ -32,5 +32,5 @@ Disassembly of section .data: .*: [0-9a-f]+ .* .*: R_MORELLO_RELATIVE \*ABS\* .*: 00000000 .* - .*: 00000302 .* - .*: 00000000 .* + .*: 00000003 .* + .*: 02000000 .* diff --git a/ld/testsuite/ld-aarch64/emit-relocs-morello-2-a64c.d b/ld/testsuite/ld-aarch64/emit-relocs-morello-2-a64c.d index f4a47355989..5d2d90cd271 100644 --- a/ld/testsuite/ld-aarch64/emit-relocs-morello-2-a64c.d +++ b/ld/testsuite/ld-aarch64/emit-relocs-morello-2-a64c.d @@ -41,5 +41,5 @@ Disassembly of section .data: .*: [0-9a-f]+ .* .*: R_MORELLO_RELATIVE \*ABS\* .*: 00000000 .* -.*: 00001b02 .* -.*: 00000000 .* +.*: 0000001b .* +.*: 02000000 .* diff --git a/ld/testsuite/ld-aarch64/emit-relocs-morello-2.d b/ld/testsuite/ld-aarch64/emit-relocs-morello-2.d index def5db0ddc1..a7077214be8 100644 --- a/ld/testsuite/ld-aarch64/emit-relocs-morello-2.d +++ b/ld/testsuite/ld-aarch64/emit-relocs-morello-2.d @@ -41,5 +41,5 @@ Disassembly of section .data: .*: 00010350 .* .*: R_MORELLO_RELATIVE \*ABS\* .*: 00000000 .* -.*: 00001b02 .* -.*: 00000000 .* +.*: 0000001b .* +.*: 02000000 .* diff --git a/ld/testsuite/ld-aarch64/emit-relocs-morello-3-a64c.d b/ld/testsuite/ld-aarch64/emit-relocs-morello-3-a64c.d index 0feb5ae286d..d596a53df90 100644 --- a/ld/testsuite/ld-aarch64/emit-relocs-morello-3-a64c.d +++ b/ld/testsuite/ld-aarch64/emit-relocs-morello-3-a64c.d @@ -39,8 +39,8 @@ Disassembly of section .data: .*: [0-9a-f]+ .* .*: R_MORELLO_CAPINIT str .*: 00000000 .* -.*: 00001b02 .* -.*: 00000000 .* +.*: 0000001b .* +.*: 02000000 .* .* : ... diff --git a/ld/testsuite/ld-aarch64/emit-relocs-morello-3.d b/ld/testsuite/ld-aarch64/emit-relocs-morello-3.d index 38f65d09893..fe248be367e 100644 --- a/ld/testsuite/ld-aarch64/emit-relocs-morello-3.d +++ b/ld/testsuite/ld-aarch64/emit-relocs-morello-3.d @@ -39,8 +39,8 @@ Disassembly of section .data: .*: [0-9a-f]+ .* .*: R_MORELLO_CAPINIT str .*: 00000000 .* -.*: 00001b02 .* -.*: 00000000 .* +.*: 0000001b .* +.*: 02000000 .* .* : ... diff --git a/ld/testsuite/ld-aarch64/emit-relocs-morello-6.d b/ld/testsuite/ld-aarch64/emit-relocs-morello-6.d index e41e42ed5ff..0baf1c49fbd 100644 --- a/ld/testsuite/ld-aarch64/emit-relocs-morello-6.d +++ b/ld/testsuite/ld-aarch64/emit-relocs-morello-6.d @@ -41,20 +41,20 @@ Disassembly of section \.got: 101010: 001001ed .* 101010: R_MORELLO_RELATIVE \*ABS\* 101014: 00000000 .* - 101018: 00000402 .* - 10101c: 00000000 .* + 101018: 00000004 .* + 10101c: 02000000 .* 101020: 00100100 .* 101020: R_MORELLO_RELATIVE \*ABS\* 101024: 00000000 .* - 101028: 000f5001 .* - 10102c: 00000000 .* + 101028: 00000f50 .* + 10102c: 04000000 .* 101030: 00100100 .* 101030: R_MORELLO_RELATIVE \*ABS\*\+0x1 101034: 00000000 .* - 101038: 000f5001 .* - 10103c: 00000000 .* + 101038: 00000f50 .* + 10103c: 04000000 .* 101040: 001001e8 .* 101040: R_MORELLO_RELATIVE \*ABS\* 101044: 00000000 .* - 101048: 00000402 .* - 10104c: 00000000 .* + 101048: 00000004 .* + 10104c: 02000000 .* diff --git a/ld/testsuite/ld-aarch64/emit-relocs-morello-6b.d b/ld/testsuite/ld-aarch64/emit-relocs-morello-6b.d index 943b339a6d1..a0fd442b644 100644 --- a/ld/testsuite/ld-aarch64/emit-relocs-morello-6b.d +++ b/ld/testsuite/ld-aarch64/emit-relocs-morello-6b.d @@ -68,17 +68,17 @@ Disassembly of section \.got: \.\.\. 101010: 00100075 .* 101014: 00000000 .* - 101018: 00000402 .* - 10101c: 00000000 .* + 101018: 00000004 .* + 10101c: 02000000 .* 101020: 00100000 .* 101024: 00000000 .* - 101028: 00105001 .* - 10102c: 00000000 .* + 101028: 00001050 .* + 10102c: 04000000 .* 101030: 00100000 .* 101034: 00000000 .* - 101038: 00105001 .* - 10103c: 00000000 .* + 101038: 00001050 .* + 10103c: 04000000 .* 101040: 00100070 .* 101044: 00000000 .* - 101048: 00000402 .* - 10104c: 00000000 .* + 101048: 00000004 .* + 10104c: 02000000 .* diff --git a/ld/testsuite/ld-aarch64/emit-relocs-morello-7.d b/ld/testsuite/ld-aarch64/emit-relocs-morello-7.d index 69913f8c573..bbf451ec942 100644 --- a/ld/testsuite/ld-aarch64/emit-relocs-morello-7.d +++ b/ld/testsuite/ld-aarch64/emit-relocs-morello-7.d @@ -49,21 +49,20 @@ Disassembly of section \.got: 1010: 000001e8 .* 1010: R_MORELLO_RELATIVE \*ABS\*\+0x38 1014: 00000000 .* - 1018: 000e6801 .* - 101c: 00000000 .* + 1018: 00000e68 .* + 101c: 04000000 .* 1020: 000001e8 .* 1020: R_MORELLO_RELATIVE \*ABS\*\+0x48 1024: 00000000 .* - 1028: 000e6801 .* - 102c: 00000000 .* + 1028: 00000e68 .* + 102c: 04000000 .* 1030: 00000230 .* 1030: R_MORELLO_RELATIVE \*ABS\* 1034: 00000000 .* - 1038: 00000d01 .* - 103c: 00000000 .* + 1038: 0000000d .* + 103c: 01000000 .* 1040: 00000220 .* 1040: R_MORELLO_RELATIVE \*ABS\* - 1044: 00000000 .* - 1048: 00000002 .* - 104c: 00000000 .* + \.\.\. + 104c: 02000000 .* diff --git a/ld/testsuite/ld-aarch64/emit-relocs-morello-a64c.d b/ld/testsuite/ld-aarch64/emit-relocs-morello-a64c.d index d081fac519f..35775f72631 100644 --- a/ld/testsuite/ld-aarch64/emit-relocs-morello-a64c.d +++ b/ld/testsuite/ld-aarch64/emit-relocs-morello-a64c.d @@ -37,8 +37,8 @@ Disassembly of section .data: .*: [0-9a-f]+ .* .*: R_MORELLO_RELATIVE \*ABS\* .*: 00000000 .* -.*: 00000402 .* -.*: 00000000 .* +.*: 00000004 .* +.*: 02000000 .* .* : ... diff --git a/ld/testsuite/ld-aarch64/emit-relocs-morello.d b/ld/testsuite/ld-aarch64/emit-relocs-morello.d index 0da62eda7a0..4613b776edb 100644 --- a/ld/testsuite/ld-aarch64/emit-relocs-morello.d +++ b/ld/testsuite/ld-aarch64/emit-relocs-morello.d @@ -37,8 +37,8 @@ Disassembly of section .data: .*: [0-9a-f]+ .* .*: R_MORELLO_RELATIVE \*ABS\* .*: 00000000 .* -.*: 00000402 .* -.*: 00000000 .* +.*: 00000004 .* +.*: 02000000 .* .* : ... diff --git a/ld/testsuite/ld-aarch64/morello-capinit.d b/ld/testsuite/ld-aarch64/morello-capinit.d index 9035351d215..54b981a60b9 100644 --- a/ld/testsuite/ld-aarch64/morello-capinit.d +++ b/ld/testsuite/ld-aarch64/morello-capinit.d @@ -22,75 +22,74 @@ Disassembly of section \.inspectionsection: .*: [0-9a-f]+ .* .*: R_MORELLO_RELATIVE \*ABS\*\+0x[0-9a-f]+ .*: 00000000 .* -.*: 00027001 .* -.*: 00000000 .* +.*: 00000270 .* +.*: 04000000 .* [0-9a-f]+ : .*: [0-9a-f]+ .* .*: R_MORELLO_RELATIVE \*ABS\*\+0x[0-9a-f]+ .*: 00000000 .* -.*: 00027001 .* -.*: 00000000 .* +.*: 00000270 .* +.*: 04000000 .* [0-9a-f]+ : .*: [0-9a-f]+ .* .*: R_MORELLO_RELATIVE \*ABS\*\+0x[0-9a-f]+ .*: 00000000 .* -.*: 00027001 .* -.*: 00000000 .* +.*: 00000270 .* +.*: 04000000 .* [0-9a-f]+ : .*: [0-9a-f]+ .* .*: R_MORELLO_RELATIVE \*ABS\*\+0x[0-9a-f]+ .*: 00000000 .* -.*: 00027001 .* -.*: 00000000 .* +.*: 00000270 .* +.*: 04000000 .* [0-9a-f]+ : .*: [0-9a-f]+ .* .*: R_MORELLO_RELATIVE \*ABS\*\+0x[0-9a-f]+ .*: 00000000 .* -.*: 00027001 .* -.*: 00000000 .* +.*: 00000270 .* +.*: 04000000 .* [0-9a-f]+ : .*: [0-9a-f]+ .* .*: R_MORELLO_RELATIVE \*ABS\* .*: 00000000 .* -.*: 00000c02 .* -.*: 00000000 .* +.*: 0000000c .* +.*: 02000000 .* [0-9a-f]+ : .*: [0-9a-f]+ .* .*: R_MORELLO_RELATIVE \*ABS\* .*: 00000000 .* -.*: 00000c02 .* -.*: 00000000 .* +.*: 0000000c .* +.*: 02000000 .* [0-9a-f]+ : .*: [0-9a-f]+ .* .*: R_MORELLO_RELATIVE \*ABS\* .*: 00000000 .* -.*: 00000802 .* -.*: 00000000 .* +.*: 00000008 .* +.*: 02000000 .* [0-9a-f]+ : .*: [0-9a-f]+ .* .*: R_MORELLO_RELATIVE \*ABS\* .*: 00000000 .* -.*: 00000402 .* -.*: 00000000 .* +.*: 00000004 .* +.*: 02000000 .* [0-9a-f]+ : .*: [0-9a-f]+ .* .*: R_MORELLO_RELATIVE \*ABS\* -.*: 00000000 .* -.*: 00000002 .* -.*: 00000000 .* + \.\.\. +.*: 02000000 .* [0-9a-f]+ : .*: [0-9a-f]+ .* .*: R_MORELLO_RELATIVE \*ABS\* .*: 00000000 .* -.*: 0*[1-9a-f]+[0-9]*02 .* -.*: 00000000 .* +.*: 000*[1-9a-f]+[0-9]* .* +.*: 02000000 .* diff --git a/ld/testsuite/ld-aarch64/morello-sizeless-global-syms.d b/ld/testsuite/ld-aarch64/morello-sizeless-global-syms.d index 5765c204366..629cc44cad5 100644 --- a/ld/testsuite/ld-aarch64/morello-sizeless-global-syms.d +++ b/ld/testsuite/ld-aarch64/morello-sizeless-global-syms.d @@ -12,22 +12,22 @@ Disassembly of section \.data: [0-9a-f]+: 00010440.* [0-9a-f]+: R_MORELLO_RELATIVE \*ABS\* [0-9a-f]+: 00000000.* - [0-9a-f]+: 00000002.* [0-9a-f]+: 00000000.* + [0-9a-f]+: 02000000.* [0-9a-f]+ : [0-9a-f]+: 00010444.* [0-9a-f]+: R_MORELLO_RELATIVE \*ABS\* [0-9a-f]+: 00000000.* - [0-9a-f]+: 00000002.* [0-9a-f]+: 00000000.* + [0-9a-f]+: 02000000.* [0-9a-f]+ : [0-9a-f]+: 00010448.* [0-9a-f]+: R_MORELLO_RELATIVE \*ABS\* [0-9a-f]+: 00000000.* - [0-9a-f]+: 00000002.* [0-9a-f]+: 00000000.* + [0-9a-f]+: 02000000.* Disassembly of section .bss: diff --git a/ld/testsuite/ld-aarch64/morello-sizeless-got-syms.d b/ld/testsuite/ld-aarch64/morello-sizeless-got-syms.d index 7c5276b3c5f..b28fca9f70d 100644 --- a/ld/testsuite/ld-aarch64/morello-sizeless-got-syms.d +++ b/ld/testsuite/ld-aarch64/morello-sizeless-got-syms.d @@ -35,18 +35,18 @@ Disassembly of section \.got: [0-9a-f]+: 000103b0 .* [0-9a-f]+: R_MORELLO_RELATIVE \*ABS\* [0-9a-f]+: 00000000 .* - [0-9a-f]+: 00000002 .* [0-9a-f]+: 00000000 .* + [0-9a-f]+: 02000000 .* [0-9a-f]+: 000103b8 .* [0-9a-f]+: R_MORELLO_RELATIVE \*ABS\* [0-9a-f]+: 00000000 .* - [0-9a-f]+: 00000002 .* [0-9a-f]+: 00000000 .* + [0-9a-f]+: 02000000 .* [0-9a-f]+: 000103b4 .* [0-9a-f]+: R_MORELLO_RELATIVE \*ABS\* [0-9a-f]+: 00000000 .* - [0-9a-f]+: 00000002 .* [0-9a-f]+: 00000000 .* + [0-9a-f]+: 02000000 .* Disassembly of section .bss: diff --git a/ld/testsuite/ld-aarch64/morello-sizeless-local-syms.d b/ld/testsuite/ld-aarch64/morello-sizeless-local-syms.d index 30a7823bb65..5439d54b66c 100644 --- a/ld/testsuite/ld-aarch64/morello-sizeless-local-syms.d +++ b/ld/testsuite/ld-aarch64/morello-sizeless-local-syms.d @@ -12,22 +12,22 @@ Disassembly of section .data: [0-9a-f]+: 00010440.* [0-9a-f]+: R_MORELLO_RELATIVE \*ABS\* [0-9a-f]+: 00000000.* - [0-9a-f]+: 00000002.* [0-9a-f]+: 00000000.* + [0-9a-f]+: 02000000.* [0-9a-f]+ : [0-9a-f]+: 00010444.* [0-9a-f]+: R_MORELLO_RELATIVE \*ABS\* [0-9a-f]+: 00000000.* - [0-9a-f]+: 00000002.* [0-9a-f]+: 00000000.* + [0-9a-f]+: 02000000.* [0-9a-f]+ : [0-9a-f]+: 00010448.* [0-9a-f]+: R_MORELLO_RELATIVE \*ABS\* [0-9a-f]+: 00000000.* - [0-9a-f]+: 00000002.* [0-9a-f]+: 00000000.* + [0-9a-f]+: 02000000.* Disassembly of section .bss: