Commit Graph

365 Commits

Author SHA1 Message Date
Rui Ueyama 175e81cf3a Use make<> instead of new (BAlloc). NFC.
We converted them before, but there were a few remaining occurrences.

llvm-svn: 296510
2017-02-28 19:36:30 +00:00
Rui Ueyama 80474a26b9 De-template DefinedRegular.
Differential Revision: https://reviews.llvm.org/D30348

llvm-svn: 296508
2017-02-28 19:29:55 +00:00
Sean Silva 1d96185f57 Add Triple::thumb to getBitcodeMachineKind
We really need to find a way to get this info from a single point of
truth in the LLVM backend, but it seems that the EM_* constants are
buried deep inside the constructors of the MCAsmBackend's.

For now, just fill in entries as we run into cases. AFAIK these mappings
are largely immutable, so we get a 75% discount on the technical debt
(code is duplicated, but little chance of divergence).

llvm-svn: 296429
2017-02-28 03:00:48 +00:00
Rui Ueyama 9cc84384ad Use uint64_t instead of uintX_t where the larger type just works.
llvm-svn: 296162
2017-02-24 19:52:52 +00:00
Rafael Espindola 774ea7d0a9 Make InputSection a class. NFC.
With the current design an InputSection is basically anything that
goes directly in a OutputSection. That includes plain input section
but also synthetic sections, so this should probably not be a
template.

llvm-svn: 295993
2017-02-23 16:49:07 +00:00
Rui Ueyama b7f39b08f4 Slightly improve an error message.
llvm-svn: 295942
2017-02-23 07:35:30 +00:00
Rui Ueyama c1a0ac2c4a Add a comment about .note.GNU-split-stack.
llvm-svn: 295941
2017-02-23 07:35:11 +00:00
Rui Ueyama 65efe35632 Update comment: .note.GNU-stack is added by default today.
llvm-svn: 295939
2017-02-23 07:15:46 +00:00
Rui Ueyama 0633273d05 Update a comment about .note.GNU-stack.
llvm-svn: 295938
2017-02-23 07:06:43 +00:00
Rui Ueyama 6e0142d78c Use isa<MergeInputSection> to check if a section is a merge section.
We have InputSection, MergeInputSection and EhInputSection, so
isa<MergeInputSection> is equivalent to !isa<InputSection> && !isa<
EhInputSection>.

llvm-svn: 295937
2017-02-23 06:47:18 +00:00
Rafael Espindola b4c9b81aad Convert InputSectionBase to a class.
Removing this template is not a big win by itself, but opens the way
for removing more templates.

llvm-svn: 295923
2017-02-23 02:28:28 +00:00
Rui Ueyama e6e206d4b4 Do not use errs() or outs() directly. Instead use message(), log() or error()
LLD is a multi-threaded program. errs() or outs() are not guaranteed
to be thread-safe (they are actually not).

LLD's message(), log() or error() are thread-safe. We should use them.

llvm-svn: 295787
2017-02-21 23:22:56 +00:00
George Rimar 858a659a4f [ELF] - Added support of linkerscript's "/DISCARD/" for --emit-relocs
Previously LLD crashed on on provided testcases because "/DISCARD/" was
not supported. Patch implements that.

After this I think there is no known issues with --emit-relocs implementation
required for linux kernel linking.

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

llvm-svn: 295488
2017-02-17 19:46:47 +00:00
George Rimar 647c1685b6 [ELF] - Move DependentSections vector from InputSection to InputSectionBase
I splitted it from D29273.
Since we plan to make relocatable sections as dependent for target ones for
--emit-relocs implementation, this change is required to support .eh_frame case.

EhInputSection inherets from InputSectionBase and not from InputSection.
So for case when it has relocation section, it should be able to access DependentSections
vector.

This case is real for Linux kernel.

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

llvm-svn: 295483
2017-02-17 19:34:05 +00:00
George Rimar 09015fee3c [ELF] - Allow section to have multiple dependent sections.
That fixes a case when section has more than one metadata 
section. Previously GC would collect one of such sections 
because we had implementation that stored only last one as
dependent.

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

llvm-svn: 295298
2017-02-16 08:41:19 +00:00
George Rimar ee6f22ce0b [ELF] - Do not segfault when using -r and section groups.
If we had SHT_GROUP sections, then when -r was used we might crash.
This is PR31952.

