Commit Graph

3740 Commits

Author SHA1 Message Date
Rui Ueyama 8d817f27e6 Make it explicit that -export-dynamic overrides -dynamic-list and -export-dynamic-symbol.
No functionality change.

llvm-svn: 301336
2017-04-25 17:40:12 +00:00
Rui Ueyama 577168ecde [ELF] Improve error message for incompatible section flags
Previously we were not printing out the flags 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: incompatible section flags for .bar
  >>> /foo/bar/incompatible-section-flags.s.tmp.o:(.bar): 0x403
  >>> output section .bar: 0x3

Patch by Alexander Richardson.

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

llvm-svn: 301319
2017-04-25 16:00:44 +00:00
Rui Ueyama a2a46a9532 Define __tls_get_addr as a hidden symbol even for ARM or MIPS.
addIgnored defines a given symbol even if there is no existing
symbol with the same name. So, even if libc provides __tls_get_addr,
we should still be able to call addIgnored.

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

llvm-svn: 301290
2017-04-25 04:44:54 +00:00
Rui Ueyama 321b9cd072 Export __progname even if a -dynamic-list is given.
BSD's __progname symbol is defined in crt1.o and linked against main
executables. The libc expects that main executables export __progname
symbol via .dynsym sections. In order to handle this case, we scan
undefined symbols in DSOs and exported them by setting Sym->ExportDynamic
to true.

But it turned out that setting that variable is not enough to make sure
that symbols are exported in all use cases. If a -dynamic-list option is
given, all symbols not explicitly mentioned in a version script are
hidden by default. That hides __progname symbol. This patch fixes the issue.

Fixes https://bugs.llvm.org/show_bug.cgi?id=32703

llvm-svn: 301282
2017-04-25 00:15:48 +00:00
Rui Ueyama 273bbbc3a7 Remove a useless temporary variable.
llvm-svn: 301278
2017-04-24 23:50:58 +00:00
Rafael Espindola 3460cdd440 Remove DefaultSoName.
We can just use the existing SoName member variable. It now initially
contains what was in DefaultSoName and is modified if the .so has an
actual soname.

llvm-svn: 301259
2017-04-24 21:44:20 +00:00
Shoaib Meenai b573b4b04d [ELF] Account for R_386_TLS_LDO_32 addend
This relocation type has an implicit addend. Account for it when
processing the relocation. Add an offset to an existing test to ensure
it gets processed correctly.

Fixes PR32634.

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

llvm-svn: 301207
2017-04-24 18:02:11 +00:00
Peter Smith cbfe9e946f [ELF] Always use Script::assignAddresses()
This change fabricates linker script commands for the case where there is
no linker script SECTIONS to control address assignment. This permits us
to have a single Script->assignAddresses() function.
    
There is a small change in user-visible-behavior with respect to the
handling of .tbss SHT_NOBITS, SHF_TLS as the Script->assignAddresses()
requires setDot() to be called with monotically increasing addresses.
The tls-offset.s test has been updated so that the script and non-script
results match.

This change should make the non-script behavior of lld closer to an
equivalent linker script.

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

llvm-svn: 300687
2017-04-19 12:46:32 +00:00
Rui Ueyama 196adecc3a Fix buildbot failure.
llvm-svn: 300681
2017-04-19 11:58:59 +00:00
Rui Ueyama 29181007df Update comment.
llvm-svn: 300676
2017-04-19 11:32:27 +00:00
Rui Ueyama 07c62c1174 Rename CompressedHeader ZDebugHeader.
`CompressedHeader` is a header for compressed data, and the header
itself is not compressed. So the previous name was confusing.

llvm-svn: 300675
2017-04-19 11:32:13 +00:00
Rui Ueyama 066c4ab9fe Simplify createHeader and inline it.
createHeader didn't use data members of Elf_Chdr type and write
directly to a given buffer. That is not a good practice because
the function had a knowledge of the struct layout.

llvm-svn: 300674
2017-04-19 11:31:58 +00:00
Rui Ueyama 4627873807 Fallthrough to reduce code a bit. NFC.
llvm-svn: 300673
2017-04-19 11:31:45 +00:00
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
Rui Ueyama 4eb2eccb24 Rename ScriptConfig::UndefinedSymbols ReferencedSymbols.
Symbols referenced by linker scripts are not necessarily be undefined,
so the previous name didn't convey the meaining of the variable.

