]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas: ADR_LO21_PCREL accounts for LSB in symbol
authorMatthew Malcomson <matthew.malcomson@arm.com>
Tue, 10 Aug 2021 11:05:44 +0000 (12:05 +0100)
committerMatthew Malcomson <matthew.malcomson@arm.com>
Tue, 10 Aug 2021 11:05:44 +0000 (12:05 +0100)
After d30dd5c GAS now accounts for the LSB getting set on STT_FUNC by
maintaining the value of the relevant functions to include that LSB.

Previously GAS attempted to account for the LSB only when outputting the
file (i.e. in the obj_adjust_symtab hook and when a relocation is
getting made for the relevant symbol).
The obj_adjust_symtab hook is still needed, since this is about adding a
flag to an elf_sym rather than adjusting the value of the symbol.

We changed from this so that expressions given by the user would
naturally account for the LSB set on C64 STT_FUNC symbols.  This means
that we no longer need to adjust local pc-relative relocations in
`parse_operands` since the relative relocation will naturally include
whether the LSB is set on the relevant symbol.

Here we remove the previous code to do this adjustment.  With both
methods of accounting we ended up adding 2 to the relocation rather than
just setting the LSB.

Note that the combination of this change and d30dd5c has meant that a
`AARCH64_ADR_PREL_LO21` relocation to a locally defined function now points
directly to that function rather than to that function plus 1.
These relocations are left in the object file when the locally defined
function is declared global.  This matches the behaviour of LLVM.

gas/config/tc-aarch64.c
gas/testsuite/gas/aarch64/morello-lsb-relocs.d
gas/testsuite/gas/aarch64/morello-lsb-relocs.s
gas/testsuite/gas/aarch64/morello-lsb-relocs2.d

index f550d9e042f4962e0d7c23eae40978610141e77b..5c0a8067168c2f9e0330f8b5c8c2f80c560c058c 100644 (file)
@@ -6689,21 +6689,6 @@ bad_adrdp:
                  case pcreladdr:
                    gas_assert (operands[i] == AARCH64_OPND_ADDR_PCREL21);
                    inst.reloc.type = BFD_RELOC_AARCH64_ADR_LO21_PCREL;
-                   if (inst.reloc.exp.X_op == O_symbol
-                       && inst.reloc.exp.X_add_symbol != NULL)
-                     {
-                       symbolS *sym = inst.reloc.exp.X_add_symbol;
-
-                       /* We set LSB for C64 local functions.  We do not do
-                          this for local labels even in code section because
-                          it could be embedded data.  */
-                       if (S_IS_DEFINED (sym) && AARCH64_IS_C64 (sym)
-                           && (symbol_get_bfdsym (sym)->flags & BSF_FUNCTION))
-                         {
-                             inst.reloc.exp.X_add_number += 1;
-                         }
-                     }
-
                    break;
                  default:
                    gas_assert (0);
index 226801b23a8a9061d466dbfcdc220b9eb279a25e..4fc9f8674175cd1c826053fcb20690e91914128f 100644 (file)
@@ -20,27 +20,33 @@ Disassembly of section \.text:
        \.\.\.
 
 000000000000000c <f>:
-   c:  14000000        b       0 <x>
-                       c: R_MORELLO_JUMP26     x
-  10:  14000000        b       c <f>
-                       10: R_MORELLO_JUMP26    f
-  14:  17fffffe        b       c <f>
-  18:  17fffffd        b       c <f>
-  1c:  5400000d        b\.le   0 <x>
-                       1c: R_MORELLO_CONDBR19  x
-  20:  5400000d        b\.le   c <f>
-                       20: R_MORELLO_CONDBR19  f
-  24:  54ffff4d        b\.le   c <f>
-  28:  54ffff2d        b\.le   c <f>
-  2c:  36080001        tbz     w1, #1, 0 <x>
-                       2c: R_MORELLO_TSTBR14   x
-  30:  36080001        tbz     w1, #1, c <f>
-                       30: R_MORELLO_TSTBR14   f
-  34:  360ffec1        tbz     w1, #1, c <f>
-  38:  360ffea1        tbz     w1, #1, c <f>
-  3c:  94000000        bl      0 <x>
-                       3c: R_MORELLO_CALL26    x
-  40:  94000000        bl      c <f>
-                       40: R_MORELLO_CALL26    f
-  44:  97fffff2        bl      c <f>
-  48:  97fffff1        bl      c <f>
+   c:  10000000        adr     c0, 0 <x>
+                       c: R_AARCH64_ADR_PREL_LO21      x
+  10:  10000000        adr     c0, c <f>
+                       10: R_AARCH64_ADR_PREL_LO21     f
+  14:  30ffffc0        adr     c0, d <f\+0x1>
+  18:  10ffffa0        adr     c0, c <f>
+  1c:  14000000        b       0 <x>
+                       1c: R_MORELLO_JUMP26    x
+  20:  14000000        b       c <f>
+                       20: R_MORELLO_JUMP26    f
+  24:  17fffffa        b       c <f>
+  28:  17fffff9        b       c <f>
+  2c:  5400000d        b\.le   0 <x>
+                       2c: R_MORELLO_CONDBR19  x
+  30:  5400000d        b\.le   c <f>
+                       30: R_MORELLO_CONDBR19  f
+  34:  54fffecd        b\.le   c <f>
+  38:  54fffead        b\.le   c <f>
+  3c:  36080001        tbz     w1, #1, 0 <x>
+                       3c: R_MORELLO_TSTBR14   x
+  40:  36080001        tbz     w1, #1, c <f>
+                       40: R_MORELLO_TSTBR14   f
+  44:  360ffe41        tbz     w1, #1, c <f>
+  48:  360ffe21        tbz     w1, #1, c <f>
+  4c:  94000000        bl      0 <x>
+                       4c: R_MORELLO_CALL26    x
+  50:  94000000        bl      c <f>
+                       50: R_MORELLO_CALL26    f
+  54:  97ffffee        bl      c <f>
+  58:  97ffffed        bl      c <f>
index 227b023e220386e4630e869ca4f62e7b4e7ff410..26e498f59d07978a9d26384bfa92db3738837cd8 100644 (file)
@@ -14,6 +14,11 @@ a:           // This function is local, so the relocation on the ADR
                // instruction will be relaxed to a value.
 altlabel:      // This label does not have function type, so will not have the
                // LSB set.
+       adr     c0, x
+       adr     c0, f
+       adr     c0, a   // Local C64 function on instruction that does not
+                       // ignore LSB so we the LSB included in the output.
+       adr     c0, altlabel
        b       x
        b       f
        b       a
index aa99c58a70c4e1a104525fef1d8eb997a346ad06..2b9386954fde61eb595e20fef42b1be94b989610 100644 (file)
@@ -3,16 +3,18 @@
 #source: morello-lsb-relocs.s
 
 
-Relocation section '\.rela\.text' at offset 0x198 contains 8 entries:
+Relocation section '\.rela\.text' at offset 0x1a8 contains 10 entries:
   Offset          Info           Type           Sym\. Value    Sym\. Name \+ Addend
-00000000000c  00090000e002 R_MORELLO_JUMP26  0000000000000000 x \+ 0
-000000000010  00080000e002 R_MORELLO_JUMP26  000000000000000d f \+ 0
-00000000001c  00090000e001 R_MORELLO_CONDBR1 0000000000000000 x \+ 0
-000000000020  00080000e001 R_MORELLO_CONDBR1 000000000000000d f \+ 0
-00000000002c  00090000e000 R_MORELLO_TSTBR14 0000000000000000 x \+ 0
-000000000030  00080000e000 R_MORELLO_TSTBR14 000000000000000d f \+ 0
-00000000003c  00090000e003 R_MORELLO_CALL26  0000000000000000 x \+ 0
-000000000040  00080000e003 R_MORELLO_CALL26  000000000000000d f \+ 0
+00000000000c  000900000112 R_AARCH64_ADR_PRE 0000000000000000 x \+ 0
+000000000010  000800000112 R_AARCH64_ADR_PRE 000000000000000d f \+ 0
+00000000001c  00090000e002 R_MORELLO_JUMP26  0000000000000000 x \+ 0
+000000000020  00080000e002 R_MORELLO_JUMP26  000000000000000d f \+ 0
+00000000002c  00090000e001 R_MORELLO_CONDBR1 0000000000000000 x \+ 0
+000000000030  00080000e001 R_MORELLO_CONDBR1 000000000000000d f \+ 0
+00000000003c  00090000e000 R_MORELLO_TSTBR14 0000000000000000 x \+ 0
+000000000040  00080000e000 R_MORELLO_TSTBR14 000000000000000d f \+ 0
+00000000004c  00090000e003 R_MORELLO_CALL26  0000000000000000 x \+ 0
+000000000050  00080000e003 R_MORELLO_CALL26  000000000000000d f \+ 0
 
 Symbol table '\.symtab' contains 10 entries:
    Num:    Value          Size Type    Bind   Vis      Ndx Name