Issue happened because we emited relocation section though its target was discared
because was a member of duplicated group. When we tried to get VA of target,
segfault happened.
Core cause is the bug that GNU as 2.27 (and probably later versions) has.
In compare with llvm-mc, it does not include relocation sections into the group, 
like shown in testcase. This patch covers that case.

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

llvm-svn: 295067
2017-02-14 16:42:38 +00:00
George Rimar 82bd8be6d8 Recommit r294464 "[ELF] - Added partial support for --emit-relocs (no --gc-section case, no /DISCARD/ support) #3"
with temporarily file name fix in testcase.

Original commit message:

-q, --emit-relocs - Generate relocations in output

Simplest implementation: 
* no GC case, 
* no "/DISCARD/" linkerscript command support.

This patch is extracted from D28612 / D29636,

Relative to PR31579.

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

llvm-svn: 294469
2017-02-08 16:18:10 +00:00
George Rimar 0b2cc8190d Reverted r294464 "[ELF] - Added partial support for --emit-relocs (no --gc-section case, no /DISCARD/ support) #3"
Broked build bot:
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/5835/steps/test/logs/stdio

llvm-svn: 294466
2017-02-08 16:10:14 +00:00
George Rimar d6ae624552 [ELF] - Added partial support for --emit-relocs (no --gc-section case, no /DISCARD/ support) #3
-q, --emit-relocs - Generate relocations in output

Simplest implementation: 
* no GC case, 
* no "/DISCARD/" linkerscript command support.

This patch is extracted from D28612 / D29636,

Relative to PR31579.

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

llvm-svn: 294464
2017-02-08 15:53:33 +00:00
Peter Smith 3a52eb0054 [ELF] Use SyntheticSections for Thunks
Thunks are now implemented by redirecting the relocation to the
symbol S, to a symbol TS in a Thunk. The Thunk will transfer control
to S. This has the following implications:
- All the side-effects of Thunks happen within createThunks()
- Thunks are no longer stored in InputSections and Symbols no longer
  need to hold a pointer to a Thunk
- The synthetic Thunk sections need to be merged into OutputSections
    
This implementation is almost a direct conversion of the existing
Thunks with the following exceptions:
- Mips LA25 Thunks are placed before the InputSection that defines
  the symbol that needs a Thunk.
- All ARM Thunks are placed at the end of the OutputSection of the
  first caller to the Thunk.
    
Range extension Thunks are not supported yet so it is optimistically
assumed that all Thunks can be reused.

This is a recommit of r293283 with a fixed comparison predicate as
std::merge requires a strict weak ordering.

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

llvm-svn: 293757
2017-02-01 10:26:03 +00:00
Rui Ueyama f20ee9f11a Revert "[ELF][ARM] Use SyntheticSections for Thunks"
This reverts commit r293283 because it broke MSVC build.

llvm-svn: 293352
2017-01-28 00:48:06 +00:00
Peter Smith 5191c6f945 [ELF][ARM] Use SyntheticSections for Thunks
Thunks are now implemented by redirecting the relocation to the
symbol S, to a symbol TS in a Thunk. The Thunk will transfer control
to S. This has the following implications:
- All the side-effects of Thunks happen within createThunks()
- Thunks are no longer stored in InputSections and Symbols no longer
  need to hold a pointer to a Thunk
- The synthetic Thunk sections need to be merged into OutputSections
    
This implementation is almost a direct conversion of the existing
Thunks with the following exceptions:
- Mips LA25 Thunks are placed before the InputSection that defines
  the symbol that needs a Thunk.
- All ARM Thunks are placed at the end of the OutputSection of the
  first caller to the Thunk.
    
Range extension Thunks are not supported yet so it is optimistically
assumed that all Thunks can be reused.

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

llvm-svn: 293283
2017-01-27 13:10:16 +00:00
Rui Ueyama c8d3a83fff Remove error(error_code, const Twine &).
Now we have the consistent interface for all log/warn/error/fatal functions.

llvm-svn: 291847
2017-01-12 22:18:04 +00:00
Rafael Espindola 79114a673e Make the -b binary .data section rw.
This matches what bfd and gold do. It also matches the common flags of
other .data sections.

llvm-svn: 291674
2017-01-11 15:13:05 +00:00
Peter Collingbourne c39e5d64b3 ELF: Discard .gnu.linkonce.* sections.
The linkonce feature is a sort of proto-comdat. As far as I am aware no
compiler produces linkonce sections anymore, but some glibc i386 object
files contain definitions of symbol "__x86.get_pc_thunk.bx" in linkonce
sections. Drop those sections to avoid duplicate symbol errors.

