Skip to content

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

Open
Martin Fink (martin-fink) wants to merge 1 commit into
microsoft:masterfrom
martin-fink:bugfix/pcrel-mem-access
Open

[X86-64] Only treat PC-relative globals as memory content if they are dynamically relocated#121
Martin Fink (martin-fink) wants to merge 1 commit into
microsoft:masterfrom
martin-fink:bugfix/pcrel-mem-access

Conversation

@martin-fink

Copy link
Copy Markdown
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 (martin-fink) force-pushed the bugfix/pcrel-mem-access branch 2 times, most recently from 7a6f9c2 to 04c32ab Compare September 13, 2021 09:11
Comment thread X86/X86MachineInstructionRaiser.cpp Outdated
… 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
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