]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fixing cap_meta
authorMatthew Malcomson <matthew.malcomson@arm.com>
Mon, 7 Feb 2022 16:19:41 +0000 (16:19 +0000)
committerMatthew Malcomson <matthew.malcomson@arm.com>
Mon, 7 Feb 2022 16:20:00 +0000 (16:20 +0000)
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.

15 files changed:
bfd/elfnn-aarch64.c
ld/testsuite/ld-aarch64/emit-relocs-morello-1.d
ld/testsuite/ld-aarch64/emit-relocs-morello-2-a64c.d
ld/testsuite/ld-aarch64/emit-relocs-morello-2.d
ld/testsuite/ld-aarch64/emit-relocs-morello-3-a64c.d
ld/testsuite/ld-aarch64/emit-relocs-morello-3.d
ld/testsuite/ld-aarch64/emit-relocs-morello-6.d
ld/testsuite/ld-aarch64/emit-relocs-morello-6b.d
ld/testsuite/ld-aarch64/emit-relocs-morello-7.d
ld/testsuite/ld-aarch64/emit-relocs-morello-a64c.d
ld/testsuite/ld-aarch64/emit-relocs-morello.d
ld/testsuite/ld-aarch64/morello-capinit.d
ld/testsuite/ld-aarch64/morello-sizeless-global-syms.d
ld/testsuite/ld-aarch64/morello-sizeless-got-syms.d
ld/testsuite/ld-aarch64/morello-sizeless-local-syms.d

index c35d1e42833a18faa99ae217bdddcaaa83766abf..cd54beec7b7d9f6b6977634dcd82501b80ab6cd4 100644 (file)
@@ -6370,18 +6370,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 {
index ee272150263d7a640a922eadfb0a50453c1e83bd..127311445b92e150db4c6708eb98b3d41ab7d816 100644 (file)
@@ -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        .*
index f4a473559894f1593c7835c82cb0f9f513818d9e..5d2d90cd271d021ee88f2614a20f4c3a9867a324 100644 (file)
@@ -41,5 +41,5 @@ Disassembly of section .data:
 .*:    [0-9a-f]+       .*
                        .*: R_MORELLO_RELATIVE  \*ABS\*
 .*:    00000000        .*
-.*:    00001b02        .*
-.*:    00000000        .*
+.*:    0000001b        .*
+.*:    02000000        .*
index def5db0ddc1a24d5aaf7170d09c4efe3182a2a56..a7077214be83beb1a099b57805498dfaa6fb263f 100644 (file)
@@ -41,5 +41,5 @@ Disassembly of section .data:
 .*:    00010350        .*
                        .*: R_MORELLO_RELATIVE  \*ABS\*
 .*:    00000000        .*
-.*:    00001b02        .*
-.*:    00000000        .*
+.*:    0000001b        .*
+.*:    02000000        .*
index 0feb5ae286d5a626c3338b6dbe2e26af73d3203f..d596a53df90e6a73ee950e91187ecf72c86d7e13 100644 (file)
@@ -39,8 +39,8 @@ Disassembly of section .data:
 .*:    [0-9a-f]+       .*
                        .*: R_MORELLO_CAPINIT   str
 .*:    00000000        .*
-.*:    00001b02        .*
-.*:    00000000        .*
+.*:    0000001b        .*
+.*:    02000000        .*
 
 .* <cap2>:
        ...
index 38f65d09893a4185ad1eb8a69a098920dee6e1c9..fe248be367e98bc0720042b0c2ed9bab76427c86 100644 (file)
@@ -39,8 +39,8 @@ Disassembly of section .data:
 .*:    [0-9a-f]+       .*
                        .*: R_MORELLO_CAPINIT   str
 .*:    00000000        .*
-.*:    00001b02        .*
-.*:    00000000        .*
+.*:    0000001b        .*
+.*:    02000000        .*
 
 .* <cap2>:
        ...
index e41e42ed5ffeca5d9ae03b2114be5d9f476223fc..0baf1c49fbde25731b97f4fe71cb9c98b864d021 100644 (file)
@@ -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        .*
index 943b339a6d1b4350202a4d2716d41c59ef8579b4..a0fd442b6449591bda7230192ffea6ceee2c2605 100644 (file)
@@ -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        .*
index 69913f8c57359ef382401fd2033c7adc23dc127c..bbf451ec9425df80631988aff699bc822189bbfd 100644 (file)
@@ -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        .*
 
index d081fac519f1c44f9462400bfecfd9f366a20029..35775f72631f84b7494f2aec4918fdffd7fcad45 100644 (file)
@@ -37,8 +37,8 @@ Disassembly of section .data:
 .*:    [0-9a-f]+       .*
                        .*: R_MORELLO_RELATIVE  \*ABS\*
 .*:    00000000        .*
-.*:    00000402        .*
-.*:    00000000        .*
+.*:    00000004        .*
+.*:    02000000        .*
 
 .* <globcap>:
        ...
index 0da62eda7a04b9b4b2e2e420f72d6977f59cbaef..4613b776edbe5b900386da94b450b3f16d416440 100644 (file)
@@ -37,8 +37,8 @@ Disassembly of section .data:
 .*:    [0-9a-f]+       .*
                        .*: R_MORELLO_RELATIVE  \*ABS\*
 .*:    00000000        .*
-.*:    00000402        .*
-.*:    00000000        .*
+.*:    00000004        .*
+.*:    02000000        .*
 
 .* <globcap>:
        ...
index 9035351d215c0bee71e2efca30dc232a40890b22..54b981a60b9518d9d9fcba28c38019e44828162c 100644 (file)
@@ -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]+ <ct_start>:
 .*:    [0-9a-f]+       .*
                        .*: R_MORELLO_RELATIVE  \*ABS\*\+0x[0-9a-f]+
 .*:    00000000        .*
-.*:    00027001        .*
-.*:    00000000        .*
+.*:    00000270        .*
+.*:    04000000        .*
 
 [0-9a-f]+ <ct1_start>:
 .*:    [0-9a-f]+       .*
                        .*: R_MORELLO_RELATIVE  \*ABS\*\+0x[0-9a-f]+
 .*:    00000000        .*
-.*:    00027001        .*
-.*:    00000000        .*
+.*:    00000270        .*
+.*:    04000000        .*
 
 [0-9a-f]+ <ct1_end>:
 .*:    [0-9a-f]+       .*
                        .*: R_MORELLO_RELATIVE  \*ABS\*\+0x[0-9a-f]+
 .*:    00000000        .*
-.*:    00027001        .*
-.*:    00000000        .*
+.*:    00000270        .*
+.*:    04000000        .*
 
 [0-9a-f]+ <ct_end>:
 .*:    [0-9a-f]+       .*
                        .*: R_MORELLO_RELATIVE  \*ABS\*\+0x[0-9a-f]+
 .*:    00000000        .*
-.*:    00027001        .*
-.*:    00000000        .*
+.*:    00000270        .*
+.*:    04000000        .*
 
 [0-9a-f]+ <cd_outer_start>:
 .*:    [0-9a-f]+       .*
                        .*: R_MORELLO_RELATIVE  \*ABS\*
 .*:    00000000        .*
-.*:    00000c02        .*
-.*:    00000000        .*
+.*:    0000000c        .*
+.*:    02000000        .*
 
 [0-9a-f]+ <cd_start>:
 .*:    [0-9a-f]+       .*
                        .*: R_MORELLO_RELATIVE  \*ABS\*
 .*:    00000000        .*
-.*:    00000c02        .*
-.*:    00000000        .*
+.*:    0000000c        .*
+.*:    02000000        .*
 
 [0-9a-f]+ <cd1_start>:
 .*:    [0-9a-f]+       .*
                        .*: R_MORELLO_RELATIVE  \*ABS\*
 .*:    00000000        .*
-.*:    00000802        .*
-.*:    00000000        .*
+.*:    00000008        .*
+.*:    02000000        .*
 
 [0-9a-f]+ <cd1_end>:
 .*:    [0-9a-f]+       .*
                        .*: R_MORELLO_RELATIVE  \*ABS\*
 .*:    00000000        .*
-.*:    00000402        .*
-.*:    00000000        .*
+.*:    00000004        .*
+.*:    02000000        .*
 
 [0-9a-f]+ <cd_end>:
 .*:    [0-9a-f]+       .*
                        .*: R_MORELLO_RELATIVE  \*ABS\*
-.*:    00000000        .*
-.*:    00000002        .*
-.*:    00000000        .*
+       \.\.\.
+.*:    02000000        .*
 
 [0-9a-f]+ <cdynamic>:
 .*:    [0-9a-f]+       .*
                        .*: R_MORELLO_RELATIVE  \*ABS\*
 .*:    00000000        .*
-.*:    0*[1-9a-f]+[0-9]*02     .*
-.*:    00000000        .*
+.*:    000*[1-9a-f]+[0-9]*     .*
+.*:    02000000        .*
index 5765c204366f345add8252739bb95f90b1ac8170..629cc44cad520e9212ab96740d7c78fdde3063fc 100644 (file)
@@ -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]+ <ptr2>:
    [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]+ <ptr1>:
    [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:
 
index 7c5276b3c5ff4cdec91ccfab17f0c39084b28c41..b28fca9f70d42fa1dea1a9ab92c57ccc324426ee 100644 (file)
@@ -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:
 
index 30a7823bb659137f824b96c3acdc78b83a728397..5439d54b66c0c786087c25a6a74fb27630b8eb22 100644 (file)
@@ -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]+ <ptr2>:
    [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]+ <ptr1>:
    [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: