This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Change (NOLOAD) type mismatch to use SHT_NOBITS instead of SHT_PROGBITS
ClosedPublic

Authored by MaskRay on May 5 2022, 9:14 PM.

Details

Summary

Placing a non-SHT_NOBITS input section in an output section specified with
(NOLOAD) is fishy but used by some projects. D118840 changed the output type to
SHT_PROGBITS, but using the specified type seems to make more sense and improve
GNU ld compatibility: (NOLOAD) seems to change the output section type
regardless of input.

I think we should keep the current type mismatch warning as it does indicate an
error-prone usage.

Diff Detail

Event Timeline

MaskRay created this revision.May 5 2022, 9:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 5 2022, 9:14 PM
MaskRay requested review of this revision.May 5 2022, 9:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 5 2022, 9:14 PM
MaskRay retitled this revision from [ELF] Change (NOLOAD) type mismatch to use the specified type instead of SHT_PROGBITS to [ELF] Change (NOLOAD) type mismatch to use SHT_NOBITS instead of SHT_PROGBITS.May 5 2022, 9:14 PM

Thanks fangrui.

manojgupta added inline comments.May 5 2022, 10:59 PM
lld/ELF/OutputSections.cpp
127

please remove tab.

MaskRay marked an inline comment as done.May 5 2022, 11:34 PM
MaskRay added inline comments.
lld/ELF/OutputSections.cpp
127

There is no tab. Phabricator may display increasing indent with >>.

peter.smith accepted this revision.May 6 2022, 3:52 AM

From doing some reading about NOLOAD, there is a use case for SHT_PROGBITS in NOLOAD. In an embedded system it can represent something like a ROM that is always present on the device at that address. This gets modelled as SHT_NOBITS so that addresses are calculated but not written to the file. Whomever writes the ZI initialization code will obviously have to make sure not to try and write that ZI.

References:
https://community.st.com/s/question/0D50X0000A7UjmzSQC/understanding-of-noload-directive-for-gnuld
https://software-dl.ti.com/ccs/esd/documents/sdto_cgt_linker_special_section_types.html (Strictly speaking this is TI's linker which has some extensions)
https://www.embeddedrelated.com/showthread/comp.arch.embedded/276222-1.php

This revision is now accepted and ready to land.May 6 2022, 3:52 AM
This revision was automatically updated to reflect the committed changes.
MaskRay marked an inline comment as done.