Commit Graph

3740 Commits

Author SHA1 Message Date
Rafael Espindola 246c1c47ea Fix flag to start with 1 << 0. NFC.
Thanks to Andrew Ng for noticing it.

llvm-svn: 303354
2017-05-18 16:20:12 +00:00
Peter Smith d54f368e6a [ELF] Support R_ARM_SBREL32 Relocation
This change adds support for the R_ARM_SBREL32 relocation. The relocation
is a base relative relocation that is produced by clang/llvm when -frwpi
is used. The use case for the -frwpi option is position independent data
for embedded systems that do not have a GOT. With -frwpi all data is
accessed via an offset from a base register (usually r9), where r9 is set
at run time to where the data has been loaded. The base of the data is
known as the static base.

The ARM ABI defines the static base as:
B(S) is the addressing origin of the output segment defining the symbol S.
The origin is not required to be the base address of the segment. For
simplicity we choose to use the base address of the segment.

The ARM procedure call standard only defines a read write variant using
R_ARM_SBREL32 relocations. The read-only data is accessed via pc-relative
offsets from the code, this is implemented in clang as -fropi.

Fixes PR32924

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

llvm-svn: 303337
2017-05-18 09:12:21 +00:00
George Rimar ec84ffc529 [ELF] - Detemplate Thunk creation.
Nothing special here, just detemplates code that became possible 
to detemplate after recent commits in a straghtforward way.

Differential revision: https://reviews.llvm.org/D33234

llvm-svn: 303237
2017-05-17 07:10:59 +00:00
George Rimar d8daafd0fb [ELF] - Update for LLVM's r303163 change. NFCi.
llvm-svn: 303164
2017-05-16 12:34:51 +00:00
George Rimar 390242d0e9 [ELF] - Detemplate elf::addSyntheticLocal(). NFC.
llvm-svn: 303155
2017-05-16 10:11:36 +00:00
George Rimar 69b17c35d9 [ELF] - Detemplate access to SymTab, DynSymTab, GnuHashTab. NFC.
Follow up for r303150.

llvm-svn: 303153
2017-05-16 10:04:42 +00:00
George Rimar f45f681609 [ELF] - Detemplate GnuHashTableSection and SymbolTableSection sections.
SymbolTableBaseSection was introduced.

Detemplation of SymbolTableSection should allow to detemplate more things.

Differential revision: https://reviews.llvm.org/D33124

llvm-svn: 303150
2017-05-16 08:53:30 +00:00
George Rimar ab94768cc1 [ELF] - Use llvm::to_integer() instead of StringRef::getAsInteger().
Switch to llvm::to_integer() everywhere in LLD instead of 
StringRef::getAsInteger() because API of latter is confusing. 
It returns true on error and false otherwise what makes reading 
the code incomfortable.

Differential revision: https://reviews.llvm.org/D33187

llvm-svn: 303149
2017-05-16 08:19:25 +00:00
Peter Collingbourne 0a2678e9aa ELF: --gdb-index: Change findSection to return an InputSection.
We should only ever expect this function to return a regular
InputSection; I would not expect a function definition to be in a
MergeInputSection or EhInputSection. We were previously crashing
in writeTo if this function returned a section that was not an
InputSection because we do not set OutSec for such sections.

This can happen in practice if a function is defined in an empty
section which shares its offset-in-file with a MergeInputSection,
as in the provided test case.

A better fix for this bug would be to fix the
DWARFUnit::collectAddressRanges() interface to provide section
information (see D33183), but this at least fixes the crash.

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

llvm-svn: 303089
2017-05-15 17:59:21 +00:00
Peter Collingbourne c5bee3212b ELF: --gdb-index: Do not add dead sections to the address area.
Fixes PR33032.

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

llvm-svn: 303088
2017-05-15 17:53:26 +00:00
George Rimar 09328b3ef8 [ELF] - Apply clang-format. NFC.
llvm-svn: 302921
2017-05-12 17:00:07 +00:00
Rafael Espindola 5210141b07 Optimize orphan placement in a general way.
We used to place orphans by just using compareSectionsNonScript.

