This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug translation/64905] New: unsigned short is loaded with 4-byte load (movl)
- From: "r.ayrapetyan at samsung dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 02 Feb 2015 18:03:35 +0000
- Subject: [Bug translation/64905] New: unsigned short is loaded with 4-byte load (movl)
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64905
Bug ID: 64905
Summary: unsigned short is loaded with 4-byte load (movl)
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: translation
Assignee: unassigned at gcc dot gnu.org
Reporter: r.ayrapetyan at samsung dot com
Created attachment 34646
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34646&action=edit
Repro case source
Version, target:
gcc version 5.0.0 20150128 (experimental)
x86_64-unknown-linux-gnu
Issue:
In some cases, uint16_t data element is read with 4-byte load (movl
instruction).
Repro case build string:
gcc -g -Os \
-ffixed-rax -ffixed-rbx -ffixed-rcx -ffixed-rdx \
-ffixed-rdi -ffixed-rsi \
-ffixed-r8 -ffixed-r9 -ffixed-r10 -ffixed-r11 \
-ffixed-r12 -ffixed-r13 -ffixed-r14 -ffixed-r15 \
unaligned_read.c -o unaligned_read
Preliminary analysis:
In the example, ffixed- options are passed to force pointer allocation on the
%rbp register.
There is another real-world example without ffixed- options, where pointer
was allocated on the %rbp register and that caused out-of-boundaries memory
access.
1. The pointer to uint16_t data element was allocated on the %rbp register
that is marked as aligned to STACK_BOUNDARY.
2. get_attr_mode called from movhi_internal returns MODE_SI for the
instruction.
This can lead to the following problems:
1. unaligned memory access (reduced performance);
2. segmentation fault due to accessing unmapped page (or page mapped with
PROT_NONE)
// mapped page with array of uint16_t | unmapped page
function (&array [index_of_last_element_on_the_mapped_page]);
3. memory access checkers complain about accessing memory out of allocated
array boundaries.