Bug 21315 - multiple misaligned address errors for Elf64_Shdr
Summary: multiple misaligned address errors for Elf64_Shdr
Status: RESOLVED OBSOLETE
Alias: None
Product: elfutils
Classification: Unclassified
Component: libelf (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-27 12:07 UTC by Agostino Sarubbo
Modified: 2017-05-24 20:18 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
errors (270 bytes, text/plain)
2017-03-27 12:07 UTC, Agostino Sarubbo
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Agostino Sarubbo 2017-03-27 12:07:25 UTC
Created attachment 9947 [details]
errors

On elfutils-0.168:

# eu-elflint -d $FILE
libelf/elf32_getshdr.c:140:8: runtime error: member access within misaligned address 0x7fa161766002 for type 'struct Elf64_Shdr', which requires 8 byte alignment


Compiled with: gcc-6.3.0
Visible with: -fsanitize=undefined

Reproducer:
https://github.com/asarubbo/poc/blob/master/00237-elfutils-misalignedaddress1

Errors attached.
Comment 1 Mark Wielaard 2017-04-03 15:07:06 UTC
Note that in some cases elfutils deliberately does unaligned accesses if it believes it is safe. See the following in lib/eu-config.h:

/* Define ALLOW_UNALIGNED if the architecture allows operations on
   unaligned memory locations.  */
#define SANITIZE_UNDEFINED 1
#if (defined __i386__ || defined __x86_64__) && ! CHECK_UNDEFINED
# define ALLOW_UNALIGNED        1
#else
# define ALLOW_UNALIGNED        0
#endif

Note that it is to not allow unaligned accesses when configuring with --enable-sanitize-undefined (which adds -fsanitize=undefined -fno-sanitize-recover to CFLAGS and CXXFLAGS).

Are you configuring using --enable-sanitize-undefined? Or adding -fsanitize=undefined by hand? In the later case you should also add -DCHECK_UNDEFINED=1
Comment 2 Agostino Sarubbo 2017-04-03 16:37:50 UTC
(In reply to Mark Wielaard from comment #1)
> Note that in some cases elfutils deliberately does unaligned accesses if it
> believes it is safe. See the following in lib/eu-config.h:
> 
> /* Define ALLOW_UNALIGNED if the architecture allows operations on
>    unaligned memory locations.  */
> #define SANITIZE_UNDEFINED 1
> #if (defined __i386__ || defined __x86_64__) && ! CHECK_UNDEFINED
> # define ALLOW_UNALIGNED        1
> #else
> # define ALLOW_UNALIGNED        0
> #endif
> 
> Note that it is to not allow unaligned accesses when configuring with
> --enable-sanitize-undefined (which adds -fsanitize=undefined
> -fno-sanitize-recover to CFLAGS and CXXFLAGS).
> 
> Are you configuring using --enable-sanitize-undefined? Or adding
> -fsanitize=undefined by hand? In the later case you should also add
> -DCHECK_UNDEFINED=1

It was added by hand..I need to test if I obtain those warning with --enable-sanitize-undefined
Comment 3 Agostino Sarubbo 2017-05-20 16:08:47 UTC
Mark,

I do not have enough resources to make again my tests. Let's close this an the other similar report for now, I'll reopen them in the future in case will be needed.
Comment 4 Mark Wielaard 2017-05-24 20:18:58 UTC
Thanks. Closing for now.