Commit Graph

3720 Commits

Author SHA1 Message Date
Rui Ueyama 789723fddf Ignore -no-keep-memory.
When the -no-keep-memory option is given, BFD linker tries to save
memory in their own way. Since our internal architecture is completely
different from that linker, that option doesn't make sense to us.

llvm-svn: 301772
2017-04-30 13:45:06 +00:00
Rui Ueyama b402a866c1 Move LTO options above "all options beyond this are ignored" comment
llvm-svn: 301771
2017-04-30 13:44:52 +00:00
Rui Ueyama bd27849e4b Rename RPath Rpath for consistency. NFC.
For an option -foo-bar-baz, we have Config->FooBarBaz. Since -rpath is
-rpath and not -r-path, it should be Config->Rpath instead Config->RPath.

llvm-svn: 301759
2017-04-29 23:06:43 +00:00
Rui Ueyama 85a5e69ced Simplify by using getString instead of getLastArg. NFC.
llvm-svn: 301758
2017-04-29 22:56:38 +00:00
Rui Ueyama 543161a10c Report an error if --compress-debug-sections is given while zlib is not availble.
llvm-svn: 301757
2017-04-29 22:56:24 +00:00
Rafael Espindola de8d9897d9 Bring back r301678.
This version uses a set to speed up the synchronize method.

Original message:

    Remove LinkerScript::flush.

    This patch replaces flush with a last ditch attempt at synchronizing
    the section list with the linker script "AST".

    The synchronization is a bit of a hack and should in time be avoided
    by creating the AST earlier so that modifications can be made directly
    to it instead of modifying the section list and synchronizing it back.

    This is the main step for fixing
    https://bugs.llvm.org/show_bug.cgi?id=32816. With this in place I
    think the only missing thing would be to have processCommands assign
    section indexes as dummy offsets so that the sort in
    OutputSection::finalize works.

    With this LinkerScript::assignAddresses becomes much simpler, which
    should help with the thunk work.

llvm-svn: 301745
2017-04-29 15:44:03 +00:00
Davide Italiano d765638ad1 [ELF] When a rel points to a SHF_MERGE section, don't merge the sec.
Fixes PR32785. Thanks to Piotr Padlewski for the report and
Rafael for the fix.

llvm-svn: 301729
2017-04-29 01:24:34 +00:00
Rui Ueyama 3151958cbd Replace PrettyPrinter class in MapFile.cpp with a few non-member functions.
Since the output format has been simplified, the class to print
out a map file doesn't seem to be needed anymore. We can replace
it with a few non-member functions.

llvm-svn: 301715
2017-04-28 23:29:15 +00:00
Rui Ueyama e2f11690fe Eliminate .debug_gnu_pub{names,types} if -gdb-index is given.
This patch is to ignore .debug_gnu_pub{names,types} sections if the
-gdb-index option was given.

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

llvm-svn: 301710
2017-04-28 22:46:55 +00:00
Rui Ueyama 216aa11cc5 Revert r301678: Remove LinkerScript::flush.
This reverts commit r301678 since that change significantly slowed
down the linker. Before this patch, LLD could link clang in 8 seconds,
but with this patch it took 40 seconds.

llvm-svn: 301709
2017-04-28 22:40:58 +00:00
Hans Wennborg ca31b9f89c Flush output in log()
This change was motivated by output from lld-link.exe and link.exe
getting intermixed. There's already a flush() call in message(), so
there's precedence.

llvm-svn: 301693
2017-04-28 21:35:02 +00:00
Rafael Espindola a7a945a13b Rename one of the variables to avoid confusion.
llvm-svn: 301691
2017-04-28 21:23:43 +00:00
Rui Ueyama 3012b371fd Change the format of the map file.
Previously, we printed out input sections and input files in
separate columns as shown below.

  Address          Size             Align Out     In      File    Symbol
  0000000000201000 0000000000000015     4 .text
  0000000000201000 000000000000000e     4         .text
  0000000000201000 000000000000000e     4                 foo.o
  0000000000201000 0000000000000000     0                         _start
  0000000000201005 0000000000000000     0                         f(int)
  000000000020100e 0000000000000000     0                         local
  0000000000201010 0000000000000002     4                 bar.o
  0000000000201010 0000000000000000     0                         foo
  0000000000201011 0000000000000000     0                         bar

