This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] tile: Fix up corner cases with signed relocations
- From: Chris Metcalf <cmetcalf at tilera dot com>
- To: Andreas Schwab <schwab at linux-m68k dot org>
- Cc: <libc-alpha at sourceware dot org>
- Date: Sat, 6 Sep 2014 12:16:09 -0400
- Subject: Re: [PATCH] tile: Fix up corner cases with signed relocations
- Authentication-results: sourceware.org; auth=none
- References: <201409051854 dot s85IsfM0024659 at gx-1 dot internal dot tilera dot com> <8761h1hkog dot fsf at linux-m68k dot org> <540A1F34 dot 2020303 at tilera dot com> <871trphhkr dot fsf at linux-m68k dot org>
On 9/5/2014 5:40 PM, Andreas Schwab wrote:
On 9/5/2014 4:33 PM, Andreas Schwab wrote:
Chris Metcalf <cmetcalf@tilera.com> writes:
@@ -686,13 +686,17 @@ elf_machine_rela (struct link_map *map, const ElfW(Rela) *reloc,
tile_bundle_bits *p = (tile_bundle_bits *) reloc_addr;
tile_bundle_bits bits = *p;
-#define MUNGE(func) do {
\
+#define MUNGE_SIGNED(func, length) do { \
bits = ((bits & ~create_##func (-1)) | create_##func (value)); \
- if (get_##func (bits) != value) \
+ ElfW(Addr) result = (long) get_##func (bits) \
+ << (__WORDSIZE - length) >> (__WORDSIZE - length); \
Left shifting a negative value has undefined value.
I'm talking about the value, not the shift amount.
Right, sorry. On tile, the compiler will always generate a "shli" for shifting an unknown value by a known constant, and shli is defined with unsigned semantics on tile, so in practice this code generates the correct value.
That said, you're right that we're better off to avoid relying on undefined behavior, so, thanks. I've changed that part of the code to look like:
ElfW(Addr) result = get_##func (bits); \
int signbits = __WORDSIZE - length; \
result = (long) (result << signbits) >> signbits; \
I'll go ahead and push the commit with that change.
--
Chris Metcalf, Tilera Corp.
http://www.tilera.com