llvm-svn: 299573
2017-04-05 18:02:30 +00:00
Rui Ueyama 42e0bb5e4f Do not use relocateOne() to just write 32-bit words.
llvm-svn: 299559
2017-04-05 16:33:44 +00:00
Rui Ueyama 69bfab0b38 Rename GotEntryAddr -> GotPltEntryAddr.
Because they are addresses in .got.plt and not in .got.

llvm-svn: 299556
2017-04-05 16:15:59 +00:00
Rui Ueyama 92a5ba6da5 Remove unnecessary local variable.
This patch does what r299506 was trying to do in a different way.

llvm-svn: 299554
2017-04-05 16:07:44 +00:00
Rui Ueyama 9c766d7a39 Fix PLT and GOTPLT entries for 32-bit x86 PIC.
Previously, the code we set to our .plt entries expected that .got
and .got.plt are consecutive in the virtual address space.
Since %ebx points to the last entry of .got for position-independent
code, it assumed that .got is accessible with small negative
displacements and .got.plt are accessible with small positive
displacements.

That assumption was simply wrong. We don't impose any restrictions on
relative layout of .got and .got.plt. As a result, the control is
transferred to a bogus address from .plt at runtime, which resulted in
segfaults.

This patch removes that wrong assumption. We still assume that .got.plt
has a fixed relative address to .got, but we no longer assume that they
are consecutive in memory.

With this change, a "hello world" program compiled with -fPIC works.

Fixes https://bugs.llvm.org/show_bug.cgi?id=31332.

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

llvm-svn: 299553
2017-04-05 16:01:33 +00:00
Peter Smith 56abf209c2 [ELF] Make createThunks a class [NFC]
For range extension thunks we will need to repeatedly call createThunks()
until no more thunks are created. We will need to retain the state of
Thunks that we have created so far to avoid recreating them on later
passes. This change does not change the functionality of createThunks().

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

llvm-svn: 299530
2017-04-05 10:30:09 +00:00
George Rimar e6c5d3862d [ELF] - Define __bss_start symbol.
GNU linkers define __bss_start symbol.
Patch teaches LLD to do that. This is PR32051.

Below is part of standart ld.bfd script:

