Commit Graph

12150 Commits

Author SHA1 Message Date
Yuanfang Chen 40a156b791 [llvm-readobj] Match GNU output for DT_RPATH and DT_RUNPATH when dumping dynamic symbol table.
Reviewers: jhenderson, grimar, MaskRay, rupprecht, espindola

Subscribers: emaste, nemanjai, arichardson, kbarton, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D63347

llvm-svn: 363868
2019-06-19 19:31:07 +00:00
Reid Kleckner a702f07301 [PDB] Ignore .debug$S subsections with high bit set
Some versions of the Visual C++ 2015 runtime have line tables with the
subsection kind of 0x800000F2. In cvinfo.h, 0x80000000 is documented to
be DEBUG_S_IGNORE. This appears to implement the intended behavior.

llvm-svn: 363724
2019-06-18 19:41:25 +00:00
Francis Visoiu Mistrih 34667519dc [Remarks] Extend -fsave-optimization-record to specify the format
Use -fsave-optimization-record=<format> to specify a different format
than the default, which is YAML.

For now, only YAML is supported.

llvm-svn: 363573
2019-06-17 16:06:00 +00:00
Fangrui Song 46f9cbe28d [llvm-objdump] Use %08 instead of %016 to print leading addresses for 32-bit binaries
Reviewed By: grimar

Differential Revision: https://reviews.llvm.org/D63398

llvm-svn: 363539
2019-06-17 09:59:55 +00:00
Reid Kleckner 05e48cb9fa Include the file in the new unknown codeview subsection warning
llvm-svn: 363466
2019-06-14 22:03:23 +00:00
Martin Storsjo 2de984cd30 [COFF] Strip section name suffix from mingw comdats
This is the second part of the fix for PR42217.

Differential Revision: https://reviews.llvm.org/D63352

llvm-svn: 363457
2019-06-14 21:02:09 +00:00
Martin Storsjo c3b1d730d6 [COFF] Handle .eh_frame$symbol as associative comdat for MinGW
This matches how it is done for .xdata and .pdata already.

On i386, the symbol name in the section name suffix does not contain
the extra underscore prefix.

This is one part of a fix for PR42217.

Differential Revision: https://reviews.llvm.org/D63350

llvm-svn: 363456
2019-06-14 21:02:04 +00:00
Martin Storsjo ff4e0a9f3e [MinGW] Support the --subsystem=val option in joined form
Differential Revision: https://reviews.llvm.org/D63250

llvm-svn: 363433
2019-06-14 17:50:39 +00:00
Martin Storsjo 6f047ae58b [MinGW] Support the --{major,minor}-{os,subsystem}-version options
This fixes PR42218.

Differential Revision: https://reviews.llvm.org/D63249

llvm-svn: 363432
2019-06-14 17:50:35 +00:00
Martin Storsjo b20fefc89b [COFF] Allow setting subsystem versions while inferring the subsystem type implicitly
Differential Revision: https://reviews.llvm.org/D63248

llvm-svn: 363431
2019-06-14 17:50:29 +00:00
Nico Weber bea1286155 Wrap a test to 80 columns
llvm-svn: 363421
2019-06-14 16:47:07 +00:00
Nico Weber 96a15796fb Remove two unused parameters
llvm-svn: 363419
2019-06-14 16:46:02 +00:00
George Rimar 76d575312d [LLD][ELF] - Fix test case after r363401
llvm-svn: 363402
2019-06-14 14:26:34 +00:00
Fangrui Song e05ca38101 [ELF] Don't emit dynamic relocations with weak undef in writable sections
In processRelocAux(), our handling of 1) link-time constant and 2) weak
undef is the same, so put them together to simplify the logic.

This moves the weak undef code around. The result is that: in a writable
section (or -z notext), we will no longer emit dynamic relocations for
weak undefined symbols.

The new behavior seems to match GNU linkers, and improves consistency
with the case of a readonly section.

The condition `!Config->Shared` was there probably because it is common
for a -shared link not to specify full dependencies. Keep it now but we
may revisit the decision in the future.

gABI says:

