This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Linkerscript: implement NOLOAD section type.
ClosedPublic

Authored by grimar on May 29 2017, 6:45 AM.

Details

Summary

This is PR32351

Each output section may have a type. The type is a keyword in parentheses. The following types are defined:
NOLOAD
The section should be marked as not loadable, so that it will not be loaded into memory when the program is run.
(https://sourceware.org/binutils/docs/ld/Output-Section-Type.html#Output-Section-Type)

Parch makes such sections to be SHT_NOBITS. That looks consistent with what BFD do. Gold do something different now,
what looks like a wrong implementation simply.

Use case is next (taken from https://mcuoneclipse.com/2014/04/19/gnu-linker-can-you-not-initialize-my-variable/):

  1. We want to place variable at absolute address and use next code:
static unsigned char Var[4096] __attribute__((section (".data_noload_a")));
  1. Our script looks like:
.data_noload_a 0x2000000 : { *(.data_noload_a) }

Problem is that Var will stop be SHT_NOBITS and became SHT_PROGBITS.
(if attribute used with section, the variable is treated like an initialized variable, see article above)
We may want to save space, and do not write 4096 of zeroes to output file. NOLOAD is a solution.

NOLOAD forces output section to be SHT_NOBITS.

Diff Detail

Event Timeline

grimar created this revision.May 29 2017, 6:45 AM
grimar updated this revision to Diff 100666.May 29 2017, 11:24 PM
  • Addressed review comments.
grimar edited the summary of this revision. (Show Details)May 29 2017, 11:27 PM
ruiu added inline comments.Jun 5 2017, 3:11 PM
ELF/LinkerScript.h
134

Noload is probably a better name.

ELF/ScriptParser.cpp
575

Read a section type. Currently, only NOLOAD is supported.

577

You can move this above if (peek() != ":"), no?

grimar updated this revision to Diff 101516.Jun 6 2017, 12:06 AM
  • Addressed review comments.
ELF/LinkerScript.h
134

Done.

ELF/ScriptParser.cpp
575

Done.

577

Do you mean something like this (new diff) ?

ruiu added inline comments.Jun 6 2017, 9:07 AM
ELF/ScriptParser.cpp
576

Why can't you do peek() != "("?

grimar updated this revision to Diff 101744.Jun 7 2017, 8:33 AM
  • Addressed review comments.
ELF/ScriptParser.cpp
576

My mistype/mistake =\ Sure we can do that.

ruiu accepted this revision.Jun 7 2017, 9:15 AM

LGTM

ELF/LinkerScript.cpp
431–432

Move this before SecToCmd[Sec] = Cmd; so that assignments to Sec->{SectionIndex,Type} are next to each other in the source code.

This revision is now accepted and ready to land.Jun 7 2017, 9:15 AM
This revision was automatically updated to reflect the committed changes.