[PATCH] D33647: [ELF] - Linkerscript: implement NOLOAD section type.
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Mon May 29 10:42:37 PDT 2017
George Rimar via Phabricator <reviews at reviews.llvm.org> writes:
> grimar created this revision.
> Herald added a subscriber: emaste.
>
> 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")));
>
> 2. Our script looks like:
>
> .data_noload_a 0x2000000 : { *(.data_noload_a) }
>
> Problem is that Var will be placed into .data section.
> (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.
It will be placed in the .data_noload_a section. I assume you mean the
problem is that it will be of type progbits and there is no syntax in
__attribute__ to mark it nobits instead.
> + // Read section type. Only NOLOAD is supported currently.
> + // https://sourceware.org/binutils/docs/ld/Output-Section-Type.html
> + if (peek() != ":") {
> + expect("(");
> + Cmd->Type = peek();
Since only noload is supported and we check that here I would suggest
replacing Type with at ForceToNoBits bool.
Cheers,
Rafael
More information about the llvm-commits
mailing list