> The behavior of weak symbols in areas not specified by this document is
> implementation defined. Weak symbols are intended primarily for use in
> system software. Applications using weak symbols are unreliable since
> changes in the runtime environment might cause the execution to fail.

Reviewed By: ruiu

Differential Revision: https://reviews.llvm.org/D63003

llvm-svn: 363399
2019-06-14 14:09:15 +00:00
George Rimar a59bc6e589 Revert r363395.
It will not work because of r363394.

llvm-svn: 363398
2019-06-14 14:06:03 +00:00
Nico Weber a35b935d39 lld/coff: slightly simplify ImportFile::parse()
llvm-svn: 363397
2019-06-14 14:03:08 +00:00
Rui Ueyama 43f4b037d5 Add --undefined-glob which is an --undefined with wildcard pattern match
This patch adds new command line option `--undefined-glob` to lld.
That option is a variant of `--undefined` but accepts wildcard
patterns so that all symbols that match with a given pattern are
handled as if they were given by `-u`.

`-u foo` is to force resolve symbol foo if foo is not a defined symbol
and there's a static archive that contains a definition of symbol foo.

Now, you can specify a wildcard pattern as an argument for `--undefined-glob`.
So, if you want to include all JNI symbols (which start with "Java_"), you
can do that by passing `--undefined-glob "Java_*"` to the linker, for example.

In this patch, I use the same glob pattern matcher as the version script
processor is using, so it does not only support `*` but also `?` and `[...]`.

Differential Revision: https://reviews.llvm.org/D63244

llvm-svn: 363396
2019-06-14 14:00:59 +00:00
George Rimar a0b0d626ab [ELF] - Attemp to fix BB.
Seems section has a wrong type.

http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/28

llvm-svn: 363395
2019-06-14 13:59:27 +00:00
Fangrui Song 5b4285d82d [ELF][RISCV] Create dummy .sdata for __global_pointer$ if .sdata does not exist
If .sdata is absent, linker synthesized __global_pointer$ gets a section index of SHN_ABS.
(ld.bfd has a similar issue: binutils PR24678)

Scrt1.o may use `lla gp, __global_pointer$` to reference the symbol PC
relatively. In -pie/-shared mode, lld complains if a PC relative
relocation references an absolute symbol (SHN_ABS) but ld.bfd doesn't:

    ld.lld: error: relocation R_RISCV_PCREL_HI20 cannot refer to lute symbol: __global_pointer$

Let the reference of __global_pointer$ to force creation of .sdata to
fix the problem. This is similar to _GLOBAL_OFFSET_TABLE_, which forces
creation of .got or .got.plt .

Also, change the visibility from STV_HIDDEN to STV_DEFAULT and don't
define the symbol for -shared. This matches ld.bfd, though I don't
understand why it uses STV_DEFAULT.

Reviewed By: ruiu, jrtc27

Differential Revision: https://reviews.llvm.org/D63132

llvm-svn: 363351
2019-06-14 02:14:53 +00:00
Eugene Leviant 0eb763c559 [lld][ELF] Add tests for bad subsection length in .ARM.attributes
Differential revision: https://reviews.llvm.org/D63191

llvm-svn: 363261
2019-06-13 13:41:28 +00:00
Fangrui Song a78e025558 [ELF] Loosen the condition that changes absolute relocation types to relative relocations for ARM and PPC64
Try fixing build bots after D63121

llvm-svn: 363236
2019-06-13 08:45:22 +00:00
Reid Kleckner 5584ab89a8 [lld] Fix type server merging with PDBs without IPI stream
PDBs may not necessarily contain an IPI stream. Handle this case
gracefully.

The test case was verified to work with MS link.exe.

Patch by Vladimir Panteleev, with a small simplification

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D63178

llvm-svn: 363213
2019-06-12 22:33:16 +00:00
Reid Kleckner efc01eac17 [lld] Allow unrecognized signatures in debug sections
An unrecognized signature (magic) at the beginning of a debug section
should not be a fatal error; it only means that the debug information
is in a format that is not supported by LLD. This can be due to it
being in CodeView versions 3 or earlier. These can occur in old import
libraries from legacy SDKs.

