]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas: xtensa build failure with --enable-64-bit-bfd
authorAlan Modra <amodra@gmail.com>
Mon, 9 Jun 2025 11:04:02 +0000 (20:34 +0930)
committerAlan Modra <amodra@gmail.com>
Tue, 10 Jun 2025 21:56:07 +0000 (07:26 +0930)
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.

gas/config/tc-xtensa.c

index ed53b6d7c310cd5ec3f59abf8014ded8ed616d06..18896080fbbfc0fb2e5b23832d22a1c815578b43 100644 (file)
@@ -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,