diff options
author | Alan Modra <amodra@gmail.com> | 2021-12-21 01:09:13 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2021-12-28 23:00:01 +1030 |
commit | 443aa5f05edb58fc1774f926e9259b7c5a180926 (patch) | |
tree | ebc72377ef825f1da276fa3080f91fb49a143341 /gas/config/tc-nds32.c | |
parent | 4748764aaba89b8515cbf8918dc0ada840cdfab7 (diff) | |
download | gdb-443aa5f05edb58fc1774f926e9259b7c5a180926.zip gdb-443aa5f05edb58fc1774f926e9259b7c5a180926.tar.gz gdb-443aa5f05edb58fc1774f926e9259b7c5a180926.tar.bz2 |
gas reloc sorting
In some cases, eg. riscv_pre_output_hook, gas generates out-of-order
relocations. Various places in the linker assume relocs are sorted
by increasing r_offset, which is normally the case. Provide
GAS_SORT_RELOCS to handle unsorted relocs.
bfd/
PR 28709
* elf32-nds32.c (nds32_insertion_sort): Make static.
* elf32-nds32.h (nds32_insertion_sort): Delete declaration.
gas/
PR 28709
* write.c (write_relocs): Implement reloc sorting by r_offset
when GAS_SORT_RELOCS.
* config/tc-nds32.c (compar_relent, nds32_set_section_relocs): Delete.
* config/tc-nds32.h (nds32_set_section_relocs): Don't declare.
(SET_SECTION_RELOCS): Don't define.
(GAS_SORT_RELOCS): Define.
* config/tc-riscv.h (GAS_SORT_RELOCS): Define.
Diffstat (limited to 'gas/config/tc-nds32.c')
-rw-r--r-- | gas/config/tc-nds32.c | 39 |
1 files changed, 0 insertions, 39 deletions
diff --git a/gas/config/tc-nds32.c b/gas/config/tc-nds32.c index 0ab436c..228afa6 100644 --- a/gas/config/tc-nds32.c +++ b/gas/config/tc-nds32.c @@ -7537,45 +7537,6 @@ nds32_allow_local_subtract (expressionS *expr_l ATTRIBUTE_UNUSED, return false; } -/* Sort relocation by address. - - We didn't use qsort () in stdlib, because quick-sort is not a stable - sorting algorithm. Relocations at the same address (r_offset) must keep - their relative order. For example, RELAX_ENTRY must be the very first - relocation entry. - - Currently, this function implements insertion-sort. */ - -static int -compar_relent (const void *lhs, const void *rhs) -{ - const arelent **l = (const arelent **) lhs; - const arelent **r = (const arelent **) rhs; - - if ((*l)->address > (*r)->address) - return 1; - else if ((*l)->address == (*r)->address) - return 0; - else - return -1; -} - -/* SET_SECTION_RELOCS () - - Although this macro is originally used to set a relocation for each section, - we use it to sort relocations in the same section by the address of the - relocation. */ - -void -nds32_set_section_relocs (asection *sec ATTRIBUTE_UNUSED, - arelent **relocs, unsigned int n) -{ - if (n <= 1) - return; - - nds32_insertion_sort (relocs, n, sizeof (*relocs), compar_relent); -} - long nds32_pcrel_from_section (fixS *fixP, segT sec ATTRIBUTE_UNUSED) { |