The test case was verified to work with MS link.exe.

Patch by Vladimir Panteleev!

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D63177

llvm-svn: 363212
2019-06-12 22:22:44 +00:00
Nico Weber 1dc2123d64 Share /machine: handling code with llvm-cvtres too
r363016 let lld-link and llvm-lib share the /machine: parsing code.
This lets llvm-cvtres share it as well.

Making llvm-cvtres depend on llvm-lib seemed a bit strange (it doesn't
need llvm-lib's dependencies on BinaryFormat and BitReader) and I
couldn't find a good place to put this code. Since it's just a few
lines, put it in lib/Object for now.

Differential Revision: https://reviews.llvm.org/D63120

llvm-svn: 363144
2019-06-12 11:32:43 +00:00
Fangrui Song 4ce0a519c1 [ELF][RISCV] Treat R_RISCV_{ADD,SET,SUB}* as link-time constants
R_RISCV_{ADD,SET,SUB}* are used for local label computation.
Add a new RelExpr member R_RISCV_ADD to represent them.

R_RISCV_ADD is treated as a link-time constant because otherwise
R_RISCV_{ADD,SET,SUB}* are not allowed in -pie/-shared mode.
In glibc Scrt1.o, .rela.eh_frame contains such relocations.
Because .eh_frame is not writable, we get this error:

    ld.lld: error: can't create dynamic relocation R_RISCV_ADD32 against symbol: .L0 in readonly segment; recompil object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output
    >>> defined in ..../riscv64-linux-gnu/lib/Scrt1.o

With D63076 and this patch, I can run -pie/-shared programs linked against glibc.

Note llvm-mc cannot currently produce R_RISCV_SET* so they are not tested.

Reviewed By: ruiu

Differential Revision: https://reviews.llvm.org/D63183

llvm-svn: 363128
2019-06-12 07:53:06 +00:00
Fangrui Song 11549e5c46 [ELF][PPC64] Don't report "relocation refers to a discarded section" for .toc
Summary:
clang (as of 2019-06-12) / gcc (as of 8.2.1) PPC64 may emit a .rela.toc
which references an embedded switch table in a discarded .rodata/.text
section. The .toc and the .rela.toc are incorrectly not placed in the
comdat.

Technically a relocation from outside the group is not allowed by the ELF spec:

> A symbol table entry with STB_LOCAL binding that is defined relative
> to one of a group's sections, and that is contained in a symbol table
> section that is not part of the group, must be discarded if the group
> members are discarded. References to this symbol table entry from
> outside the group are not allowed.

Don't report errors to work around the bug.

This should fix the ppc64le-lld-multistage-test bot while linking llvm-tblgen:

    ld.lld: error: relocation refers to a discarded section: .rodata._ZNK4llvm3MVT13getSizeInBitsEv
    >>> defined in utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenRegisters.cpp.o
    >>> referenced by CodeGenRegisters.cpp
    >>> utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenRegisters.cpp.o:(.toc+0x0)

Some other PPC specific sections may have similar problems. We can blacklist more
section names when problems occur.

    // A simple program that reproduces the bug.
    // Note .rela.toc (outside the group) references a section symbol (STB_LOCAL) in a group.
    void puts(const char *);
    struct A {
      void foo(int a) {
        switch (a) {
        case 0: puts("0"); break;
        case 1: puts("1"); puts("1"); break;
        case 2: puts("2"); break;
        case 3: puts("3"); puts("4"); break;
        case 4: puts("4"); break;
        case 5: puts("5"); puts("5"); break;
        case 6: puts("6"); break;
        }
      }
      int a;
    };
    void foo(A x) { x.foo(x.a); }

Reviewers: ruiu, sfertile, espindola

Reviewed By: ruiu

Subscribers: emaste, nemanjai, arichardson, kbarton, jsji, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D63182

llvm-svn: 363126
2019-06-12 07:35:42 +00:00
Fangrui Song 8a529f3cea Revert "Revert r362867: [ELF][PPC] Simplify {read,write}FromHalf16"
This reverts commit r363060 and restores r362867.

r362867 is innocent. The ppc64le-lld-multistage-test bot failure was due to a clang/gcc .toc bug:

    ld.lld: error: relocation refers to a discarded section: .rodata._ZNK4llvm3MVT13getSizeInBitsEv
    >>> defined in utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenRegisters.cpp.o
    >>> referenced by CodeGenRegisters.cpp
    >>>               utils/TableGen/CMakeFiles/llvm-tblgen.dir/CodeGenRegisters.cpp.o:(.toc+0x0)

It will be worked around by D63182.

llvm-svn: 363124
2019-06-12 06:00:39 +00:00
Amy Huang 9970817c57 Deduplicate S_CONSTANTs in LLD.
Summary: Deduplicate S_CONSTANTS when linking, if they have the same value.

Reviewers: rnk

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D63151

llvm-svn: 363089
2019-06-11 18:02:39 +00:00
Nico Weber af6bc65ddf lld-link: Reject more than one resource .obj file
Users are exepcted to pass all .res files to the linker, which then
merges all the resource in all .res files into a tree structure and then
converts the final tree structure to a .obj file with .rsrc$01 and
.rsrc$02 sections and then links that.

If the user instead passes several .obj files containing such resources,
the correct thing to do would be to have custom code to merge the trees
in the resource sections instead of doing normal section merging -- but
link.exe rejects if multiple resource obj files are passed in with
LNK4078, so let lld-link do that too instead of silently writing broken
.rsrc sections in that case.

The only real way to run into this is if users manually convert .res
files to .obj files by running cvtres and then handing the resulting
.obj files to lld-link instead, which in practice likely never happens.

(lld-link is slightly stricter than link.exe now: If link.exe is passed
one .obj file created by cvtres, and a .res file, for some reason it
just emits a warning instead of an error and outputs strange looking
data. lld-link now errors out on mixed input like this.)

One way users could accidentally run into this is the following
scenario: If a .res file is passed to lib.exe, then lib.exe calls
cvtres.exe on the .res file before putting it in the output .lib.
(llvm-lib currently doesn't do this.)
link.exe's /wholearchive seems to only add obj files referenced from the
static library index, but lld-link current really adds all files in the
archive. So if lld-link /wholearchive is used with .lib files produced
by lib.exe and .res files were among the files handed to lib.exe, we
previously silently produced invalid output, but now we error out.

link.exe's /wholearchive semantics on the other hand mean that it
wouldn't load the resource object files from the .lib file at all.
Since this scenario is probably still an unlikely corner case,
the difference in behavior here seems fine -- and lld-link might have to
change to use link.exe's /wholearchive semantics in the future anyways.

Vaguely related to PR42180.

Differential Revision: https://reviews.llvm.org/D63109

llvm-svn: 363078
2019-06-11 15:22:28 +00:00
Fangrui Song 47d77365aa [ELF][RISCV] Add R_RISCV_PC_INDIRECT to isRelExpr()
So that R_RISCV_PCREL_LO12_[IS] are considered as link-time constants in
-pie mode, otherwise there are bogus errors:

    ld.lld: error: can't create dynamic relocation R_RISCV_PCREL_LO12_I against symbol: .L0  in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output

Reviewed By: ruiu

Differential Revision: https://reviews.llvm.org/D63123

llvm-svn: 363064
2019-06-11 13:39:08 +00:00
Rui Ueyama 963d73ff44 Revert r362867: [ELF][PPC] Simplify {read,write}FromHalf16
This reverts commit r362867 since it seems to have broken
ppc64le-lld-multistage-test bot.

llvm-svn: 363060
2019-06-11 13:00:52 +00:00
Fangrui Song 025a815d75 [ELF] Make the rule to create relative relocations in a writable section stricter
The current rule is loose: `!Sym.IsPreemptible || Expr == R_GOT`.

When the symbol is non-preemptable, this allows absolute relocation
types with smaller numbers of bits, e.g. R_X86_64_{8,16,32}. They are
disallowed by ld.bfd and gold, e.g.

    ld.bfd: a.o: relocation R_X86_64_8 against `.text' can not be used when making a shared object; recompile with -fPIC

This patch:

a) Add TargetInfo::SymbolicRel to represent relocation types that resolve to a
symbol value (e.g. R_AARCH_ABS64, R_386_32, R_X86_64_64).

  As a side benefit, we currently (ab)use GotRel (R_*_GLOB_DAT) to resolve
  GOT slots that are link-time constants. Since we now use Target->SymbolRel
  to do the job, we can remove R_*_GLOB_DAT from relocateOne() for all targets.
  R_*_GLOB_DAT cannot be used as static relocation types.
b) Change the condition to `!Sym.IsPreemptible && Type != Target->SymbolicRel || Expr == R_GOT`.

Some tests are caught by the improved error checking (ld.bfd/gold also
issue errors on them). Many misuse .long where .quad should be used
instead.

Reviewed By: ruiu

Differential Revision: https://reviews.llvm.org/D63121

llvm-svn: 363059
2019-06-11 12:59:30 +00:00
Nico Weber dd6019526d Let writeWindowsResourceCOFF() take a TimeStamp parameter
For lld, pass in Config->Timestamp (which is set based on lld's
/timestamp: and /Brepro flags). Since the writeWindowsResourceCOFF()
data is only used in-memory by LLD and the obj's timestamp isn't used
for anything in the output, this doesn't change behavior.

For llvm-cvtres, add an optional /timestamp: parameter, and use the
current behavior of calling time() if the parameter is not passed in.

This doesn't really change observable behavior (unless someone passes
/timestamp: to llvm-cvtres, which wasn't possible before), but it
removes the last unqualified call to time() from llvm/lib, which seems
like a good thing.

Differential Revision: https://reviews.llvm.org/D63116

llvm-svn: 363050
2019-06-11 11:26:50 +00:00
Peter Collingbourne eaf3f56924 ELF: Don't process the partition end marker during combineEhSections().
Otherwise the getPartition() accessor may return an OOB pointer. Found
using _GLIBCXX_DEBUG.

The error is benign (we never dereference the pointer for the end marker)
so this wasn't caught by e.g. the sanitizer bots.

llvm-svn: 363026
2019-06-11 02:54:30 +00:00
Fangrui Song fc2b5c40ae Fix -DBUILD_SHARED_LIBS=on build after r362977
The executable has an undefined reference to lld::Saver, the library
should be explicitly linked.

llvm-svn: 363023
2019-06-11 01:50:58 +00:00
Nico Weber 80571d8ed2 Wrap comment to 80 columns
llvm-svn: 363017
2019-06-11 01:14:23 +00:00
Nico Weber b941fa8821 llvm-lib: Implement /machine: argument
And share some code with lld-link.

While here, also add a FIXME about PR42180 and merge r360150 to llvm-lib.

Differential Revision: https://reviews.llvm.org/D63021

llvm-svn: 363016
2019-06-11 01:13:41 +00:00
Tim Shen 23ee97be05 [LLD] Change FileCheck output file pattern to a temporary file
The previous name "%lib" doesn't trigger any actual replacement. It
creates the file "./tools/lld/test/ELF/%lib.o" in the test directory.

llvm-svn: 362988
2019-06-10 21:39:11 +00:00
Martin Storsjo bb12396f91 [Driver] Look for -m in response files as well
Also expand response files in the MinGW driver.

This should fix PR42135.

Differential Revision: https://reviews.llvm.org/D63024

llvm-svn: 362977
2019-06-10 20:10:10 +00:00
Rui Ueyama 1f73bbbd3a [LLD][COFF] Fix missing MergeChunk::Instances cleanup in COFF::link()
Patch by Erik McClure with a modification to rebase to HEAD.

When calling `COFF::link()` with `CanExitEarly` set to `false`, the
function needs to clean up several global variable caches to ensure that
the next invocation of the function starts from a clean slate. The
`MergeChunk::Instances` cache is missing from this cleanup code, and as
a result will create nondeterministic memory access errors and sometimes
infinite loops due to invalid memory being referenced on the next call
to `COFF::link()`.

This fix simply clears `MergeChunk::Instances` before exiting the function.

An additional review of the COFF library was made to try and find any
other missing global caches, but I was unable to find any other than
`MergeChunk`. Someone more familiar with the global variables might want
to do their own check.

This fix was made to support inNative
<https://github.com/innative-sdk/innative>'s `.wast` script compiler,
which must build multiple incremental builds. It relies on statically
linking LLD because the entire compiler must be a single statically
embeddable library, thus preventing it from being able to call LLD as a
new process.

Differential Revision: https://reviews.llvm.org/D63042

llvm-svn: 362930
2019-06-10 12:16:41 +00:00
Peter Smith 386f3a27db [COFF][X86] Add REQUIRES: x86 to a couple of tests
Fix buildbot failure on native AArch64 buildbot that does not have X86
backend compiled in.

Differential Revision: https://reviews.llvm.org/D63071

llvm-svn: 362926
2019-06-10 10:09:36 +00:00
Fangrui Song 44d908d743 [ELF][RISCV] Parse BFD names elf{32,64}-littleriscv
e.g. glibc libc.so on riscv64 uses `OUTPUT_FORMAT(elf64-littleriscv)`.

Reviewed By: ruiu

Differential Revision: https://reviews.llvm.org/D63070

llvm-svn: 362922
2019-06-10 08:09:55 +00:00
Martin Storsjo 6ddd7aa4c3 [ELF] [PPC] Fix a typo from SVN r362721
Apparently no test covers this exact codepath, but GCC produced a
warning about it.

llvm-svn: 362883
2019-06-08 18:26:27 +00:00
Martin Storsjo 4962f9464d [MinGW] Support the -u/--undefined option.
This is implemented by the lld-link option -include:, just like
--require-defined. Contrary to --require-defined, the -u/--undefined
option allows the symbol to remain undefined in the end.

This should fix PR42121.

Differential Revision: https://reviews.llvm.org/D62876

llvm-svn: 362882
2019-06-08 18:26:24 +00:00
Martin Storsjo c02f6bf07f [COFF] Add an lld specific option /includeoptional
This works like /include, but is not fatal if the requested symbol
wasn't found. This allows implementing the GNU ld option -u.

Differential Revision: https://reviews.llvm.org/D62976

llvm-svn: 362881
2019-06-08 18:26:18 +00:00
Fangrui Song 27de3d3950 [ELF][PPC] Simplify {read,write}FromHalf16
I've change the variable names used in PPC64.cpp from "Instr" to "Insn"
because "Insn" is a more common abbreviation for "instruction".

While changing PPC64.cpp relocateOne(), make R_PPC64_ADDR16_LO{_DS}
slightly more efficient by saving a read and a write for the TocOptimize
case.

Reviewed By: ruiu

Differential Revision: https://reviews.llvm.org/D63043

llvm-svn: 362867
2019-06-08 05:19:05 +00:00
Reid Kleckner 53cd7406bb [COFF] Fix /export:foo=bar when bar is a weak alias
Summary:
When handling exports from the command line or from .def files, the
linker does a "fuzzy" string lookup to allow finding mangled symbols.
However, when the symbol is re-exported under a new name, the linker has
to transfer the decorations from the exported symbol over to the new
name. This is implemented by taking the mangled symbol that was found in
the object and replacing the original symbol name with the export name.

Before this patch, LLD implemented the fuzzy search by adding an
undefined symbol with the unmangled name, and then during symbol
resolution, checking if similar mangled symbols had been added after the
last round of symbol resolution. If so, LLD makes the original symbol a
weak alias of the mangled symbol. Later, to get the original symbol
name, LLD would look through the weak alias and forward it on to the
import library writer, which copies the symbol decorations. This
approach doesn't work when bar is itself a weak alias, as is the case in
asan. It's especially bad when the aliasee of bar contains the string
"bar", consider "bar_default". In this case, we would end up exporting
the symbol "foo_default" when we should've exported just "foo".

To fix this, don't look through weak aliases to find the mangled name.
Save the mangled name earlier during fuzzy symbol lookup.

Fixes PR42074

Reviewers: mstorsjo, ruiu

Subscribers: thakis, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D62984

llvm-svn: 362849
2019-06-07 22:05:12 +00:00
Peter Collingbourne 8cfb14fad6 docs: Update partitioning docs now that the feature is fully landed.
llvm-svn: 362831
2019-06-07 19:23:19 +00:00
Peter Collingbourne 0282898586 ELF: Create synthetic sections for loadable partitions.
We create several types of synthetic sections for loadable partitions, including:
- The dynamic symbol table. This allows code outside of the loadable partitions
  to find entry points with dlsym.
- Creating a dynamic symbol table also requires the creation of several other
  synthetic sections for the partition, such as the dynamic table and hash table
  sections.
- The partition's ELF header is represented as a synthetic section in the
  combined output file, and will be used by llvm-objcopy to extract partitions.

Differential Revision: https://reviews.llvm.org/D62350

llvm-svn: 362819
2019-06-07 17:57:58 +00:00
Peter Smith e208208a31 [ELF][AArch64] Support for BTI and PAC
Branch Target Identification (BTI) and Pointer Authentication (PAC) are
architecture features introduced in v8.5a and 8.3a respectively. The new
instructions have been added in the hint space so that binaries take
advantage of support where it exists yet still run on older hardware. The
impact of each feature is:

BTI: For executable pages that have been guarded, all indirect branches
must have a destination that is a BTI instruction of the appropriate type.
For the static linker, this means that PLT entries must have a "BTI c" as
the first instruction in the sequence. BTI is an all or nothing
property for a link unit, any indirect branch not landing on a valid
destination will cause a Branch Target Exception.

PAC: The dynamic loader encodes with PACIA the address of the destination
that the PLT entry will load from the .plt.got, placing the result in a
subset of the top-bits that are not valid virtual addresses. The PLT entry
may authenticate these top-bits using the AUTIA instruction before
branching to the destination. Use of PAC in PLT sequences is a contract
between the dynamic loader and the static linker, it is independent of
whether the relocatable objects use PAC.

BTI and PAC are independent features that can be combined. So we can have
several combinations of PLT:
- Standard with no BTI or PAC
- BTI PLT with "BTI c" as first instruction.
- PAC PLT with "AUTIA1716" before the indirect branch to X17.
- BTIPAC PLT with "BTI c" as first instruction and "AUTIA1716" before the
  first indirect branch to X17.
    
The use of BTI and PAC in relocatable object files are encoded by feature
bits in the .note.gnu.property section in a similar way to Intel CET. There
is one AArch64 specific program property GNU_PROPERTY_AARCH64_FEATURE_1_AND
and two target feature bits defined:
- GNU_PROPERTY_AARCH64_FEATURE_1_BTI
-- All executable sections are compatible with BTI.
- GNU_PROPERTY_AARCH64_FEATURE_1_PAC
-- All executable sections have return address signing enabled.

Due to the properties of FEATURE_1_AND the static linker can tell when all
input relocatable objects have the BTI and PAC feature bits set. The static
linker uses this to enable the appropriate PLT sequence.
Neither -> standard PLT
GNU_PROPERTY_AARCH64_FEATURE_1_BTI -> BTI PLT
GNU_PROPERTY_AARCH64_FEATURE_1_PAC -> PAC PLT
Both properties -> BTIPAC PLT

In addition to the .note.gnu.properties there are two new command line
options:
--force-bti : Act as if all relocatable inputs had
GNU_PROPERTY_AARCH64_FEATURE_1_BTI and warn for every relocatable object
that does not.
--pac-plt : Act as if all relocatable inputs had
GNU_PROPERTY_AARCH64_FEATURE_1_PAC. As PAC is a contract between the loader
and static linker no warning is given if it is not present in an input.

Two processor specific dynamic tags are used to communicate that a non
standard PLT sequence is being used.
DTI_AARCH64_BTI_PLT and DTI_AARCH64_BTI_PAC.

Differential Revision: https://reviews.llvm.org/D62609

llvm-svn: 362793
2019-06-07 13:00:17 +00:00