Then we noticed that since linker scripts can use another order, we
should first try match the section to a given PT_LOAD. But there is
nothing special about PT_LOAD. The same issue can show up for
PT_GNU_RELRO for example.

In general, we have to search for the most similar section and put the
orphan next to it. Most similar being defined as how long they follow
the same code path in compareSecitonsNonScript.

That is what this patch does. We now compute a rank for each output
section, with a bit for each branch in what was
compareSectionsNonScript.

With this findOrphanPos is now fully general and orphan placement can
be optimized by placing every section with the same rank at once.

The included testcase is a variation of many-sections.s that uses
allocatable sections to avoid the fast path in the existing
code. Without threads it goes form 46 seconds to 0.9 seconds.

llvm-svn: 302903
2017-05-12 14:52:22 +00:00
George Rimar b4081bb0ab [ELF] - Stop support of DF_STATIC_TLS flag.
This reverts changes introduced in r302414 "[ELF] - Set DF_STATIC_TLS flag for i386 target."

Because DF_STATIC_TLS does not look to be used by glibc or anything else.

llvm-svn: 302884
2017-05-12 08:04:58 +00:00
George Rimar 6f586731c5 [ELF] - Don't allow R_X86_64_TPOFF32 dynamic relocation when linking PIC
Both gold and bfd restrict that one:

