Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple X32 miscompilation #55061

Closed
henke96 opened this issue Apr 24, 2022 · 4 comments
Closed

Simple X32 miscompilation #55061

henke96 opened this issue Apr 24, 2022 · 4 comments
Assignees
Labels

Comments

@henke96
Copy link

henke96 commented Apr 24, 2022

test.c:

void test(void) {
    *(int *)0x80000000 = 0x123;
}

Compile with: clang -target x86_64-unknown-linux-gnux32 -O1 -c test.c

objdump test.o --disassemble=test shows:

00000000 <test>:
   0:   c7 04 25 00 00 00 80    movl   $0x123,0xffffffff80000000
   7:   23 01 00 00 
   b:   c3                      retq 

It stores the value to address 0xffffffff80000000 instead of the expected 0x80000000.

Seems to only happen with optimizations enabled, and only if bit 32 is set in the address.

@llvmbot
Copy link
Member

llvmbot commented Apr 24, 2022

@llvm/issue-subscribers-backend-x86

@RKSimon
Copy link
Collaborator

RKSimon commented Apr 24, 2022

CC @hvdijk

@hvdijk
Copy link
Contributor

hvdijk commented Apr 24, 2022

Confirmed. I was initially thinking this is unlikely to affect real programs since all symbols are guaranteed to be located in the low 2GB virtual address space, but no such restriction is present for mmap with MAP_FIXED: (int *)0x80000000 can be made a valid pointer that way.

@RKSimon RKSimon added the confirmed Verified by a second party label Apr 25, 2022
@hvdijk
Copy link
Contributor

hvdijk commented Apr 25, 2022

RKSimon added a commit that referenced this issue Sep 20, 2023
Test file showing current codegen for D124406
@hvdijk hvdijk closed this as completed in 8d52097 Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants