This is an archive of the discontinued LLVM Phabricator instance.

[COFF] Adjust secrel limit check
ClosedPublic

Authored by smeenai on Sep 18 2017, 7:48 PM.

Details

Summary

According to Microsoft's PE/COFF documentation, a SECREL relocation is
"The 32-bit offset of the target from the beginning of its section". By
my reading, the "from the beginning of its section" implies that the
offset is unsigned.

Change from an assertion to an error, since it's possible to trigger
this condition normally for input files with very large sections, and we
should fail gracefully for those instead of asserting.

Diff Detail

Repository
rL LLVM

Event Timeline

smeenai created this revision.Sep 18 2017, 7:48 PM

Again, I'm not sure how to create a test for this one without creating gigantic (> 2 GiB) intermediate object files. The .bss trick won't work here, since we can't have relocations in a .bss section.

compnerd edited edge metadata.Sep 19 2017, 10:35 AM

Sorry I wasn't able to get around to this. Im not sure if we can add a test for this. Generating a 4GiB binary from the assembler takes a while.

ruiu added inline comments.Sep 19 2017, 12:28 PM
COFF/Chunks.cpp
65 ↗(On Diff #115779)

Can you use error() instead of assert()? If you can intentionally trigger an assertion, it shouldn't be an assert() but should be handled by error().

smeenai added inline comments.Sep 19 2017, 4:08 PM
COFF/Chunks.cpp
65 ↗(On Diff #115779)

I thought about that, but I think an assertion is actually the right thing here. D38005 makes it so that a section larger than 4 GiB will trigger an error, which means relocation processing can assume that as a precondition, and a SecRel larger than 4 GiB implies a section larger than 4 GiB, which implies a precondition violation. Does that seem reasonable?

On the other hand, since D38005 is using error, I suppose it's possible to enter here with a section larger than 4 GiB which you've already issued an error for previously (but processing continued after issuing that error), so that makes it slightly less clear.

ruiu added inline comments.Sep 19 2017, 4:12 PM
COFF/Chunks.cpp
65 ↗(On Diff #115779)

When you call error() it won't immediately exit. If you explicitly return if ErrorCount is larger than zero before reaching this function, then yes, it's a precondition and assert would be the best choice.

smeenai updated this revision to Diff 115933.Sep 19 2017, 5:14 PM
smeenai retitled this revision from [COFF] Adjust secrel limit assertion to [COFF] Adjust secrel limit check.
smeenai edited the summary of this revision. (Show Details)

Change to error

smeenai updated this revision to Diff 115934.Sep 19 2017, 5:15 PM

Bail out of function in case of error

Harbormaster completed remote builds in B10434: Diff 115934.
ruiu accepted this revision.Sep 19 2017, 5:21 PM

LGTM

This revision is now accepted and ready to land.Sep 19 2017, 5:21 PM
This revision was automatically updated to reflect the committed changes.