.data1          : { *(.data1) }
  _edata = .; PROVIDE (edata = .);
  . = .;
  __bss_start = .;
  .bss            :
  {
Currently LLD can emit up to 3 .bss* sections as one of testcase shows.
Implementation inserts this symbol before first .bss* output section.

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

llvm-svn: 299528
2017-04-05 10:03:25 +00:00
George Rimar 07d7c42c5d Revert r299506 "Simplify. NFC."
It was not NFC unfortunaly,
one of changes decrements begin() iterator and
that is not allowed by MSVS.

llvm-svn: 299525
2017-04-05 09:19:29 +00:00
Rui Ueyama 23af89cc9a Make readAssert() to return an AssertCommand object.
llvm-svn: 299521
2017-04-05 05:50:28 +00:00
Rui Ueyama 05f6b8527a Add a file comment.
llvm-svn: 299520
2017-04-05 05:50:08 +00:00
Rui Ueyama b579c439c1 Simplify. NFC.
Looks like we can use consume() in many more places.

llvm-svn: 299519
2017-04-05 05:40:21 +00:00
Rui Ueyama 7e9155115e Inline leftShift and rightShift. NFC.
llvm-svn: 299518
2017-04-05 05:40:01 +00:00
Rui Ueyama 96b3fe025a Do not make ScriptParser class public.
This class is used only within this file, so it can be file-local.

llvm-svn: 299516
2017-04-05 05:08:01 +00:00
Rui Ueyama 2ec34544aa Move the parser for the linker script to a separate file.
LinkerScript.cpp contains both the linker script processor and the
linker script parser. I put both into a single file, but the file grown
too large, so it's time to put them into two different files.

llvm-svn: 299515
2017-04-05 05:07:39 +00:00
Rui Ueyama fd9dafdc65 Remove unused typedef.
llvm-svn: 299514
2017-04-05 05:07:18 +00:00
Rui Ueyama 583264e477 Do not use public inheritance where it is not needed.
ScriptParser is not a ScriptLexer, so this should be a private inheritance.

llvm-svn: 299513
2017-04-05 05:06:58 +00:00
Rui Ueyama f62d260744 Simplify. NFC.
llvm-svn: 299512
2017-04-05 05:06:37 +00:00
Rui Ueyama e31d98869d Simplify. NFC.
A for-loop is more boring than a find_if, but I think this is easier to read.

llvm-svn: 299511
2017-04-05 05:06:17 +00:00
Rui Ueyama 01aacc94b9 Fix memory leak found by asan.
llvm-svn: 299509
2017-04-05 03:52:47 +00:00
Rui Ueyama 4e1e88e300 Simplify and update comment.
llvm-svn: 299508
2017-04-05 03:52:28 +00:00
Rui Ueyama c8124ee9a3 Simplify. NFC.
llvm-svn: 299506
2017-04-05 03:21:01 +00:00
Rui Ueyama 8f99f73c8f Use make to create linker script command objects.
It simplifies variable types.

llvm-svn: 299505
2017-04-05 03:20:42 +00:00
Rui Ueyama d379f7357d Remove default arguments because they don't improve readability.
llvm-svn: 299504
2017-04-05 03:20:22 +00:00
Rui Ueyama cba41013ef Add parentheses around `&`.
llvm-svn: 299503
2017-04-05 03:20:03 +00:00
Rui Ueyama d7c5400f9e Update comment.
llvm-svn: 299502
2017-04-05 03:19:43 +00:00
Rui Ueyama cc400cc8ac Use empty() instead of size().
`!V.size()` where V is a vector is equivalent to `V.empty()`.

llvm-svn: 299501
2017-04-05 03:19:24 +00:00
Rui Ueyama 0b2381e71f Simplify. NFC.
llvm-svn: 299500
2017-04-05 03:19:06 +00:00
Rui Ueyama 2e081a4ff0 Make variable names consistent. NFC.
llvm-svn: 299499
2017-04-05 03:18:46 +00:00
Rui Ueyama 72e107f302 Return a result from computeInputSections instead of mutating its argument.
This should improve readability.

llvm-svn: 299498
2017-04-05 02:05:48 +00:00
Rui Ueyama 2c7171bf3c Remove `=` from a lambda that doesn't capture any variable.
llvm-svn: 299495
2017-04-05 00:43:45 +00:00
Rui Ueyama ea93fe00b9 Inline small functions that are used only once as lambdas.
llvm-svn: 299494
2017-04-05 00:43:25 +00:00
Rui Ueyama 5f20b6304b Add newlines.
llvm-svn: 299493
2017-04-05 00:43:05 +00:00
Rui Ueyama a08fa2eca3 Make dummy variable's scope smaller.
llvm-svn: 299492
2017-04-05 00:42:45 +00:00
Rafael Espindola 8465d08392 Don't resolve hidden undef to a DSO.
The ELF spec says:

all of the non-default visibility attributes, when applied to a symbol
reference, imply that a definition to satisfy that reference must be
provided within the current executable or shared object.

But we were trying to resolve those undef references to shared
symbols. That causes odd results like creating a got entry with
a relocation pointing to 0.

llvm-svn: 299464
2017-04-04 20:03:34 +00:00
James Henderson b7a90ef48e [ELF] Fail the link early if the map file path is invalid
As with the changes made in r297645, we do not want a potentially long link to
be run, if it will ultimately fail because the map file is not writable. This
change reuses the same functionality as the output file path check. See
https://reviews.llvm.org/D30449 for further justification and explanations.

Reviewers: ruiu

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

llvm-svn: 299420
2017-04-04 09:42:24 +00:00
Peter Smith 6308ac2254 [ELF] Rename ARM Thunks in anticipation of Range Thunks
The existing names for the ARM and Thumb Thunks highlight their current
use as interworking Thunks. These Thunks can also be used for range
extension Thunks where there is no state change. This change makes the name
more generic so it is suitable for range extension.

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

llvm-svn: 299418
2017-04-04 09:29:36 +00:00
Rui Ueyama 6ea72527e0 Change the error message format for an incompatible relocation.
Previous error message style:

  error: /home/alice/src/bar.c:12: relocation R_X86_64_PLT32 cannot refer to absolute symbol 'answer' defined in /home/alice/src/foo.o

New error message style:

  error: relocation R_X86_64_PLT32 cannot refer to absolute symbol: foo
  >>> defined in /home/alice/src/foo.o
  >>> referenced by bar.c:12 (/home/alice/src/bar.c:12)
  >>>               /home/alice/src/bar.o:(.text+0x1)

llvm-svn: 299390
2017-04-03 21:36:31 +00:00
Rui Ueyama c49bb0f418 Make a helper function file-local.
llvm-svn: 299377
2017-04-03 19:14:35 +00:00
Rui Ueyama 4e4e8662bc Remove InputFiles::LogName.
LogName member was added to construct input file names for logging
only once. This patch does this in a different way. Now toString
caches its results.

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

llvm-svn: 299375
2017-04-03 19:11:23 +00:00
Rui Ueyama 3a965f7e68 Change the error format to report corrupted .eh_frame.
llvm-svn: 299289
2017-04-01 01:42:20 +00:00
Rui Ueyama 810ce10b8c Change the error message format for duplicate symbols.
This patch is intended to improve readability of "duplicate symbol"
error messages.

Without this patch:

  /ssd/clang/bin/ld.lld: error: /ssd/llvm-project/lld/ELF/Relocations.cpp:1054: duplicate symbol 'lld:🧝:demangle(llvm::StringRef)'
  /ssd/clang/bin/ld.lld: error: /ssd/llvm-project/lld/ELF/Strings.cpp:93: previous definition was here

With this patch:

  /ssd/clang/bin/ld.lld: error: duplicate symbol: lld:🧝:demangle(llvm::StringRef)
  >>> defined at Strings.cpp:93 (/ssd/llvm-project/lld/ELF/Strings.cpp:93)
  >>>            Strings.cpp.o:(lld:🧝:demangle(llvm::StringRef)) in archive lib/liblldELF.a
  >>> defined at Relocations.cpp:1054 (/ssd/llvm-project/lld/ELF/Relocations.cpp:1054)
  >>>            Relocations.cpp.o:(.text+0x4C30) in archive lib/liblldELF.a

Discussion thread:
http://lists.llvm.org/pipermail/llvm-dev/2017-March/111459.html

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

llvm-svn: 299280
2017-03-31 23:40:21 +00:00
James Henderson 50c374f37a Remove unnecessary cast and branch. NFC.
llvm-svn: 299208
2017-03-31 12:31:23 +00:00
Peter Collingbourne 7b30f16c9f Re-apply r299168 and r299169 now that the libdeps are fixed.
llvm-svn: 299184
2017-03-31 04:47:07 +00:00
Peter Collingbourne f10698b940 Revert r299168 and r299169 due to library dependency issues.
http://bb.pgr.jp/builders/i686-mingw32-RA-on-linux/builds/25073/steps/build_llvmclang/logs/stdio

llvm-svn: 299171
2017-03-31 02:44:50 +00:00
Peter Collingbourne d9717aa0e4 LTO: Reduce memory consumption by creating an in-memory symbol table for InputFiles. NFCI.
Introduce symbol table data structures that can be potentially written to
disk, have the LTO library build those data structures using temporarily
constructed modules and redirect the LTO library implementation to go through
those data structures. This allows us to remove the LLVMContext and Modules
owned by InputFile.

With this change I measured a peak memory consumption decrease from 5.4GB to
2.8GB in a no-op incremental ThinLTO link of Chromium on Linux. The impact on
memory consumption is larger in COFF linkers where we are currently forced
to materialize all metadata in order to read linker options. Peak memory
consumption linking a large piece of Chromium for Windows with full LTO and
debug info decreases from >64GB (OOM) to 15GB.

Part of PR27551.

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

llvm-svn: 299168
2017-03-31 02:28:30 +00:00
Rui Ueyama 6117a624db Update comments.
llvm-svn: 299128
2017-03-30 22:57:49 +00:00
Rui Ueyama 37e60a52f3 Include filenames in error messages to report broken files.
llvm-svn: 299115
2017-03-30 21:13:00 +00:00
Rui Ueyama 66611d94ad Do not enclose an entire file with namespaces.
This change is to improve consistency with other files.

llvm-svn: 299110
2017-03-30 20:31:19 +00:00
Rui Ueyama b87602032a Change the error message format for undefined symbols.
Previously, undefined symbol errors are one line like this
and wasn't easy to read.

  /ssd/clang/bin/ld.lld: error: /ssd/llvm-project/lld/ELF/Writer.cpp:207: undefined symbol 'lld:🧝:EhFrameSection<llvm::object::ELFType<(llvm::support::endianness)0, true> >::addSection(lld:🧝:InputSectionBase*)'

This patch make it more structured like this.

  bin/ld.lld: error: undefined symbol: lld:🧝:EhFrameSection<llvm::object::ELFType<(llvm::support::endianness)0, true>
  >>> Referenced by Writer.cpp:207 (/ssd/llvm-project/lld/ELF/Writer.cpp:207)
  >>>               Writer.cpp.o in archive lib/liblldELF.a

Discussion thread:
http://lists.llvm.org/pipermail/llvm-dev/2017-March/111459.html

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

llvm-svn: 299097
2017-03-30 19:13:47 +00:00
Rui Ueyama 8d753caa78 Remove parameter names from template instantiations to make them compact. NFC.
llvm-svn: 299025
2017-03-29 20:15:29 +00:00
Rui Ueyama aa693468c5 Revert r298815: Do not use assert to report broken input files.
This reverts commit because this really shouldn't happen unless
there's a bug in LLD.

llvm-svn: 299021
2017-03-29 19:35:44 +00:00
George Rimar 5f73bc9517 [ELF] - Prepare GnuHashTableSection<ELFT> for detemplation.
This patch changes GnuHashTableSection implementation
to avoid depend on uintX_t and other ELFT stuff, reducing amount of 
changes for following patch(es).

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

llvm-svn: 298998
2017-03-29 15:23:28 +00:00
Rui Ueyama fb0f093e88 Attempt to fix buildbot.
llvm-svn: 298971
2017-03-29 01:36:37 +00:00
Rui Ueyama 6022b2be55 Use uint64_t instead of uintX_t and size_t.
uint64_t is simpler and less error-prone than target or host-dependent types.

llvm-svn: 298969
2017-03-29 00:49:50 +00:00
Rui Ueyama c95671bd78 Change the order of parameters. NFC.
If a function takes a size and an alignment, we usually pass them
in that order instead of the reverse order.

llvm-svn: 298968
2017-03-29 00:49:29 +00:00
Rui Ueyama 00805d8b09 Remove a comment that is taken from gdb man page.
This is not an original comment but taken from gdb man page, so
a pointer to the original document should suffice.

llvm-svn: 298964
2017-03-29 00:09:40 +00:00
Peter Collingbourne 0d56b959ad LTO: Replace InputFile::Symbol::getFlags() with predicate accessors. NFC.
This makes the predicates independent of the flag representation
and makes the code a little easier to read.

llvm-svn: 298951
2017-03-28 22:31:35 +00:00
Rui Ueyama 486369fc1a Do not set entsize for .gnu.hash.
.gnu.hash happen to contain only 32-bit integers for 32-bit arch,
but the section contents are not uniform array members, so setting
entsize doesn't make much sense. This behavior seems to have been
blindly copied from GNU linkers.

llvm-svn: 298934
2017-03-28 18:11:52 +00:00
Rui Ueyama 70c8efd03c Sort.
llvm-svn: 298829
2017-03-27 03:42:55 +00:00
Rui Ueyama ceb5bd59cc Simplify. NFC.
This patch calls getAddend on a relocation only when the relocation is RELA.
That doesn't really improve runtime performance but should improve
readability as the code now matches the function description.

llvm-svn: 298828
2017-03-27 03:41:00 +00:00
Rui Ueyama 4c6dfbdc20 Factor out code to add a GOT entry.
llvm-svn: 298821
2017-03-26 21:00:09 +00:00
Rui Ueyama 37c3c2d0ca Factor out common code.
llvm-svn: 298818
2017-03-26 20:51:14 +00:00
Rui Ueyama a2f63f1471 Remove MIPS-specific code from computeAddend.
Previously, computeAddend had many parameters but most of them were
used only for MIPS. The MIPS ABI is too odd that I don't want to mix
it into the regular code path. Splitting the function into non-MIPS
and MIPS parts makes the regular code path easy to follow.

llvm-svn: 298817
2017-03-26 19:35:24 +00:00
Rui Ueyama 09fd21f45c Do not use assert to report broken input files.
llvm-svn: 298815
2017-03-26 18:23:22 +00:00
Rui Ueyama 8d462b2b5f Update comments.
llvm-svn: 298814
2017-03-26 18:23:00 +00:00
Rui Ueyama ff524bf739 Sort. NFC.
llvm-svn: 298797
2017-03-26 04:10:43 +00:00
Rui Ueyama f7c2b0cb49 Remove a redundant local variable.
llvm-svn: 298796
2017-03-26 03:42:00 +00:00
Rui Ueyama a588b5fcdc Add a comment.
llvm-svn: 298795
2017-03-26 03:41:41 +00:00
Rui Ueyama 2bb35f6844 Inline a function that is used only once.
llvm-svn: 298794
2017-03-26 03:21:08 +00:00
Rui Ueyama 94e36c894e De-template a few functions in which ELFT is not needed.
llvm-svn: 298793
2017-03-26 03:20:49 +00:00
Rui Ueyama 760197cef1 Add comments and return early.
llvm-svn: 298792
2017-03-26 03:20:30 +00:00
Rui Ueyama beeab45770 Remove unused parameter.
llvm-svn: 298790
2017-03-26 02:28:09 +00:00
Rui Ueyama cb815ac549 Remove redundant local variables.
llvm-svn: 298789
2017-03-26 02:27:50 +00:00
Rui Ueyama b5cb328383 Remove a parameter from adjustExpr. NFC.
llvm-svn: 298788
2017-03-26 02:27:30 +00:00
Rui Ueyama dfd204fa1d Inline a small lambda.
llvm-svn: 298787
2017-03-26 02:27:11 +00:00
Rui Ueyama 2f274230f1 Rename C -> Sec and RI -> Rel.
C is short for Chunk, but we are no longer using that term.
RI is probably short for relocation iterator, but this is not an interator.

llvm-svn: 298786
2017-03-26 02:26:52 +00:00
Rui Ueyama 08aede362b Simplify relocation offset adjustment.
Previously, relocation offsets are recalculated for .eh_frame sections
inside the main loop, and that messed up the main loop. This patch
separates that logic into a dedicated class.

llvm-svn: 298785
2017-03-26 02:26:33 +00:00
Rui Ueyama 22f0d804f5 Use raw_fd_ostream::has_colors instead of StandardErrHasColors().
I just didn't know that raw_fd_ostream has has_colors() function.

llvm-svn: 298749
2017-03-24 23:21:34 +00:00
Rui Ueyama 561d72c328 Update comment.
llvm-svn: 298748
2017-03-24 23:21:14 +00:00
Rui Ueyama c3ddb655cc Return early.
llvm-svn: 298675
2017-03-24 01:13:30 +00:00
Rui Ueyama 2c88cee15c Early continue. NFC.
The original code is a big `if` and `else` which ends with `continue`
like this:

  if (cond) {
    ...
    // fall through
  } else {
    ...
    continue;
  }

This patch rewrites it with the following.

  if (!cond) {
    ...
    continue;
  }
  ...

llvm-svn: 298672
2017-03-24 00:50:37 +00:00
Rui Ueyama 81cb710784 Update comments.
llvm-svn: 298669
2017-03-24 00:15:57 +00:00
Rui Ueyama be68fe18cc Use `using namespace lld` for consistency with other files.
llvm-svn: 298668
2017-03-24 00:15:37 +00:00
Rui Ueyama 9b55e92a7f Move a few functions to a new file Filesystem.{cpp,h}.
llvm-svn: 298667
2017-03-24 00:15:16 +00:00
Rui Ueyama 0cbf1fd2f6 Fix varaible names that correspond to command line options.
llvm-svn: 298632
2017-03-23 18:16:42 +00:00
Simon Atanasyan 6ab0d5b0d1 [ELF] Print two more MIPS targets "supported" by LLD
These targets are related to MIPS N32 ABI.

llvm-svn: 298591
2017-03-23 12:17:32 +00:00
Petr Hosek 30f16b2339 [ELF] Allow references to reserved symbols in linker scripts
This requires collectign all symbols referenced in the linker script
and adding them to symbol table as undefined symbol.

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

llvm-svn: 298577
2017-03-23 03:52:34 +00:00