This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Export trie addresses should be relative to the image base
ClosedPublic

Authored by int3 on Sep 16 2020, 11:23 AM.

Details

Summary

We didn't notice this earlier this we were only testing the export trie
encoded in a dylib, whose image base starts at zero. But a regular
executable contains __PAGEZERO, which means it has a non-zero image
base. This bug was discovered after attempting to run some programs that
performed dlopen on an executable.

Diff Detail

Event Timeline

int3 created this revision.Sep 16 2020, 11:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 16 2020, 11:23 AM
int3 requested review of this revision.Sep 16 2020, 11:23 AM
smeenai accepted this revision.Sep 17 2020, 3:58 PM
smeenai added a subscriber: smeenai.

LGTM

lld/MachO/ExportTrie.h
36

Nit: do we need this initialization, given that setImageBase should always be called?

This revision is now accepted and ready to land.Sep 17 2020, 3:58 PM
int3 marked an inline comment as done.Sep 17 2020, 4:07 PM
int3 added inline comments.
lld/MachO/ExportTrie.h
36

I think it's good practice to zero-init fields that aren't initialized in the ctor. That way, if we forget to call setImageBase, we'll be more likely to get a deterministic error.

smeenai added inline comments.Sep 17 2020, 5:00 PM
lld/MachO/ExportTrie.h
36

The flip side is that any tools which detect uninitialized memory wouldn't catch the issue. It doesn't seem like either ASan or UBSan can actually catch the uninitialized access right now though, so that's a purely academic concern :)

This revision was landed with ongoing or failed builds.Sep 20 2020, 8:44 PM
This revision was automatically updated to reflect the committed changes.
int3 marked an inline comment as done.
smeenai added inline comments.Sep 21 2020, 11:55 AM
lld/MachO/ExportTrie.h
36

Ah, MSan is able to catch the uninitialized memory use, which is helpful.