From: Alan Modra Date: Mon, 9 Jun 2025 11:04:02 +0000 (+0930) Subject: gas: xtensa build failure with --enable-64-bit-bfd X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2bc3171316931e79321a21c6bf59b4a0d42b74a7;p=thirdparty%2Fbinutils-gdb.git gas: xtensa build failure with --enable-64-bit-bfd A 32-bit host with --enable-64-bit-bfd --target=xtensa-lx106-elf give: gas/config/tc-xtensa.c: In function ‘xg_get_best_chain_entry’: gas/config/tc-xtensa.c:7689:11: error: absolute value function ‘labs’ given an argument of type ‘offsetT’ {aka ‘long long int’} but has parameter of type ‘long int’ which may cause truncation of value [-Werror=absolute-value] 7689 | if (labs (off) >= J_RANGE - J_MARGIN) | ^~~~ Let's not use labs. Unlike labs vma_abs deliberately returns an unsigned value, and does the negation in an unsigned type so that signed overflow can't happen. * config/tc-xtensa.c (vma_abs): New function. (xg_get_best_chain_entry, xg_get_fulcrum, xg_find_best_trampoline), (xg_is_relaxable_fixup): Use in place of labs. --- diff --git a/gas/config/tc-xtensa.c b/gas/config/tc-xtensa.c index ed53b6d7c31..18896080fbb 100644 --- a/gas/config/tc-xtensa.c +++ b/gas/config/tc-xtensa.c @@ -7660,6 +7660,12 @@ static size_t xg_find_chain_entry (struct trampoline_chain *tc, return a; } +static valueT +vma_abs (offsetT v) +{ + return v < 0 ? -(valueT) v : (valueT) v; +} + /* Find the best jump target for the source in the given trampoline chain. The best jump target is the one that results in the shortest path to the final target, it's the location of the jump closest to the final target, @@ -7686,7 +7692,7 @@ xg_get_best_chain_entry (struct trampoline_chain *tc, addressT source) chained_target = S_GET_VALUE(next->sym) + next->offset; off = source - chained_target; - if (labs (off) >= J_RANGE - J_MARGIN) + if (vma_abs (off) >= J_RANGE - J_MARGIN) break; i += step; @@ -7696,8 +7702,8 @@ xg_get_best_chain_entry (struct trampoline_chain *tc, addressT source) chained_target = S_GET_VALUE(e->sym) + e->offset; off = source - chained_target; - if (labs (off) < J_MARGIN || - labs (off) >= J_RANGE - J_MARGIN) + if (vma_abs (off) < J_MARGIN + || vma_abs (off) >= J_RANGE - J_MARGIN) return &tc->target; return tc->entry + i; } @@ -9359,7 +9365,7 @@ static addressT xg_get_fulcrum (addressT source, addressT target) offsetT delta = target - source; int n; - n = (labs (delta) + J_RANGE - J_MARGIN - 1) / (J_RANGE - J_MARGIN); + n = (vma_abs (delta) + J_RANGE - J_MARGIN - 1) / (J_RANGE - J_MARGIN); return source + delta / n; } @@ -9410,11 +9416,11 @@ static size_t xg_find_best_trampoline (struct trampoline_index *idx, /* Stop if some trampoline is found and the search is more than J_RANGE / 4 from the projected fulcrum. A trampoline w/o jump around is nice, but it shouldn't have much overhead. */ - if (best < idx->n_entries && labs (off) > J_RANGE / 4) + if (best < idx->n_entries && vma_abs (off) > J_RANGE / 4) return best; off = trampoline_frag->fr_address - source; - if (labs (off) < J_RANGE - J_MARGIN) + if (vma_abs (off) < J_RANGE - J_MARGIN) { ++checked; /* Stop if a trampoline w/o jump around is found or initialized @@ -9480,7 +9486,7 @@ static bool xg_is_relaxable_fixup (fixS *fixP) target = S_GET_VALUE (s) + fixP->fx_offset; delta = target - addr; - if (labs (delta) < J_RANGE - J_MARGIN) + if (vma_abs (delta) < J_RANGE - J_MARGIN) return false; xtensa_insnbuf_from_chars (isa, trampoline_buf,