[ELF] Support (TYPE=<value>) to customize the output section type
authorFangrui Song <i@maskray.me>
Thu, 17 Feb 2022 20:10:58 +0000 (12:10 -0800)
committerFangrui Song <i@maskray.me>
Thu, 17 Feb 2022 20:10:58 +0000 (12:10 -0800)
commit66f8ac8d3604d67599734c3fd272032e9448aca2
tree3021e56b8d9e15369b4da3c42705f5dd7651760d
parent9f7075de5c6200f4efda736220ca7716738a5e0e
[ELF] Support (TYPE=<value>) to customize the output section type

The current output section type allows to set the ELF section type to
SHT_PROGBITS or SHT_NOLOAD. This patch allows an arbitrary section value
to be specified. Some common SHT_* literal names are supported as well.

```
SECTIONS {
  note (TYPE=SHT_NOTE) : { BYTE(8) *(note) }
  init_array ( TYPE=14 ) : { QUAD(14) }
  fini_array (TYPE = SHT_FINI_ARRAY) : { QUAD(15) }
}
```

When `sh_type` is specified, it is an error if an input section has a different type.

Our syntax is compatible with GNU ld 2.39 (https://sourceware.org/bugzilla/show_bug.cgi?id=28841).

Reviewed By: peter.smith

Differential Revision: https://reviews.llvm.org/D118840
lld/ELF/OutputSections.cpp
lld/ELF/OutputSections.h
lld/ELF/ScriptParser.cpp
lld/docs/ELF/linker_script.rst
lld/test/ELF/linkerscript/custom-section-type.s [new file with mode: 0644]
lld/test/ELF/linkerscript/noload.s