This format doesn't make much sense because for each input section,
there's always exactly one input file. This patch changes the format
to this.

  Address          Size             Align Out     In      Symbol
  0000000000201000 0000000000000015     4 .text
  0000000000201000 000000000000000e     4         foo.o:(.text)
  0000000000201000 0000000000000000     0                 _start
  0000000000201005 0000000000000000     0                 f(int)
  000000000020100e 0000000000000000     0                 local
  0000000000201010 0000000000000002     4         bar.o:(.text)
  0000000000201010 0000000000000000     0                 foo
  0000000000201011 0000000000000000     0                 bar

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

llvm-svn: 301683
2017-04-28 20:38:27 +00:00
Rafael Espindola b3bc1ed0d4 Remove LinkerScript::flush.
This patch replaces flush with a last ditch attempt at synchronizing
the section list with the linker script "AST".

The synchronization is a bit of a hack and should in time be avoided
by creating the AST earlier so that modifications can be made directly
to it instead of modifying the section list and synchronizing it back.

This is the main step for fixing
https://bugs.llvm.org/show_bug.cgi?id=32816. With this in place I
think the only missing thing would be to have processCommands assign
section indexes as dummy offsets so that the sort in
OutputSection::finalize works.

With this LinkerScript::assignAddresses becomes much simpler, which
should help with the thunk work.

llvm-svn: 301678
2017-04-28 20:22:47 +00:00
Rui Ueyama 8a3ef95fc9 Use toString(Inputfile*) to format a file object.
llvm-svn: 301674
2017-04-28 20:00:09 +00:00
Rui Ueyama 72408fb2ac Remove trailing whitespace from the -Map output.
If a string is shorter than 7 characters, we used to print out
trailing whitespace characters.

llvm-svn: 301668
2017-04-28 18:54:08 +00:00
Rui Ueyama 2634d0ff5c Remove a redundant local variable.
llvm-svn: 301661
2017-04-28 17:50:23 +00:00
Rui Ueyama b882e5910d Speed up the -Map option.
We found that some part of code for the -Map option takes O(m*n)
where m is the number of input sections in some file and n is
the number of symbols in the same file. If you do LTO, we usually
have only a few object files as inputs for the -Map option
feature, so this performance characteristic was worse than I
expected.

This patch rewrites the -Map option feature to speed it up.
I eliminated the O(m*n) bottleneck and also used multi-threading.

As a result, clang link time with the -Map option improved from
18.7 seconds to 11.2 seconds. Without -Map, it takes 7.7 seconds,
so the -Map option is now about 3x faster than before for this
test case (from 11.0 seconds to 3.5 seconds.) The generated output
file size was 223 MiB, and the file contains 1.2M lines.

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