This is glibc PR20543, we should remove this hack once that has been
fixed for a while.

Fixes PR31215.

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

llvm-svn: 291474
2017-01-09 20:26:33 +00:00
Rui Ueyama ec1c75e059 Add linker-script-included files to reproduce tar files.
Previously, files added using INCLUDE directive weren't added
to reproduce archives. In this patch, I defined a function to
open a file and use that from Driver and LinkerScript.

llvm-svn: 291413
2017-01-09 01:42:02 +00:00
Rafael Espindola 2756e04fac Handle versioned undefined symbols.
In order to keep symbol lookup a simple name lookup this patch adds
versioned symbols with an explicit @ to the symbol table.

llvm-svn: 291293
2017-01-06 22:30:35 +00:00
Rui Ueyama ce039266c1 Merge elf::toString and coff::toString.
The two overloaded functions hid each other. This patch merges them.

llvm-svn: 291222
2017-01-06 10:04:08 +00:00
Rui Ueyama 214a897681 Use \ as the path separator on Windows.
Previously, when we printed out a path obtained from DWARF debug info,
we replaced \ with / on Windows. But that doesn't make sense. We should
respect the system's path separator.

llvm-svn: 291219
2017-01-06 08:59:32 +00:00
Rui Ueyama 7f1f912794 Use TarWriter to create tar archives instead of cpio.
This is how we use TarWriter in LLD. Now LLD does not append
a file extension, so you need to pass `--reproduce foo.tar`
instead of `--reproduce foo`.

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

llvm-svn: 291210
2017-01-06 02:33:53 +00:00
Peter Smith 97c6d78f3e [ELF] Add support for thunks to undefined non-weak symbols
In a shared library an undefined symbol is implicitly imported. If the
symbol is called as a function a PLT entry is generated for it. When the
caller is a Thumb b.w a thunk to the PLT entry is needed as all PLT
entries are in ARM state.
    
This change allows undefined symbols to have thunks in the same way that
shared symbols may have thunks.

llvm-svn: 290951
2017-01-04 09:45:45 +00:00
Rui Ueyama 9381eb1045 Remove lld/Support/Memory.h.
I thought for a while about how to remove it, but it looks like we
can just copy the file for now. Of course I'm not happy about that,
but it's just less than 50 lines of code, and we already have
duplicate code in Error.h and some other places. I want to solve
them all at once later.

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

llvm-svn: 290062
2016-12-18 14:06:06 +00:00
Peter Smith 532bc984f5 [ELF] Accept first SHT_ARM_ATTRIBUTES section
The eglibc library, as used by Ubuntu 14.04 requires the presence of an
SHT_ARM_ATTRIBUTES section in for the purposes of checking hard/soft float
compatibility when dlopen() is used. Unfortunately when the section is not
present dlopen() fails with a generic could not find file message.
    
This change makes lld keep the first .ARM.attributes section that it
encounters and propagates it to the output. This is not a complete
SHT_ARM_ATTRIBUTES implementation, that would involve reading the contents
of the section and joining each individual attribute. It should suffice
for a homogenous build all libraries and executables on the same system
with a compatible set of command line options.

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

llvm-svn: 289642
2016-12-14 10:36:12 +00:00
Rui Ueyama 520d9169e6 Move Memory.{h,cpp} to lld/Support so that we can use them from COFF.
llvm-svn: 289084
2016-12-08 18:31:13 +00:00
Rui Ueyama 9a97acc097 Remove redundant call of std::unique_ptr::get.
Obj is an instance of std::unique_ptr, so *Obj.get() is the same as *Obj.

llvm-svn: 288996
2016-12-07 23:26:39 +00:00
Rui Ueyama f966fe6c38 Do not pass line number to convertToUnixPathSeparator.
Line number can never contain '/' or '\', so the previous code
was pointless at that point.

llvm-svn: 288973
2016-12-07 20:25:45 +00:00
Rui Ueyama 63d064e9d1 Make convertToUnixPathSeparator return a new string instead of mutating argument.
llvm-svn: 288972
2016-12-07 20:22:27 +00:00
George Rimar 49326e4d84 Format. NFC.
llvm-svn: 288967
2016-12-07 19:44:27 +00:00
George Rimar 92c88a4f76 [ELF] - Print absolute file name in errors when possible.
Currently LLD prints basename of source file name in error messages,
for example:
$ mkdir foo
$ echo 'void _start(void) { foobar(); }' > foo/bar.c
$ gcc -g -c foo/bar.c
$ bin/ld.lld -o out bar.o 
bin/ld.lld: error: bar.c:1: undefined symbol 'foobar'
$
This should say:
bin/ld.lld: error: foo/bar.c:1: undefined symbol 'foobar'

