This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Set __PAGEZERO size to 4GB
ClosedPublic

Authored by int3 on May 18 2020, 9:09 PM.

Details

Summary

That's what ld64 uses for 64-bit targets. I figured it's best
to make this change sooner rather than later since a bunch of our tests
are relying on hardcoded addresses that depend on this value.

Depends on D80169.

Diff Detail

Event Timeline

int3 created this revision.May 18 2020, 9:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 18 2020, 9:09 PM
smeenai requested changes to this revision.May 19 2020, 1:43 PM

Thanks for fixing this! It'll make it way easier to compare results with ld64.

Requesting changes cos I think we're gonna mess up entryoff as this stands, and we definitely need to add test coverage for that.

lld/MachO/Target.h
30

It's really confusing to have PageZeroSize and ImageBase be different, and for that matter, to have both of them.

With this diff, we're only using ImageBase in one place: https://github.com/llvm/llvm-project/blob/master/lld/MachO/Writer.cpp#L171. From looking into LC_MAIN, it seems like the entryoff is supposed to be an offset in the file rather than a virtual address, so computing it in terms of getVA is confusing. We should also fix that and then get rid of either ImageBase or PageZeroSize.

For that matter, is our LC_MAIN entryoff calculation gonna be correct after this? I have a hard time imagining that, and we don't have any tests for it :/

This revision now requires changes to proceed.May 19 2020, 1:43 PM
int3 marked 2 inline comments as done.May 19 2020, 3:10 PM
int3 added inline comments.
lld/MachO/Target.h
30

oops, good catch...

int3 updated this revision to Diff 265057.May 19 2020, 3:10 PM
int3 marked an inline comment as done.

fix and add test

int3 updated this revision to Diff 265058.May 19 2020, 3:13 PM

make ENTRYOFF a numeric var

smeenai accepted this revision.May 19 2020, 3:34 PM

Looks great, thanks!

lld/MachO/Symbols.h
111

This is *definitely* follow-up territory, but we should figure out if it ever makes sense for getFileOffset to be called on a non-defined symbol, and if not, just fail loudly in that case instead of silently returning 0.

This revision is now accepted and ready to land.May 19 2020, 3:34 PM
int3 marked an inline comment as done.May 19 2020, 4:12 PM
int3 added inline comments.
lld/MachO/Symbols.h
111

oh good point. I doubt it would ever be valid; I can just insert a fatal here. Does it really need to be in a follow-up?

smeenai added inline comments.May 19 2020, 4:36 PM
lld/MachO/Symbols.h
111

It doesn't need to be a follow-up. I just didn't mean the comment to block this diff, but folding it in here is great too.

smeenai added inline comments.May 20 2020, 12:32 PM
lld/MachO/Symbols.h
111

I'd probably use llvm_unreachable, since reaching this would be purely a logic error in the linker rather then e.g. something that could be triggered by broken or unsupported input.

int3 updated this revision to Diff 265372.May 20 2020, 3:53 PM

llvm_unreachable

This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.Jun 2 2020, 2:14 PM

Looks like this is failing on Windows: http://45.33.8.238/win/16635/step_10.txt

int3 added a comment.Jun 2 2020, 3:28 PM

Thanks for the heads up, just pushed a likely fix and will monitor http://lab.llvm.org:8011/builders/lld-x86_64-win. I'll set up a local Windows VM to catch future such issues earlier...

Thanks for the heads up, just pushed a likely fix and will monitor http://lab.llvm.org:8011/builders/lld-x86_64-win. I'll set up a local Windows VM to catch future such issues earlier...

@int3, can you please point out the fix you pushed? The tests are failing downstream, and I am looking for the commit that fixes it.

Moreover, in the head llvm-project there are still issues for 32-bit host builds:

enum : uint64_t {
...
  PageZeroSize = 1ull << 32, // XXX should be 4096 for 32-bit targets
...
};

PageZeroSize is a 64-bit constant, but it is being returned as size_t, which is 4 bytes for 32-bit hosts:

class PageZeroSection : public SyntheticSection {
...
  size_t getSize() const override { return PageZeroSize; }
...

Could you please fix this?

int3 added a comment.Jun 16 2020, 3:46 PM

rGd767de44bf9527cb5058f5fe16aac2f23c21977c was the referenced fix. Good point about size_t, I'll change that

rGd767de44bf9527cb5058f5fe16aac2f23c21977c was the referenced fix. Good point about size_t, I'll change that

Thanks. The enum change does not fix the fails on my side. I guess it has to be the size_t issue.