Commit Graph

3627 Commits

Author SHA1 Message Date
George Rimar dbf9339715 [ELF] - Implemented --compress-debug-sections option.
Patch implements --compress-debug-sections=zlib.

In compare with D20211 (a year old patch, abandoned), it implementation
uses streaming and fully reimplemented, does not support zlib-gnu for
simplification.

This is PR32308.

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

llvm-svn: 300444
2017-04-17 08:58:12 +00:00
Rui Ueyama 3a16769e04 [ELF] Remove unused member [NFC]
Patch by Alexander Richardson.

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

llvm-svn: 300359
2017-04-14 18:38:38 +00:00
George Rimar 1022112d77 [ELF] - Linkerscript: make section with no content to be SHT_PROGBITS by default.
Imagine next script:

SECTIONS { BYTE(0x11); }

Section content written to disk will be 0x11. Previous LLD behavior was to make this
section SHT_NOBITS. What is not correct because section has content.
ld.bfd makes such sections SHT_PROGBITS, this patch do the same.

This fixes PR32537

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

llvm-svn: 300317
2017-04-14 09:37:00 +00:00
George Rimar 01aa795f82 [ELF] LinkerScript: Don't assign zero to all regular symbols
This fixes an assertion `Align != 0u && "Align can't be 0."'
in llvm::alignTo() when a linker script references a globally
defined variable in an ALIGN() context.

Patch by Alexander Richardson !

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

llvm-svn: 300315
2017-04-14 09:23:26 +00:00
Peter Collingbourne 8446f1fe6a Object, LTO: Add target triple to irsymtab and LTO API.
Start using it in LLD to avoid needing to read bitcode again just to get the
target triple, and in llvm-lto2 to avoid printing symbol table information
that is inappropriate for the target.

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

llvm-svn: 300300
2017-04-14 02:55:06 +00:00
Peter Collingbourne c0987938ea ELF: Remove some dead code.
llvm-svn: 300297
2017-04-14 02:34:32 +00:00
Rui Ueyama 0faa53aaab Remove useless local variable.
llvm-svn: 300294
2017-04-14 01:35:04 +00:00
Rui Ueyama c49bdd6d5d Replace uintX_t with uint64_t.
We generally want to use uint64_t instead of uintX_t if the 64-bit
type works for both 32-bit and 64-bit because it is simpler than
the variable-size type.

llvm-svn: 300293
2017-04-14 01:34:45 +00:00
Rui Ueyama 1c2b3c43fe Remove useless namespaces.
llvm-svn: 300284
2017-04-13 23:49:54 +00:00
Rui Ueyama 8acbf1cca9 Rename readOutputSectionFiller parseFill.
"read" is used as a prefix for functions that read tokens from input
streams. This function doesn't really read anything, but just parses
a given string as an integer, so rename.

llvm-svn: 300281
2017-04-13 23:40:19 +00:00
Rui Ueyama 15732b718b Fix FILL linker script command.
FILL command doesn't need a semicolon.
Fixes https://bugs.llvm.org/show_bug.cgi?id=32657

llvm-svn: 300280
2017-04-13 23:40:00 +00:00
Rui Ueyama 3e1fc3f6fe Add "1" suffix if there's varaible ends with "2".
If we knew that we'd add End2, Edata2 and Etext2, we'd name their
original symbols with "1". This patch does it.

llvm-svn: 300263
2017-04-13 21:37:56 +00:00
Rui Ueyama 1505ba826c Replace a clever lambda helper with a simpler one.
llvm-svn: 300259
2017-04-13 21:23:03 +00:00
Peter Smith 4dc4bc4e3c [ELF] Tidy up handleARMTlsRelocation [NFC]
Replace addModuleReloc with AddTlsReloc so that we can use it for both the
module relocation and the offset relocation.

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

llvm-svn: 300192
2017-04-13 10:56:40 +00:00
Peter Smith cec1e260c3 [ELF] Mark ARM Exceptions that refer to folded code as not live
ARM Exception Index Table sections .ARM.exidx have an implicit dependency
on code sections via SHF_LINK_ORDER. When code sections are folded by ICF
we must mark the unique .ARM.exidx table that describes it as not live
to prevent an illegal entry in the exception table.
    
Note that we do not try and follow the relocations from the .ARM.exidx
section to the .ARM.extab sections to mark these as not live. Leaving
these sections is not a correctness problem. In theory these could be
removed via an application of garbage collection.
    
Fixes https://bugs.llvm.org/show_bug.cgi?id=32614

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

llvm-svn: 300182
2017-04-13 08:52:58 +00:00
Rui Ueyama 9d773f3cb2 Add comments for the RELRO segment.
RELRO is a feature to make segments read-only after dynamic relocations
are applied. It is different from read-only segments because RELRO is
initially writable. And of course RELRO is different from writable
segments.

RELRO is not a very well known feature. We have a series of checks to
make a decision whether a section should be in a RELRO segment or not,
but we didn't describe why. This patch adds comments to explain how
that decision is made.

llvm-svn: 300176
2017-04-13 05:40:07 +00:00
Rui Ueyama 3233d3eb46 Do not initialize this->SoName with this->DefaultSoName.
This patch uses DefaultSoName in getSoName instead of in parseSoName.
I think this is more readable. This patch also add comments.

llvm-svn: 300147
2017-04-13 00:23:32 +00:00
Rui Ueyama 040af7deab Allow expressions in MEMORY command.
Previously, we allowed only integers in this context. Now you can
write expressions there. LLD is now able to handle the following
linker, for example.

  MEMORY { rom (rx) : ORIGIN = (1024 * 1024) }

llvm-svn: 300131
2017-04-12 23:16:52 +00:00
Evgeniy Stepanov a76349bffe [lld] Keep full library path in DT_NEEDED.
Fixes PR32572.

When
    (a) a library has no soname
and (b) library is given on the command line with path (and not through -L/-l flags)
DT_NEEDED entry for such library keeps the path as given.

This behavior is consistent with gold and bfd, and is used in compiler-rt test suite.

This is a second attempt after r300007 got reverted. This time relro-omagic test is
changed in a way to avoid hardcoding the path to the test directory in the objdump'd
binary.

llvm-svn: 300011
2017-04-12 00:13:48 +00:00
Evgeniy Stepanov d512afe3da Revert "[lld] Keep full library path in DT_NEEDED."
This reverts commit r300007. Reason: breaks all the bots.

llvm-svn: 300008
2017-04-12 00:01:21 +00:00
Evgeniy Stepanov 2c2dcae13c [lld] Keep full library path in DT_NEEDED.
Fixes PR32572.

When
    (a) a library has no soname
and (b) library is given on the command line with path (and not through -L/-l flags)
DT_NEEDED entry for such library keeps the path as given.

This behavior is consistent with gold and bfd, and is used in compiler-rt test suite.

llvm-svn: 300007
2017-04-11 23:46:58 +00:00
Rui Ueyama b58079d4e2 Remove big-endianness from =<fillexp> code.
llvm-svn: 300005
2017-04-11 22:45:57 +00:00
Rui Ueyama 8f8c2f9599 Call getFiller only when filler is not zero.
llvm-svn: 300004
2017-04-11 22:45:38 +00:00
Evgeniy Stepanov 6c973d647f [lld] --export-dynamic overrides --dynamic-list.
Fixes PR32573.

--export-dynamic exports everything, even in the presence of a --dynamic-list,
or --export-dynamic-symbol.

llvm-svn: 300002
2017-04-11 22:37:54 +00:00
George Rimar e7bf968803 [ELF] - Stop producing broken output for R_386_GOT32[X] relocations.
Previously we silently produced broken output for R_386_GOT32X/R_386_GOT32 
relocations if they were used to compute the address of the symbol’s global
offset table entry without base register when position-independent code is disabled.

Situation happened because of recent ABI changes. Released ABI mentions that
R_386_GOT32X can be calculated in a two different ways (so we did not follow ABI here 
before this patch), but draft ABI also mentions R_386_GOT32 relocation here. 
We should use the same calculations for both relocations.

Problem is that we always calculated them as G + A - GOT (offset from end of GOT),
but for case when PIC is disabled, according to i386 ABI calculation should be G + A,
what should produce just an address in GOT finally.

ABI: https://github.com/hjl-tools/x86-psABI/wiki/intel386-psABI-draft.pdf (p36, p60).
llvm-svn: 299812
2017-04-08 06:14:14 +00:00
Rafael Espindola e4c8b9b78c Simplify this further.
Thanks to Rui for noticing it.

llvm-svn: 299777
2017-04-07 16:10:46 +00:00
Simon Atanasyan 60d0e982f0 [ELF] Do not pass GOT section as an argument to handleARMTlsRelocation and handleMipsTlsRelocation functions. NFC
Both functions always use the same GOT sections In<ELFT>::Got and
In<ELFT>::MipsGot respectively, so we do not need to pass them as an
argument.

llvm-svn: 299773
2017-04-07 15:05:44 +00:00
James Henderson 9d9a663731 [ELF] Recommit r299635 to pad x86 executable sections with 0xcc
This follows r299748 which fixed a latent bug the original commit exposed.

llvm-svn: 299755
2017-04-07 10:36:42 +00:00
Peter Smith 99a992343c [ELF] Fix ARM TLS global dynamic TlsOffsetRel for non-preemtible symbols
When the target of the TlsOffsetRel is non-preemptible we can write the
offset directly into the GOT without needing a dynamic relocation. This
is optional for dynamically linked executables but is required for static
linking.
    
This change adds the relocation to the GOT entry and a test case for
non-0 offsets so that if we miss out the offset the test won't spuriously
pass by virtue of the default value being 0.

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

llvm-svn: 299751
2017-04-07 09:37:30 +00:00
Peter Smith a630d0f01b [ELF] Split handleNoRelaxTlsRelocation into ARM and Mips specific impls
The handleNoRelaxTlsRelocation handled both ARM and Mips as at a
high-level the actions of what to do when encountering a local dynamic or
global dynamic TLS relocation are the same. However due to Mips using a
custom GOT the differences of the implementation are enough that the
function became difficult to understand.
    
This change replaces handleNotRelaxTlsRelocation into
handleARMTlsRelocation() and handleMipsTlsRelocation() so that the ARM and
Mips specific code is isolated.

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

llvm-svn: 299750
2017-04-07 09:09:48 +00:00
Rafael Espindola dc8eb810db Move a cast out of a function. NFC.
The argument was always casted, so cast it in the caller.

llvm-svn: 299742
2017-04-07 01:40:21 +00:00
Rafael Espindola 7f91d44fba Remove unnecessary cast.
llvm-svn: 299740
2017-04-07 01:25:01 +00:00
Rui Ueyama 5eb8ea8872 Rename refersToGotEntry needsGot and add comments.
This patch addresses a post-commit review comment for r299615.

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

llvm-svn: 299722
2017-04-06 22:39:11 +00:00
Rafael Espindola d1960dc097 Call updateAlignment before assignAddresses.
The alignment expression cannot depend on '.', so we can compute it
early.

llvm-svn: 299717
2017-04-06 21:40:22 +00:00
Rafael Espindola feed750676 Move call to findMemoryRegion before assignAddresses.
This removes a bit more work from assignAddresses.

llvm-svn: 299716
2017-04-06 21:31:24 +00:00
Rafael Espindola 1902b337e9 Remove redundant argument. NFC.
llvm-svn: 299713
2017-04-06 21:26:03 +00:00
Rafael Espindola 9b9800951d Cache the result of findSection.
This avoids calling it multiple times. In particular, we don't have to
call in in assignAddresses any more.

llvm-svn: 299709
2017-04-06 21:05:39 +00:00
James Henderson d983180778 Revert r299635 because it exposed a latent bug.
llvm-svn: 299655
2017-04-06 15:22:58 +00:00
James Henderson 7ee227561e [ELF] Remove unnecessary cast and fix comments. NFC.
llvm-svn: 299636
2017-04-06 09:40:03 +00:00
James Henderson 8dd4c06a77 [ELF] Pad x86 executable sections with 0xcc int3 instructions
Executable sections should not be padded with zero by default. On some
architectures, 0x00 is the start of a valid instruction sequence, so can confuse
disassembly between InputSections (and indeed the start of the next InputSection
in some situations). Further, in the case of misjumps into padding, padding may
start to be executed silently.

On x86, the "0xcc" byte represents the int3 trap instruction. It is a single
byte long so can serve well as padding. This change switches x86 (and x86_64) to
use this value for padding in executable sections, if no linker script directive
overrides it. It also puts the behaviour into place making it easy to change the
behaviour of other targets when desired. I do not know the relevant instruction
sequences for trap instructions on other targets however, so somebody should add
this separately.

Because the old behaviour simply wrote padding in the whole section before
overwriting most of it, this change also modifies the padding algorithm to write
padding only where needed. This in turn has caused a small behaviour change with
regards to what values are written via Fill commands in linker scripts, bringing
it into line with ld.bfd. The fill value is now written starting from the end of
the previous block, which means that it always starts from the first byte of the
fill, whereas the old behaviour meant that the padding sometimes started mid-way
through the fill value. See the test changes for more details.

Reviewed by: ruiu

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

Bugzilla: http://bugs.llvm.org/show_bug.cgi?id=32227
llvm-svn: 299635
2017-04-06 09:29:08 +00:00
Rui Ueyama 5036cc6768 Create GOT and PLT entries early in scanRelocs().
scanRelocs() does a lot of things. It fills InputSection's Relocations vector,
making a decision whether a TLS relocation should be relaxed or not,
and making a decision whether a GOT/PLT slot needs to be created or not.

They don't actually have to be done in a single loop. I want to separate
them so that some of them can be run concurently. As a first step, this
patch moves PLT/GOT slot assignment to beginning of the loop, so that
they just fall through to the next statements. This should make it clear
that that code doesn't affect other parts of the loop.

llvm-svn: 299615
2017-04-06 03:30:51 +00:00
Rui Ueyama c2a49bf95c Remove Target::isTlsGlobalDynamicRel()
Relocations are abstracted as platform-independent R_TLS_* relocations,
so we don't need to check platform-specific ones to see if a relocation
is TLS GD.

llvm-svn: 299614
2017-04-06 03:30:32 +00:00
Rui Ueyama 5c65088fd4 Return Optional<uint64_t> from readInteger instead of returning just success/failure.
llvm-svn: 299600
2017-04-05 23:22:11 +00:00
Rui Ueyama 0ce388bebb Remove unused typedefs.
llvm-svn: 299594
2017-04-05 21:46:06 +00:00
Rui Ueyama 9f125857ae Inline a small function. NFC.
llvm-svn: 299593
2017-04-05 21:45:47 +00:00
Rui Ueyama 6bd3822007 Use uint64_t to keep file size even on 32-bit machines.
If an output file is too large for 32-bit, we should report an error.

llvm-svn: 299592
2017-04-05 21:37:09 +00:00
Rui Ueyama f2dc4362c0 Inline a small function. NFC.
llvm-svn: 299590
2017-04-05 21:08:47 +00:00
Rui Ueyama 63fda39e2f Remove unnecessary virtual dtor.
This class doesn't have virtual member functions, and no instances
of this class is deleted through base pointers.

llvm-svn: 299581
2017-04-05 19:21:35 +00:00
Rui Ueyama b2fb84a1fa Inline small functions that are used only once.
llvm-svn: 299580
2017-04-05 19:21:15 +00:00
Rui Ueyama 03fc8d1e0d Fix comments.
llvm-svn: 299579
2017-04-05 19:20:54 +00:00