This is PR31299

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

llvm-svn: 288966
2016-12-07 19:42:25 +00:00
Rui Ueyama 84e65a7ca1 Use StringRefZ explicitly instead of const char *.
This patch is to avoid an implicit conversion from const char * to
StringRefZ, to make it apparent where we are using StringRefZ.

llvm-svn: 288182
2016-11-29 19:11:39 +00:00
Rui Ueyama a13efc2a73 Introduce StringRefZ class to represent null-terminated strings.
StringRefZ is a class to represent a null-terminated string. String
length is computed lazily, so it's more efficient than StringRef to
represent strings in string table.

The motivation of defining this new class is to merge functions
that only differ in string types; we have many constructors that takes
`const char *` or `StringRef`. With StringRefZ, we can merge them.

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

llvm-svn: 288172
2016-11-29 18:05:04 +00:00
Rui Ueyama 623b36e358 Move typedefs inside a class definition.
llvm-svn: 287945
2016-11-25 18:51:56 +00:00
Rui Ueyama 3fc0f7e54f Define toString() as a generic function to get a string for error message.
We have different functions to stringize objects to construct
error messages. For InputFile, we have getFilename, and for
InputSection, we have getName. You had to memorize them.

I think this is the case where the function overloading comes in handy.

This patch defines toString() functions that are overloaded for all these
types, so that you just call it in error().

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

llvm-svn: 287787
2016-11-23 18:07:33 +00:00
Eugene Leviant c3a44b2fbe [ELF] Refactor several error messages
Differential revision: https://reviews.llvm.org/D26970

llvm-svn: 287753
2016-11-23 10:07:46 +00:00
Rui Ueyama 0cbf749397 Remove one of SymbolTable::addRegular function that forwards other addRegular.
So that we have less number of overloaded functions.

llvm-svn: 287745
2016-11-23 06:59:47 +00:00
Rui Ueyama c72ba3a4d7 Allow calling getName() on local symbols.
Previously, we stored offsets in string tables to symbols, so
you needed to pass a string table to get a symbol name. This patch
stores const char pointers instead to eliminate the need to pass
a string table.

llvm-svn: 287737
2016-11-23 04:57:25 +00:00
Rui Ueyama e8785ba4d7 Change the way how we print out line numbers.
LLD's error messages contain line numbers, function names or section names.
Currently they are formatter as follows.

  foo.c (32): symbol 'foo' not found
  foo.c (function bar): symbol 'foo' not found
  foo.c (.text+0x1234): symbol 'foo' not found

This patch changes them so that they are consistent with Clang's output.

  foo.c:32: symbol 'foo' not found
  foo.c:(function bar): symbol 'foo' not found
  foo.c:(.text+0x1234): symbol 'foo' not found

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

llvm-svn: 287537
2016-11-21 13:49:57 +00:00
Eugene Leviant 7d7ff80f4b [ELF] Better error reporting for broken archives
Differential revision: https://reviews.llvm.org/D26852

llvm-svn: 287527
2016-11-21 09:28:07 +00:00
George Rimar 463984d4bf [ELF] - Better diagnostic for relative relocation to an absolute value error.
Patch adds a filename to that error message.

I faced next error when debugged one of FreeBSD port:
error: relocation R_X86_64_PLT32 cannot refer to absolute symbol __tls_get_addr

error message was poor and this patch improves it to show the locations 
of symbol declaration and using.

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

llvm-svn: 286940
2016-11-15 08:07:14 +00:00
George Rimar 308752e474 [ELF] - Allow symbols of STT_NOTYPE to be associated with SHT_SYMTAB sections.
Found this when tried to link lang/ccl FreeBSD port.
Issue is very close to D23201.
This is the reason of lang/ccl port link fail.

GNU assembler 2.17.50 [FreeBSD] 2007-07-03 could generate broken objects,
where notype symbols are associated with symtab:
...
[ 9] .symtab           SYMTAB           0000000000000000  00003c78
     0000000000006858  0000000000000018          10   803     8
...
192: 000000000000000d     0 NOTYPE  LOCAL  DEFAULT    9 _cons_org

Patch allows to handle such objects.

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

llvm-svn: 286939
2016-11-15 07:56:28 +00:00