]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
elf: Adjust DT_EXTRATAGIDX to avoid undefined shifts
authorRichard Henderson <rth@twiddle.net>
Thu, 17 Apr 2025 20:58:35 +0000 (17:58 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 7 May 2025 13:41:34 +0000 (10:41 -0300)
When building with --enable-ubsan, the relocation code triggers:

UBSAN: Undefined behaviour in get-dynamic-info.h:56:30 left shift of 1879047925 by 1 cannot be represented in type 'int'

Originally from
https://sourceware.org/pipermail/libc-alpha/2015-August/063015.html.

elf/elf.h

index 1e1a59c14d2eb5516e50261d02dc490085e24b2c..d48cf47b9a82a0003f16a078728e08cc87cfe712 100644 (file)
--- a/elf/elf.h
+++ b/elf/elf.h
@@ -995,7 +995,7 @@ typedef struct
    range.  Be compatible.  */
 #define DT_AUXILIARY    0x7ffffffd      /* Shared object to load before self */
 #define DT_FILTER       0x7fffffff      /* Shared object to get values from */
-#define DT_EXTRATAGIDX(tag)    ((Elf32_Word)-((Elf32_Sword) (tag) <<1>>1)-1)
+#define DT_EXTRATAGIDX(tag)  (-((Elf32_Sword)((Elf32_Word)(tag) * 2) / 2 + 1))
 #define DT_EXTRANUM    3
 
 /* Values of `d_un.d_val' in the DT_FLAGS entry.  */