llvm-svn: 301659
2017-04-28 17:19:13 +00:00
Rui Ueyama 42fca6e794 Recommend users use readelf instead of objdump to dump .comment contents.
readelf's output is much easier to read than objdump's as you can see below.

  $ readelf --string-dump .comment foo
  String dump of section '.comment':
    [     1]  GCC: (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
    [    2c]  clang version 5.0.0
    [    41]  Linker: LLD 5.0.0

  $ objdump -j .comment -s foo
  Contents of section .comment:
   0000 00474343 3a202855 62756e74 7520342e  .GCC: (Ubuntu 4.
   0010 382e342d 32756275 6e747531 7e31342e  8.4-2ubuntu1~14.
   0020 30342e33 2920342e 382e3400 636c616e  04.3) 4.8.4.clan
   0030 67207665 7273696f 6e20352e 302e3020  g version 5.0.0
   0040 004c696e 6b65723a 204c4c44 20352e30  .Linker: LLD 5.0
   0050 2e3000                               .0.

llvm-svn: 301515
2017-04-27 04:50:08 +00:00
Rui Ueyama c9d82b9e16 Simplify BinaryFile::parse and add comments.
llvm-svn: 301514
2017-04-27 04:01:36 +00:00
Rui Ueyama 63d48e5956 Remove needless type conversions.
llvm-svn: 301513
2017-04-27 04:01:14 +00:00
Rui Ueyama e5ad2986fc Remove unnecessary instantiation of StringRef.
SoName's type has changed from StringRef to std::string, so this
code does not make sense anymore.

llvm-svn: 301490
2017-04-26 23:00:32 +00:00
Rui Ueyama 330e52b018 Removes createELFFile which takes a template class as a template parameter.
This patch is to reduce amount of template uses. The new code is less
exciting and boring than before, but I think it is easier to read.

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

llvm-svn: 301488
2017-04-26 22:51:51 +00:00
Rafael Espindola 4f013bb3b2 Create an OutputSection for each non-empty OutputSectionCommand.
We were already pretty close, the one exception was when a name was
reused in another SECTIONS directive:

SECTIONS {
  .text : { *(.text) }
  .data : { *(.data) }
}
SECTIONS {
  .data : { *(other) }
}

In this case we would create a single .data and magically output
"other" while looking at the first OutputSectionCommand.

We now create two .data sections. This matches what gold does. If we
really want to create a single one, we should change the parser so that
the above is parsed as if the user had written

SECTIONS {
  .text : { *(.text) }
  .data : { *(.data) *(other)}
}

That is, there should be only one OutputSectionCommand for .data and
it would have two InputSectionDescriptions.

By itself this patch makes the code a bit more complicated, but is an
important step in allowing assignAddresses to operate just on the
linker script.

llvm-svn: 301484
2017-04-26 22:30:15 +00:00
Rui Ueyama cf8247ef48 Do flag compatibility check in checkOptions. NFC.
llvm-svn: 301476
2017-04-26 21:27:33 +00:00
Rui Ueyama 08af54c304 Factor out code to parse -build-id. NFC.
llvm-svn: 301475
2017-04-26 21:23:11 +00:00
Rui Ueyama d283eb7091 Make LLD work even if the current directory is not writable.
llvm-svn: 301423
2017-04-26 16:15:07 +00:00
Rui Ueyama 7163027884 Move code to emit error messages from Filesystem.cpp to Driver.cpp.
isFileWritable() checked if a file is writable and then emitted
an error message if it is not writable. So it did more than the
name says. This patch moves error() calls to Driver.

llvm-svn: 301422
2017-04-26 16:14:46 +00:00
George Rimar 3505716d72 [ELF] - Remove dead TLS relocations relative code for MIPS and ARM
This code was not used because of
handleARMTlsRelocation and handleMipsTlsRelocation methods that are called
for these platforms instead of regular TLS code.

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

llvm-svn: 301414
2017-04-26 14:48:36 +00:00
George Rimar 9703ad2221 [ELF] - Implemented --defsym option.
gnu ld description of option is:

--defsym=symbol=expression
Create a global symbol in the output file, containing the absolute address given 
by expression. You may use this option as many times as necessary to define multiple
symbols in the command line. A limited form of arithmetic is supported for the 
expression in this context: you may give a hexadecimal constant or the name of an
existing symbol, or use "+" and "-" to add or subtract hexadecimal constants or 
symbols. If you need more elaborate expressions, consider using the linker command
language from a script. Note: there should be no white space between symbol, 
the equals sign ("="), and expression.

In compare with D32082, this patch does not support math expressions and absolute
symbols. It implemented via code similar to --wrap. That covers 1 of 3 possible
--defsym cases.

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

llvm-svn: 301391
2017-04-26 10:40:02 +00:00
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