This is an archive of the discontinued LLVM Phabricator instance.

[COFF] Fix SECTION and SECREL relocation handling for absolute symbols
ClosedPublic

Authored by rnk on Jun 22 2017, 4:20 PM.

Details

Summary

For SECTION relocations against absolute symbols, MSVC emits the largest
output section index plus one. I've implemented that by threading a
global variable through DefinedAbsolute that is filled in by the Writer.
A more library-oriented approach would be to thread the Writer through
Chunk::writeTo and SectionChunk::applyRel*, but Rui seems to prefer
doing it this way.

MSVC rejects SECREL relocations against absolute symbols, but only when
the relocation is in a real output section. When the relocation is in a
CodeView debug info section destined for the PDB, it seems that this
relocation error is suppressed, and absolute symbols become zeros in the
object file. This is easily implemented by checking the input section
from which we're applying relocations.

This should fix errors about safe_se_handler_table and
guard_fids_table when linking the CRT and generating a PDB.

Diff Detail

Repository
rL LLVM

Event Timeline

rnk created this revision.Jun 22 2017, 4:20 PM
ruiu accepted this revision.Jun 22 2017, 4:27 PM

LGTM

lld/COFF/Chunks.cpp
61 ↗(On Diff #103660)

nit: I would reverse the condition so that it becomes one line shorter.

lld/COFF/Symbols.cpp
64 ↗(On Diff #103660)

You want to use uint32_t.

This revision is now accepted and ready to land.Jun 22 2017, 4:27 PM
rnk marked an inline comment as done.Jun 22 2017, 4:31 PM
rnk added inline comments.
lld/COFF/Symbols.cpp
64 ↗(On Diff #103660)

True. uint16_t would probably be best.

This revision was automatically updated to reflect the committed changes.