ld.bfd: test.o: relocation R_X86_64_TPOFF32 against `var' can not be 
used when making a shared object; recompile with -fPIC
ld.gold: error: test.o: unsupported reloc 23 against global symbol var

What looks reasonable because it is 32 bit one. Patch do the same.

Differential revision: https://reviews.llvm.org/D33100

llvm-svn: 302881
2017-05-12 07:19:11 +00:00
Rafael Espindola 8ff5c41192 Detemplate compareSections. NFC.
llvm-svn: 302849
2017-05-11 23:37:55 +00:00
Rafael Espindola 24a5a9058e Detemplate compareSectionsNonScript. NFC.
llvm-svn: 302848
2017-05-11 23:33:19 +00:00
Rafael Espindola 9e889eb48c Detemplate isRelroSection. NFC.
llvm-svn: 302847
2017-05-11 23:31:06 +00:00
Rafael Espindola f9e3c9cc22 Detemplate SymbolBody::getGotVA. NFC.
llvm-svn: 302846
2017-05-11 23:28:49 +00:00
Rafael Espindola 88ab9fb163 Detemplate the got.
This is a bit hackish, but allows for a lot of followup cleanups.

llvm-svn: 302845
2017-05-11 23:26:03 +00:00
Rafael Espindola 5ab1989584 Reduce templating. NFC.
llvm-svn: 302843
2017-05-11 23:16:43 +00:00
Rafael Espindola 895aea6d15 Reduce template usage. NFC.
llvm-svn: 302832
2017-05-11 22:02:41 +00:00
Rafael Espindola b3aa2c9b9e Reduce template usage. NFC.
llvm-svn: 302828
2017-05-11 21:33:30 +00:00
Rafael Espindola 4b1c3696e3 Reduce template usage. NFC.
llvm-svn: 302826
2017-05-11 21:23:38 +00:00
Zachary Turner 3a57fbd6db [Support] Move Parallel algorithms from LLD to LLVM.
Differential Revision: https://reviews.llvm.org/D33024

llvm-svn: 302748
2017-05-11 00:03:52 +00:00
Rui Ueyama 42ec5b9728 Remove unused #include.
llvm-svn: 302719
2017-05-10 20:02:41 +00:00
Rui Ueyama 33d903d1b0 Rename parallelFor -> parallelForEachN.
So that it is clear that the function is a wrapper for for_each_n.

llvm-svn: 302718
2017-05-10 20:02:19 +00:00
Rafael Espindola d7dc225888 Use a DenseMap in LinkerScript::getCmd.
This improves many-sections.s with a linker script from 22s to 0.9s.

llvm-svn: 302708
2017-05-10 19:13:38 +00:00
Rafael Espindola fa948c724a Refactor OutputSection to OutputSectionCommand mapping.
We now always use getCmd. I will optimize it in a followup commit.

llvm-svn: 302706
2017-05-10 19:00:23 +00:00
Rui Ueyama 896cbc40ad [ELF] Improve error message for incompatible section types
Previously we were not printing out the type of the incompatible section
which made it difficult to determine what the problem was.

The error message format has been change to the following:

  error: section type mismatch for .shstrtab
  >>> <internal>:(.shstrtab): SHT_STRTAB
  >>> output section .shstrtab: Unknown

Patch by Alexander Richardson.

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

llvm-svn: 302694
2017-05-10 16:57:50 +00:00
Petr Hosek 6b936bf6c7 [ELF] Define __ehdr_start unconditionally even when using linker script
This behavior differs from the semantics implemented by GNU linkers
which only define this symbol iff ELF headers are in the memory
mapped segment.

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

llvm-svn: 302687
2017-05-10 16:20:33 +00:00
Rafael Espindola c2dd0bdf17 Mark LinkerScript as final.
We used to inherit from it, but don't need it anymore.

llvm-svn: 302675
2017-05-10 14:45:15 +00:00
Rafael Espindola 3f38e818ac Remove one more use of section names.
llvm-svn: 302672
2017-05-10 14:35:20 +00:00
Rafael Espindola 2c923c2c37 Remove another use of section names. NFC.
llvm-svn: 302671
2017-05-10 14:28:31 +00:00
George Rimar 608cf67084 [ELF] - Don't segfault when assigning non-calculatable absolute symbol value.
This is PR32664.

Issue was revealed by linux kernel script which was:

SECTIONS {
 . = (0xffffffff80000000 + ALIGN(0x1000000, 0x200000));
 phys_startup_64 = ABSOLUTE(startup_64 - 0xffffffff80000000);

 .text : AT(ADDR(.text) - 0xffffffff80000000) {
.....
  *(.head.text)
Where startup_64 is in .head.text.

At the place of assignment to phys_startup_64 we can not calculate absolute value for startup_64
because .text section has no VA assigned. Two patches were prepared earlier to address this: D32173 and D32174.

And in comments for D32173 was suggested not try to support this case, but error out.

Differential revision: https://reviews.llvm.org/D32793

llvm-svn: 302668
2017-05-10 14:23:33 +00:00
George Rimar 4388b071bf [ELF] - Use LLVM_FALLTHROUGH in code.
When compiling LLD using GCC 7 it reports warnings like:
"warning: this statement may fall through [-Wimplicit-fallthrough=]"

LLVM has LLVM_FALLTHROUGH macro which can be used to avoid such warnings.
Together with D33036 this patch fixes them.

Differential revision: https://reviews.llvm.org/D32907

llvm-svn: 302666
2017-05-10 14:19:59 +00:00
Rafael Espindola dc1ed12015 Remove another use of section names. NFC.
llvm-svn: 302662
2017-05-10 14:12:02 +00:00
Rafael Espindola c5b612b8b4 Don't use section names in getFiller. NFC.
This is just faster and avoids using names.

llvm-svn: 302661
2017-05-10 14:01:13 +00:00
Zachary Turner 092c767745 [Core] Make parallel algorithms match C++ Parallelism TS.
Differential Revision: https://reviews.llvm.org/D33016

llvm-svn: 302613
2017-05-10 01:16:22 +00:00
Rui Ueyama 91b95b61f8 Add memory ORIGIN and LENGTH expression support
Adds support for the ORIGIN and LENGTH linker script built in functions.

  ORIGIN(memory) Return the origin of the memory region
  LENGTH(memory) Return the length of the memory region

Redo of D29775 for refactored linker script parsing.

Patch by Robert Clarke

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

llvm-svn: 302564
2017-05-09 18:24:38 +00:00
Rafael Espindola 0ca3712796 Use a simpler heuristic for placing orphans.
This is a bit easier to read and a lot faster in some cases. A version
of many-sections.s with linker scripts goes from 0m41.232s to
0m19.575s.

llvm-svn: 302528
2017-05-09 13:58:46 +00:00
Rafael Espindola b5de5b9354 Simplify orphan section positioning.
The code following this one already considers every possible insertion
point for orphan sections, there is no point in sorting them before.

llvm-svn: 302441
2017-05-08 16:49:20 +00:00
George Rimar 1564122b05 [ELF] - Set DF_STATIC_TLS flag for i386 target.
This is PR32437.

DF_STATIC_TLS
If set in a shared object or executable, this flag instructs the 
dynamic linker to reject attempts to load this file dynamically. 
It indicates that the shared object or executable contains code 
using a static thread-local storage scheme. Implementations need 
not support any form of thread-local storage.

Patch checks if IE/LE relocations were used to check if code uses
static model. If so it sets the DF_STATIC_TLS flag.

Differential revision: https://reviews.llvm.org/D32354

llvm-svn: 302414
2017-05-08 10:24:38 +00:00
George Rimar d86a4e505b [ELF] - Linkerscript: support combination of linkerscript and --compress-debug-sections.
Previously it was impossible to use linkerscript with --compress-debug-sections 
because of assert failture:
Assertion failed: isFinalized(), file C:\llvm\lib\MC\StringTableBuilder.cpp, line 64

Patch fixes the issue

llvm-svn: 302413
2017-05-08 10:18:12 +00:00
Rafael Espindola 660c9ab929 Delete LinkerScript::getSectionIndex.
We can set SectionIndex tentatively as we process the linker script
instead of looking it repeatedly.

In general we should try to have as few name lookups as possible.

llvm-svn: 302299
2017-05-05 21:34:26 +00:00
Rafael Espindola 81273c721c Remove isTlsLocalDynamicRel and isTlsInitialExecRel.
This feels a bit hackish, but I think it is still an improvement.

The way a tls address is computed in the various architectures is not
that different. For example, for local dynamic we need the base of the
tls (R_TLSLD or R_TLSLD_PC), and the offset of that particular symbol
(R_ABS).

Given the similarity, we can just use the expressions instead of
having two additional target hooks.

llvm-svn: 302279
2017-05-05 20:25:54 +00:00
Rui Ueyama 21ebb216ea Remove redundant `explicit`.
llvm-svn: 302273
2017-05-05 19:24:58 +00:00
Rafael Espindola 0f6cc65fe9 Remember OffsetInArchive in LazyObjectFile.
LazyObjectFile might turn out to be a BitcodeFile, so we need
OffsetInArchive.

llvm-svn: 302242
2017-05-05 15:17:07 +00:00
Rafael Espindola 0b1413a881 Use the archive offset with --whole-archive.
The test ELF/lto/thin-archivecollision.ll was not testing what it
wanted to test. It needs two archive members with the same name, but
different offsets.

Without this we could remove all references of OffsetInArchive and all
tests would still pass.

Fixing the test showed that the --whole-archive case was broken, which
this patch fixes.

llvm-svn: 302241
2017-05-05 15:08:06 +00:00
Rafael Espindola 80ae8ae186 Remember archive name when creating LazyObjectFile.
It is needed for creating an unique identifier for ThinLTO.

This fixes pr32931.

llvm-svn: 302235
2017-05-05 13:55:51 +00:00
George Rimar bb451903f5 [ELF] - Accept --defsym foo=value form.
Previously we accepted --defsym=foo=value only.

Reported by Sean Silva.

llvm-svn: 302227
2017-05-05 11:59:15 +00:00