From: Matthew Malcomson Date: Tue, 10 Aug 2021 11:05:44 +0000 (+0100) Subject: gas: ADR_LO21_PCREL accounts for LSB in symbol X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=855a447058ec619e12121ed28edce10f2cce55e2;p=thirdparty%2Fbinutils-gdb.git gas: ADR_LO21_PCREL accounts for LSB in symbol 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. --- diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c index f550d9e042f..5c0a8067168 100644 --- a/gas/config/tc-aarch64.c +++ b/gas/config/tc-aarch64.c @@ -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); diff --git a/gas/testsuite/gas/aarch64/morello-lsb-relocs.d b/gas/testsuite/gas/aarch64/morello-lsb-relocs.d index 226801b23a8..4fc9f867417 100644 --- a/gas/testsuite/gas/aarch64/morello-lsb-relocs.d +++ b/gas/testsuite/gas/aarch64/morello-lsb-relocs.d @@ -20,27 +20,33 @@ Disassembly of section \.text: \.\.\. 000000000000000c : - c: 14000000 b 0 - c: R_MORELLO_JUMP26 x - 10: 14000000 b c - 10: R_MORELLO_JUMP26 f - 14: 17fffffe b c - 18: 17fffffd b c - 1c: 5400000d b\.le 0 - 1c: R_MORELLO_CONDBR19 x - 20: 5400000d b\.le c - 20: R_MORELLO_CONDBR19 f - 24: 54ffff4d b\.le c - 28: 54ffff2d b\.le c - 2c: 36080001 tbz w1, #1, 0 - 2c: R_MORELLO_TSTBR14 x - 30: 36080001 tbz w1, #1, c - 30: R_MORELLO_TSTBR14 f - 34: 360ffec1 tbz w1, #1, c - 38: 360ffea1 tbz w1, #1, c - 3c: 94000000 bl 0 - 3c: R_MORELLO_CALL26 x - 40: 94000000 bl c - 40: R_MORELLO_CALL26 f - 44: 97fffff2 bl c - 48: 97fffff1 bl c + c: 10000000 adr c0, 0 + c: R_AARCH64_ADR_PREL_LO21 x + 10: 10000000 adr c0, c + 10: R_AARCH64_ADR_PREL_LO21 f + 14: 30ffffc0 adr c0, d + 18: 10ffffa0 adr c0, c + 1c: 14000000 b 0 + 1c: R_MORELLO_JUMP26 x + 20: 14000000 b c + 20: R_MORELLO_JUMP26 f + 24: 17fffffa b c + 28: 17fffff9 b c + 2c: 5400000d b\.le 0 + 2c: R_MORELLO_CONDBR19 x + 30: 5400000d b\.le c + 30: R_MORELLO_CONDBR19 f + 34: 54fffecd b\.le c + 38: 54fffead b\.le c + 3c: 36080001 tbz w1, #1, 0 + 3c: R_MORELLO_TSTBR14 x + 40: 36080001 tbz w1, #1, c + 40: R_MORELLO_TSTBR14 f + 44: 360ffe41 tbz w1, #1, c + 48: 360ffe21 tbz w1, #1, c + 4c: 94000000 bl 0 + 4c: R_MORELLO_CALL26 x + 50: 94000000 bl c + 50: R_MORELLO_CALL26 f + 54: 97ffffee bl c + 58: 97ffffed bl c diff --git a/gas/testsuite/gas/aarch64/morello-lsb-relocs.s b/gas/testsuite/gas/aarch64/morello-lsb-relocs.s index 227b023e220..26e498f59d0 100644 --- a/gas/testsuite/gas/aarch64/morello-lsb-relocs.s +++ b/gas/testsuite/gas/aarch64/morello-lsb-relocs.s @@ -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 diff --git a/gas/testsuite/gas/aarch64/morello-lsb-relocs2.d b/gas/testsuite/gas/aarch64/morello-lsb-relocs2.d index aa99c58a70c..2b9386954fd 100644 --- a/gas/testsuite/gas/aarch64/morello-lsb-relocs2.d +++ b/gas/testsuite/gas/aarch64/morello-lsb-relocs2.d @@ -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