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

[X86-64] Only treat PC-relative globals as memory content if they are dynamically relocated #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

martin-fink
Copy link
Contributor

This makes sure that both of the following work as expected:

  1. mov eax, [rip + myglob@GOTPCREL]
    used for shared libraries compiled to position independent code (-fPIC). Here myglob is dynamically relocated through the GOT
  2. mov eax, [rip + myglob]
    used for non-PIC code to access a global directly without any indirection through the GOT

The added test verifies that 2. works, which was broken previously (the code would print the address of i instead of its value). The tests globalvar-test.c and dhrystone verify that 1. works as expected.

I've implemented this by adding a set that keeps track of global variables that have DynRelocType == ELF::R_X86_64_GLOB_DAT.

@martin-fink martin-fink force-pushed the bugfix/pcrel-mem-access branch 2 times, most recently from 7a6f9c2 to 04c32ab Compare September 13, 2021 09:11
@martin-fink martin-fink force-pushed the bugfix/pcrel-mem-access branch from 04c32ab to bd633cb Compare September 25, 2021 07:47
… dynamically relocated

This makes sure that both of the following work as expected:

1. mov eax, [rip + myglob@GOTPCREL]
   used for shared libraries compiled to position independent code (-fPIC)
   Here myglob is dynamically relocated through the GOT
2. mov eax, [rip + myglob]
   used for non-PIC code to access a global directly without any
   indirection through the GOT

[Test] Added one test to verify RIP-relative globals work as expected
@martin-fink martin-fink force-pushed the bugfix/pcrel-mem-access branch from bd633cb to 0fc6971 Compare January 16, 2022 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants