Commit Graph

3397 Commits

Author SHA1 Message Date
Rui Ueyama 360bace8eb COFF: Add /alternatename option.
Previously, this feature was implemented using a special type of
undefined symbol, in addition to an intricate way to make the resolver
read a virtual file containing that renaming symbols.

Now the feature is directly handled by the symbol table.
The symbol table has a function, rename(), to rename symbols, whose
definition is 4 lines long. Symbol renaming is naturally modeled using
Symbol and SymbolBody.

llvm-svn: 238696
2015-05-31 22:31:31 +00:00
Rui Ueyama 711cd2d7c8 COFF: Detect file type by file magic.
llvm-svn: 238691
2015-05-31 21:17:10 +00:00
Rui Ueyama d7c2f5847a COFF: Make the Driver own all MemoryBuffers. NFC.
Previously, a MemoryBuffer of a file was owned by each InputFile object.
This patch makes the Driver own all of them. InputFiles now have only
MemoryBufferRefs. This change simplifies ownership managment
(particularly for ObjectFile -- the object owned a MemoryBuffer only when
it's not created from an archive file, because in that case a parent
archive file owned the entire buffer. Now it owns nothing unconditionally.)

llvm-svn: 238690
2015-05-31 21:04:56 +00:00
Simon Atanasyan faa8bfdd1a [Mips] Add a couple of MipsAbiInfoHandler functions to check linked code type
No functional changes.

llvm-svn: 238689
2015-05-31 20:37:22 +00:00
Simon Atanasyan 2944e4a43d [Mips] Do not put the .reginfo section into the separate segment
The .reginfo should not belong to the separate segment if there is
a .MIPS.abiflags section.

llvm-svn: 238688
2015-05-31 20:37:13 +00:00
Simon Atanasyan c140b41c39 [Mips] Sort segments so PT_MIPS_ABIFLAGS goes right after the PT_INTERP
llvm-svn: 238687
2015-05-31 20:36:58 +00:00
Simon Atanasyan c90c425735 [Mips] Reading, merging and writing .MIPS.abiflags section
http://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking

llvm-svn: 238686
2015-05-31 20:36:43 +00:00
Simon Atanasyan 3eec407a53 [Mips] Delete MipsReginfo structure. Use the Elf_Mips_RegInfo instead.
llvm-svn: 238685
2015-05-31 20:36:21 +00:00
Simon Atanasyan 70e21bc83d [Mips] Collect all ABI related info in the single MipsAbiInfoHandler class
New MipsAbiInfoHandler merges and hold both ELF header flags
and registries usage masks. In the future commits it will manage some
additional information.

llvm-svn: 238684
2015-05-31 20:36:11 +00:00
Rui Ueyama f4784cce54 COFF: /libpath should not take precedence over the current directory.
llvm-svn: 238683
2015-05-31 20:20:37 +00:00
Rui Ueyama 0613747e1a COFF: Add /libpath option.
llvm-svn: 238682
2015-05-31 20:10:11 +00:00
Rui Ueyama e042fa9aa5 COFF: Add /include option.
It does not involve notions of virtual archives or virtual files,
nor store a list of undefined symbols somewhere else to consume them later.
We did that before. In this patch, undefined symbols are just added to
the symbol table, which now can be done in very few lines of code.

llvm-svn: 238681
2015-05-31 19:55:40 +00:00
Rui Ueyama d21b00bd7c COFF: Add /nodefaultlib option.
llvm-svn: 238679
2015-05-31 19:17:14 +00:00
Rui Ueyama 54b71daec4 COFF: Refactor functions to find files from search paths.
llvm-svn: 238678
2015-05-31 19:17:12 +00:00
Rui Ueyama a9cbbf885f COFF: Create LinkerDriver class.
Previously the main linker routine is just a non-member function.
We store some context information to the Config object.
This patch makes it belong to Driver.

llvm-svn: 238677
2015-05-31 19:17:09 +00:00
Rui Ueyama 80b5689d91 COFF: Use range-based for loop.
llvm-svn: 238675
2015-05-31 16:10:50 +00:00
Rui Ueyama aa47cf9dae COFF: Remove redundant options from tests.
llvm-svn: 238670
2015-05-31 04:21:30 +00:00
Rui Ueyama d68ff34ad2 Fix unsafe memory access.
llvm-svn: 238669
2015-05-31 03:57:30 +00:00
Rui Ueyama 3ee0fe4c2c COFF: Implement subsystem inference.
llvm-svn: 238668
2015-05-31 03:55:46 +00:00
Rui Ueyama 5cff68599d COFF: Infer entry symbol name if /entry is not given.
`main` is not the only main function in Windows. You can choose one
from these four -- {w,}{WinMain,main}. There are four different entry
point functions for them, {w,}{WinMain,main}CRTStartup, respectively.
The linker needs to choose the right one depending on which `main`
function is defined.

llvm-svn: 238667
2015-05-31 03:34:08 +00:00
Rui Ueyama e00d651071 Use initializer instead of memset to zero out.
llvm-svn: 238662
2015-05-30 19:28:58 +00:00
Rui Ueyama bfb4aa1791 COFF: Support long section name.
Section names were truncated to 8 bytes because the section table's
name field is 8 byte long. This patch creates the string table to
store long names.

llvm-svn: 238661
2015-05-30 19:09:50 +00:00
Peter Collingbourne 246ccc5f51 COFF: Move machine type auto-detection to SymbolTable.
The new mechanism is less code, and fixes the case where all inputs
are archives.

Differential Revision: http://reviews.llvm.org/D10136

llvm-svn: 238618
2015-05-29 21:47:36 +00:00
Rui Ueyama 15cc47ee81 COFF: Add /subsystem option.
llvm-svn: 238571
2015-05-29 16:34:31 +00:00
Rui Ueyama b9dcdb5fc9 COFF: Add /version option.
llvm-svn: 238570
2015-05-29 16:28:29 +00:00
Rui Ueyama c377e9aefe COFF: Add /heap option.
llvm-svn: 238569
2015-05-29 16:23:40 +00:00
Rui Ueyama b41b7e5a69 Add /stack option.
llvm-svn: 238568
2015-05-29 16:21:11 +00:00
Rui Ueyama 804a8b6361 COFF: Add /base option.
llvm-svn: 238567
2015-05-29 16:18:15 +00:00
Rui Ueyama 5c726433d2 COFF: Add /help option.
llvm-svn: 238565
2015-05-29 16:11:52 +00:00
Rui Ueyama 3d3e6fba6e COFF: Add /machine option.
llvm-svn: 238564
2015-05-29 16:06:00 +00:00
Rui Ueyama 7c4fcdd559 COFF: Move Windows-specific function under Windows-specific marker.
llvm-svn: 238563
2015-05-29 15:49:09 +00:00
Rui Ueyama c9bfe32010 COFF: Fill imort table HintName field.
Currently we set the field to zero, but as per the spec, we should
set numbers we read from import library files. The loader uses the
values as starting offsets for binary search when looking up imported
symbols from DLL.

llvm-svn: 238562
2015-05-29 15:45:35 +00:00
Rui Ueyama 322b2c413d COFF: Return an error_code directly.
llvm-svn: 238486
2015-05-28 20:39:29 +00:00
Rui Ueyama 3500f6667a COFF: Split Driver.cpp to Driver.cpp and DriverUtils.cpp. NFC.
The previous implementation's driver file is cluttered by lots of
small functions, and it was hard to find important functions.
Make a separate file to prevent that issue.

llvm-svn: 238482
2015-05-28 20:30:06 +00:00
Rui Ueyama d52824d361 Rename InputFile::Name -> InputFile::Filename.
Other local variables shadowed the member variable.
Rename to make that a bit longer.

llvm-svn: 238478
2015-05-28 20:16:25 +00:00
Rui Ueyama 9aefa0c6b9 Fix non-debug build.
llvm-svn: 238474
2015-05-28 20:04:51 +00:00
Rui Ueyama d6fefba447 COFF: Teach Chunk to write to a mmap'ed output file.
Previously Writer directly handles writes to a file.
Chunks needed to give Writer a continuous chunk of memory.
That was inefficent if you construct data in chunks because
it would require two memory copies (one to construct a chunk
and the other is to write that to a file).

This patch teaches chunk to write directly to a file.
From readability point of view, this is also good because
you no longer have to call hasData() before calling getData().

llvm-svn: 238464
2015-05-28 19:45:43 +00:00
Rui Ueyama 411c636081 COFF: Add a new PE/COFF port.
This is an initial patch for a section-based COFF linker.

The patch has 2300 lines of code including comments and blank lines.
Before diving into details, you want to start from reading README
because it should give you an overview of the design.

All important things are written in the README file, so I write
summary here.

- The linker is already able to self-link on Windows.

- It's significantly faster than the existing implementation.
  The existing one takes 5 seconds to link LLD on my machine,
  while the new one only takes 1.2 seconds, even though the new
  one is not multi-threaded yet. (And a proof-of-concept multi-
  threaded version was able to link it in 0.5 seconds.)

- It uses much less memory (250MB vs. 2GB virtual memory space
  to self-host).

- IMHO the new code is much simpler and easier to read than
  the existing PE/COFF port.

http://reviews.llvm.org/D10036

llvm-svn: 238458
2015-05-28 19:09:30 +00:00
Michael J. Spencer 42a738198b Fix unused variable warnings.
llvm-svn: 238384
2015-05-28 00:29:56 +00:00
Michael J. Spencer cc0554d057 Add PHDR and FILL parsing.
llvm-svn: 238383
2015-05-28 00:14:58 +00:00
Simon Atanasyan 06eccbea9d [Mips] Move member function definitions to cpp files
No functional changes.

llvm-svn: 238310
2015-05-27 11:56:15 +00:00
Simon Atanasyan bb399f3d57 [ELF][Mips] Do not merge ELF flags in the `isCompatible` routine
We do not need to merge ELF flags from DSO. But `isCompatible` is called
for all input files. So this change move ELF flags merging into the
MipsELFFile class.

llvm-svn: 238304
2015-05-27 08:45:31 +00:00
Simon Atanasyan 256f2cadfe [Mips] Factor out look up of Elf_Mips_RegInfo structure into the separate function
No functional changes.

llvm-svn: 238303
2015-05-27 08:45:21 +00:00
Adhemerval Zanella f3c1c065aa [ELF/AArch64] Fix local TLS relocations
This patch fixes the R_AARCH64_TLSLE_ADD_TPREL_HI12 and R_AARCH64_TLSLE_ADD_TPREL_LO12_NC
handling by using the correct offset by using the target layout along with
aarch64 alignments requirements.

It fixes the TLS test-suite SingleSource failures for aarch64:

* SingleSource/UnitTests/Threads/2010-12-08-tls.execution_time
* SingleSource/UnitTests/Threads/tls.execution_time

llvm-svn: 238258
2015-05-26 21:49:39 +00:00
Denis Protivensky 499292dede [ARM] Fix enum type cast in switch
It caused warning in clang assuming the default
branch would never be reached with the given
switch key type.

llvm-svn: 238194
2015-05-26 11:13:09 +00:00
Denis Protivensky 02fc0b1d64 [ARM] Move out .ARM.exidx related things to ARM backend
llvm-svn: 238191
2015-05-26 10:26:15 +00:00
Simon Atanasyan b48abf5dac [Mips] Use structures declared in the llvm/Object/ELFTypes.h
No functional changes.

llvm-svn: 238189
2015-05-26 08:48:33 +00:00
Simon Atanasyan e62aa7457f [Mips] Add Elf_Mips_Options::getRegInfoDesc() function to retrieve an ODK_REGINFO descriptor
No functional changes.

llvm-svn: 238176
2015-05-26 06:05:07 +00:00
Simon Atanasyan e09faec16e [Mips] Make the code shorter - use LLVM_ELF_IMPORT_TYPES_ELFT macro
No functional changes.

llvm-svn: 238175
2015-05-26 06:05:01 +00:00
Davide Italiano 683703ea6d [ELF] Add support for -z origin/now options.
Differential Revision:	http://reviews.llvm.org/D9963

llvm-svn: 238169
2015-05-26 01:57:32 +00:00
Simon Atanasyan 0b22359858 [ELF] Fix lld when no unique sections is used
Original patch of Shankar Easwaran with additional test case.
The yaml2obj does not allow to create an object file with non-unique
sections names so the fix uses a binary input object file in the test
case.

llvm-svn: 238115
2015-05-24 16:19:27 +00:00
Lang Hames 825e258fc3 [lld] Manage atom ordinals in the File class rather than using a static counter.
This is a cleaner fix for the race-condition bug that was originally papered
over by r237857.

llvm-svn: 238072
2015-05-22 23:56:44 +00:00
Simon Atanasyan b2f6afb30a [Mips] Cleanup and reformat test cases, add more checkings
No functional changes.

llvm-svn: 238050
2015-05-22 21:08:37 +00:00
Benjamin Kramer ebcc0dcad1 Remove redundant std::move on functions that return a unique_ptr.
llvm-svn: 238034
2015-05-22 17:52:04 +00:00
Benjamin Kramer 91d8cfd698 [ELF] Remove redundant unique_ptr moves found by -Wpessimizing-move.
llvm-svn: 238030
2015-05-22 16:01:21 +00:00
Benjamin Kramer fc99f3d43f [ELF] Fix shared CMake build.
llvm-svn: 238029
2015-05-22 16:01:12 +00:00
Denis Protivensky f2c22f4ff8 [ARM] report_fatal_error for not implemented functionality
llvm-svn: 238017
2015-05-22 12:39:05 +00:00
Denis Protivensky 575f7d4f1c [ARM] Ability to add GOT and PLTGOT entries for same symbol
These two serve different purpose:
PLTGOT entries are (usually) lazily resolved and serve as trampolines
to correctly call dynamically linked functions. They often have
R_*_JUMP_SLOT dynamic relocation type used.
Simple GOT entries hold other things, one of them may be
R_*_GLOB_DAT to correctly reference global and static data. This
is also used to hold dynamically linked function's address.

To properly handle cases when shared object's function is called
and at the same time its address is taken, we need to be able to have
both GOT and PLTGOT entries bearing different dynamic relocation types
for the same symbol.

llvm-svn: 238015
2015-05-22 11:23:39 +00:00
Denis Protivensky 214122cffc [ARM] Implement R_ARM_GLOB_DAT for GOT entries
This is used when referencing global or static data in shared
objects. This is also used when function's address is taken and
function call is made indirectly.

llvm-svn: 238014
2015-05-22 11:00:31 +00:00
Lang Hames ff4b13c538 [lld] Make the MachO -stack_size default '0', add a test case.
Addresses some review comments for r237841.

llvm-svn: 237979
2015-05-22 00:25:34 +00:00
Davide Italiano 339191fcfa [ELF] Simplify dynamic table entry creation.
Differential Revision:	http://reviews.llvm.org/D9921
Reviewed by:  atanasyan

llvm-svn: 237973
2015-05-21 23:44:19 +00:00
Denis Protivensky af1c9dd513 [ARM] Add dynamic symbols to the dynamic library writer
llvm-svn: 237898
2015-05-21 12:52:00 +00:00
Denis Protivensky eb273b6b28 [ARM] Remove useless file with writer's instantiation stub
llvm-svn: 237896
2015-05-21 12:31:15 +00:00
Denis Protivensky db2b179b1e [ARM] Remove unused field in executable writer
llvm-svn: 237892
2015-05-21 11:50:54 +00:00
Denis Protivensky ad52e44e98 [ARM] Move out common Writer functionality to ARMELFWriter
llvm-svn: 237891
2015-05-21 11:16:40 +00:00
Denis Protivensky 30e40be080 [ELF] Move start/end atom method assignment to OutputELFWriter. NFC
llvm-svn: 237886
2015-05-21 10:11:27 +00:00
Denis Protivensky e6651618a8 [ARM] Remove unused fields in dynamic library writer
llvm-svn: 237883
2015-05-21 09:52:21 +00:00
Denis Protivensky 2db1a03b07 [ARM] Add skeleton implementation of DSO linking
llvm-svn: 237881
2015-05-21 09:28:25 +00:00
Lang Hames b103c0321f [LLD] Make lastOrdinal atomic to avoid race conditions.
No test case: We don't have a good way to test race conditions.

llvm-svn: 237857
2015-05-20 23:44:37 +00:00
Lang Hames 2a10996706 [LLD] Fix an out-of-order-initialization bug that was introduced in r237841 by
moving a field in MachOLinkingContext.

llvm-svn: 237847
2015-05-20 22:35:20 +00:00
Lang Hames d48be84032 [LLD] Revert r237842 - it went in without a proper commit message.
llvm-svn: 237846
2015-05-20 22:33:34 +00:00
Lang Hames d39a6d20c2 y
llvm-svn: 237842
2015-05-20 22:26:06 +00:00
Lang Hames 65a64c9c29 [LLD] Add support for the -stack_size option to Darwin ld.
llvm-svn: 237841
2015-05-20 22:10:50 +00:00
Reid Kleckner 5959176069 [lld] Use lit's shell to run tests on Windows by default
It's a lot faster than bash.

Also use FileCheck instead of grep to search through a binary file.
Cygwin's grep isn't working here for unknown reasons that probably
aren't worth investigating.

llvm-svn: 237834
2015-05-20 20:41:45 +00:00
Denis Protivensky 56b12d75bf [ARM] Add needed symbols during dynamic executable linking
These include _GLOBAL_OFFSET_TABLE_ and _DYNAMIC.

llvm-svn: 237791
2015-05-20 13:39:33 +00:00
Lang Hames 3d2911f5cd [LLD] Make sure MachO FDEs read their augmentation data strings from the right
CIE, not just the most recently encountered one.

llvm-svn: 237491
2015-05-16 00:08:02 +00:00
Lang Hames f7c163c986 [LLD] Properly relocate the LSDA field of MachO eh-frames.
Previously the LSDA field was not being relocated during linking, leading to
failures for some EH tests.

llvm-svn: 237222
2015-05-13 00:44:47 +00:00
Lang Hames 6483c00079 [LLD] Add support for MachO ripRel32MinusNAnon relocations.
llvm-svn: 237219
2015-05-13 00:29:43 +00:00
Lang Hames 9bbc3653c5 [LLD] Add a mutex to prevent concurrent modification of the dylib maps in
MachOLinkingContext.

llvm-svn: 237217
2015-05-13 00:17:08 +00:00
Davide Italiano d3142ec82b [ARM] Use the correct variable name and unbreak buildbot.
llvm-svn: 236880
2015-05-08 16:49:18 +00:00
Leny Kholodov bde4144338 [ARM] Generation of .ARM.exidx/.ARM.extab sections
This patch provides generation of .ARM.exidx & .ARM.extab sections which are
used for unwinding. The patch adds new content type typeARMExidx for atoms from
.ARM.exidx section and integration of atoms with such type to the ELF
ReaderWriter. exidx.test has been added with checking of contents of .ARM.exidx
section and .ARM.extab section.

Differential Revision: http://reviews.llvm.org/D9324

llvm-svn: 236873
2015-05-08 16:04:11 +00:00
Denis Protivensky 679c2c3639 [ARM] Check overflow of R_ARM_THM_JUMP11
llvm-svn: 236842
2015-05-08 12:45:11 +00:00
Denis Protivensky 73e927885c [ARM] Check overflow of R_ARM_CALL/JUMP24
llvm-svn: 236841
2015-05-08 12:36:40 +00:00
Denis Protivensky a0cffffcfa [ARM] Check overflow of R_ARM_THM_CALL/JUMP24
llvm-svn: 236839
2015-05-08 12:34:43 +00:00
Simon Atanasyan cb9547b941 [ELF] Initialize the _outputMagic class field using default value
No functional changes.

llvm-svn: 236823
2015-05-08 10:48:30 +00:00
Simon Atanasyan 668977f666 [Mips] Update test cases to reflect changes in the yaml2obj tool
No functional changes.

llvm-svn: 236742
2015-05-07 16:24:09 +00:00
Denis Protivensky 1a3bd31e52 [ARM] Check overflow of R_ARM_PREL31
llvm-svn: 236729
2015-05-07 14:05:30 +00:00
Denis Protivensky cf4e031b36 [ARM] llvm_unreachable => make_dynamic_error in R_ARM_BASE_PREL
llvm-svn: 236727
2015-05-07 13:44:51 +00:00
Denis Protivensky aaeba9ebb9 [ARM] llvm_unreachable => make_*_reloc_error in group relocs
llvm-svn: 236726
2015-05-07 13:41:44 +00:00
Denis Protivensky bc11ba4061 [ARM] Return directly from switch in relocation handler
llvm-svn: 236724
2015-05-07 13:12:11 +00:00
Denis Protivensky 9c3738ccef [ARM] Add return codes to relocation handlers
llvm-svn: 236723
2015-05-07 12:44:20 +00:00
Simon Atanasyan 1c55a071fd [Mips] Add more checkings to the test
No functional changes.

llvm-svn: 236391
2015-05-02 21:03:00 +00:00
Davide Italiano 06b21daf00 Revert unrelated chunk committed by accident in r236334.
The change is likely to be correct, but unrelated to the aforementioned
commit and needs a test to gets shipped. Sorry.

llvm-svn: 236336
2015-05-01 19:24:29 +00:00
Davide Italiano 9de946fa1f [ELF] Fix test for .init_array.
Change the test so that it tests the right functionality.
Also put a description with the code from which the test was generated.
Reported by Simon Atanasysan.

llvm-svn: 236334
2015-05-01 19:20:48 +00:00
Simon Atanasyan 097c21520e [Mips] Check creation of GOT entries corresponded to R_MIPS_REL32 relocations
No functional changes.

llvm-svn: 236314
2015-05-01 13:41:45 +00:00
Davide Italiano 312b15adb9 Change test target from x86_64-linux to x86_64.
llvm-svn: 236293
2015-05-01 00:36:41 +00:00
Davide Italiano 0e4a3addf0 [ELF] Mark linker defined symbols as .hidden when needed.
I noticed that gold mark these as hidden. While at it I rewrote the test for
this feature to use yaml rather than an object file as input.

Differential Revision:	http://reviews.llvm.org/D9418
Reviewed by:	ruiu

llvm-svn: 236291
2015-05-01 00:07:11 +00:00
Davide Italiano f14fbcbf91 [GNU] Remove -x/-X from the list of options to be implemented.
llvm-svn: 236149
2015-04-29 20:35:58 +00:00
Rafael Espindola ed48e53d60 Use MemoryBufferRef instead of MemoryBuffer&. NFC.
This just reduces the noise from another patch.

llvm-svn: 235933
2015-04-27 22:48:51 +00:00
Rui Ueyama 035025c0da Remove trailing whitespace characters.
llvm-svn: 235897
2015-04-27 17:18:04 +00:00
Rui Ueyama de9215e498 ELF: Simplify LinkerScript detection. NFC.
llvm-svn: 235895
2015-04-27 16:54:48 +00:00
Adhemerval Zanella d31aadf515 Add missing snippets from r235880
llvm-svn: 235890
2015-04-27 15:13:17 +00:00
Adhemerval Zanella 6bf4da02c1 ELF/ARM: Ignore R_ARM_V4BX for ARMv4 but allow linking
This patch allow the ARM relocation R_ARM_V4BX to be processed by lld,
although it is not really handled in the static relocation code.  The
relocation is in the form:

Relocation section '.rel.text' at offset 0x428 contains 4 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000014  00000028 R_ARM_V4BX

Meaning it does have a direct target, but rather references to an absolute
section *ABS* (in this exemple to the .text segment itself).  It makes the
target Atom after file parse to not have a associated pointer and thus
generating a derrefence NULL point in ELFFile<ELFT>::findAtom.  Current
approach is just ignore and return nullptr in such cases.

The problem relies that default GCC configuration
for arm-linux-gnueabi{hf} emits the relocation for the asm:

--
.syntax unified
.arm

.p2align 2
.type fn, %function
fn:
  ldr r3, .LGOT
  ldr r2, .LGOT+4
.LPIC:
  add r3, pc, r3
  ldr r2, [r3, r2]
  cmp r2, #0
  bxeq lr
  b __start__
.LGOT:
 .word _GLOBAL_OFFSET_TABLE_-(.LPIC+8)
 .word __start__(GOT)
--

But only with the option -march=armv4 (which is the default GCC configuration).
For arm5 and forward the relocation is not created. This a special relocation
(defined miscellaneous for ARM) that instruct the linker to replace the bx
instruction into a mov.  GNU linker has some options related to which substitution
it can create for such cases.

With this patch I can dynamically link an application against a GLIBC
arm-linux-gnueabi system configured with default GCC.

llvm-svn: 235880
2015-04-27 13:55:14 +00:00
Rafael Espindola 6759319c3c Use MemoryBufferRef instead of MemoryBuffer&. NFC.
This just reduces the noise from another patch.

llvm-svn: 235776
2015-04-24 21:10:50 +00:00
Rafael Espindola b597408da4 Simplify parseMemberFiles to take a single file.
llvm-svn: 235751
2015-04-24 19:08:51 +00:00
Rafael Espindola 773a159116 Simplify now that there is only one file. NFC.
llvm-svn: 235747
2015-04-24 19:01:30 +00:00
Rafael Espindola ab5696ba82 Return ErrorOr<std::unique_ptr<File>>. NFC.
llvm-svn: 235744
2015-04-24 18:51:30 +00:00
Rafael Espindola c1d535af05 Remove unused enum value. NFC.
llvm-svn: 235742
2015-04-24 18:36:57 +00:00
Rafael Espindola dedab912c3 Return an ErrorOr<std::unique_ptr<File>>. NFC.
llvm-svn: 235741
2015-04-24 18:33:50 +00:00
Davide Italiano 75e1172b19 [Test] Explictly pass target architecture.
If we're not being explicit, the test fails on windows.
Reported and tested by Aaron Ballman!

llvm-svn: 235739
2015-04-24 18:18:34 +00:00
Rafael Espindola c08ab8e6e4 Delete unnecessary generality in loadFile.
loadFile could load mulitple files just because yaml has a feature for
putting multiple documents in one file.

Designing a linker around what yaml can do seems like a bad idea to
me. This patch changes it to read a single file.

There are further improvements to be done to the api and they
will follow shortly.

llvm-svn: 235724
2015-04-24 15:51:45 +00:00
Simon Atanasyan e10a258527 [Mips] Simplify the code a bit using early return
No functional changes.

llvm-svn: 235708
2015-04-24 11:14:24 +00:00
Denis Protivensky 87d935dd09 [ARM] Update TODO notes
llvm-svn: 235706
2015-04-24 09:55:11 +00:00
Denis Protivensky c3431bf67b [ARM] Implement R_ARM_COPY relocation
This adds support of copying objects from shared libraries.

llvm-svn: 235705
2015-04-24 08:53:02 +00:00
Leny Kholodov 592cee666e [ARM] Update R_ARM_TARGET1 command line option names (remove prefix 'arm-')
Command line options --arm-target1-rel and --arm-target1-abs have been renamed to be compatible with GNU linkers.
Two tests have been updated:
  test/elf/options/target-specific-args.test
  test/elf/ARM/rel-arm-target1.test

Differential Revision: http://reviews.llvm.org/D9037

llvm-svn: 235499
2015-04-22 11:58:09 +00:00
Leny Kholodov 9e4292c0ec [ARM] Replace branches to undefined weak functions with NOP
According to the code model (ARM, Thumb, Thumb2) this patch updates the b/bl/blx 0 instructions with NOP.
test/elf/ARM/weak-branch.test has been added with tests for all available NOP (A1, T1, T2 encodings).

Differential Revision: http://reviews.llvm.org/D8807

llvm-svn: 235498
2015-04-22 11:47:53 +00:00
Simon Atanasyan 6668eb3c40 [Mips] Assign .MIPS.options section to the PT_LOAD segment
llvm-svn: 235488
2015-04-22 08:09:38 +00:00
Simon Atanasyan 5606dac67e [ELF] Allow TargetLayout descendants to control assignment sections to segments
The TargetLayout class puts two sections into the same segment if they
have equal segment types and the same section flags (SHF_xxx). To be
able to merge some sort of sections into the same segment we drop some
flags before comparison. For example to merge string sections into Data
segment we drop SHF_STRINGS and SHF_MERGE flags.

The patch allows TargetLayout descendants to drop some target specific
section flags. MIPS target needs that to merge .MIPS.options section
which has SHF_MIPS_NOSTRIP flag into the LOAD segment.

http://reviews.llvm.org/D9160

llvm-svn: 235487
2015-04-22 07:57:35 +00:00
Denis Protivensky 4b0abddeea [ARM] Implement veneers for dynamic executable linking
llvm-svn: 235486
2015-04-22 07:51:26 +00:00
Denis Protivensky f6c8938edd [ARM] Move veneer generators to base class. NFC
llvm-svn: 235485
2015-04-22 07:45:55 +00:00
Denis Protivensky 38b09f529c [ARM] Rename static veneer atoms to absolute code veneer atoms
No functional changes.

llvm-svn: 235484
2015-04-22 07:38:47 +00:00
Simon Atanasyan acd58af7df [ELF] Change return type of the OutputSection::flags() method
This method returns _flags field which has `uint64_t` type. Now the
field's type and the method's return type are consistent.

llvm-svn: 235393
2015-04-21 17:02:49 +00:00
Simon Atanasyan 72026b013b [ELF] Narrow down the type of OutputSection::_sections container
The `OutputSection::appendSection()` method always gets a pointer
to the `Section` class descendants. So it is not necessary to keep them
in the vector of `Chunk` pointers.

No functional changes.

llvm-svn: 235392
2015-04-21 17:02:42 +00:00
Simon Atanasyan fcb19e19d0 [Mips] Write .reginfo section into the separate PT_MIPS_REGINFO segment
llvm-svn: 235391
2015-04-21 17:02:35 +00:00
Simon Atanasyan d64f8a5188 [ELF] Simplify class memeber function declaration
No functional changes.

llvm-svn: 235390
2015-04-21 17:02:27 +00:00
Davide Italiano 037cfdd1db --discard-locals should be --discard-all here.
Sorry for the mistake/confusion.

llvm-svn: 235359
2015-04-20 22:54:50 +00:00
Davide Italiano 30326b9d8f [GNU/ELF] Add support for -X/--discard-locals.
There's (almost) never need to keep .L symbols around for production
builds. In fact, the FreeBSD kernel explicitly specify -X beacuse the
size impact (and the subsequent performance impact) might be significant,
because we keep symbols in memory.
I was tempted to make this the default, but I haven't (yet).

PR:		23232
llvm-svn: 235357
2015-04-20 22:52:56 +00:00
Simon Atanasyan 84adf3ff15 [Mips] Write DT_MIPS_OPTIONS tag to .dynamic section
If .MIPS.options section exists the DT_MIPS_OPTIONS tag should hold
an address of this section.

llvm-svn: 235290
2015-04-20 07:36:27 +00:00
Simon Atanasyan 8119228977 [Mips] Support R_MICROMIPS_PC18_S3/PC19_S2/PC21_S2/PC26_S2 relocations handling
llvm-svn: 235289
2015-04-20 07:34:52 +00:00
Simon Atanasyan 41ce98cc6f [Mips] Support R_MICROMIPS_GOT_DISP / PAGE / OFST relocations handling
llvm-svn: 235288
2015-04-20 07:33:02 +00:00
Davide Italiano 3d9e582a46 Accept --dynamic-linker <file>.
Before we only accepted --dynamic-linker=<file> and -dynamic-linker <file>
but older versions of GNU ld (e.g. 2.17.50) accept this other form, so
try to be compatible.

PR:		23233
llvm-svn: 235282
2015-04-19 23:45:41 +00:00
Davide Italiano 9a5b990f27 [GNU/ELF] Add support for -x/--discard-all.
PR:		23232
llvm-svn: 235247
2015-04-18 00:32:38 +00:00
Rui Ueyama e47aca8a6c Delete dead code (again).
llvm-svn: 235217
2015-04-17 18:58:34 +00:00
Rui Ueyama 3ff1170e5e Delete dead code.
llvm-svn: 235216
2015-04-17 18:54:29 +00:00
Rui Ueyama 1620a334ba Use C++11 non-static member initialization.
llvm-svn: 235187
2015-04-17 12:53:16 +00:00
Denis Protivensky 0575c5de68 [ARM] Implement R_ARM_TLS_IE32 for dynamic executable
llvm-svn: 235182
2015-04-17 11:30:29 +00:00
Denis Protivensky 3b5f7e9965 [ARM] Test R_ARM_TLS_LE32 for dynamic executable
llvm-svn: 235180
2015-04-17 11:24:11 +00:00
Simon Atanasyan 6313038925 [Mips] Make tests more tolerant to offsets, symbol sizes etc
No functional changes.

llvm-svn: 235035
2015-04-15 18:32:22 +00:00
Simon Atanasyan 09129d957c [Mips] clang-format the code
llvm-svn: 235033
2015-04-15 18:32:05 +00:00
Simon Atanasyan f4a87333ff [Mips] Remove redundant `.got` section lookup
No functional changes.

llvm-svn: 235032
2015-04-15 18:31:59 +00:00
Simon Atanasyan 834632cd1a [Mips] Create _GLOBAL_OFFSET_TABLE_ only if the .got section exists
llvm-svn: 235031
2015-04-15 18:31:53 +00:00
Simon Atanasyan fa21338a97 [Mips] Check `_gp_disp` symbol using a trivial string comparison
No functional changes.

llvm-svn: 235030
2015-04-15 18:31:44 +00:00
Adhemerval Zanella 17d33dc3ec ELF/Arch64: Fix testcases requirements
This patch fixes 2 aarch64 testcases that require dissassemble output
when running on builds that do not enable aarch64 backend.

llvm-svn: 235001
2015-04-15 12:03:42 +00:00
Denis Protivensky 0bcc491318 [ARM] Don't generate veneers when bl->blx fixup is possible
llvm-svn: 234991
2015-04-15 10:05:12 +00:00
Denis Protivensky 7f6b22ee84 [ARM] Pass Thumb flag to handler methods instead of atom
llvm-svn: 234989
2015-04-15 09:57:04 +00:00
Denis Protivensky 97375dc751 [ELF] Fix gcc -pedantic warnings (remove extra ';')
llvm-svn: 234981
2015-04-15 07:45:11 +00:00
Rui Ueyama bd94dbcf0a ELF: Attempt to simplify Segment::AssignVirtualAddress.
This is a retry of r234944.

llvm-svn: 234955
2015-04-14 23:11:14 +00:00
Rui Ueyama 13e41bcf9c temporary
llvm-svn: 234954
2015-04-14 23:11:12 +00:00
Rui Ueyama 0a57476c20 temporary
llvm-svn: 234953
2015-04-14 23:11:10 +00:00
Rui Ueyama ed796d518c ELF: Move Instrcution definition to HexagonEncoding.h.
HexagonEncodings.h contains a list of bitmasks. The file is used
only by HexagonRelocationHandler.cpp. The header is odd in the sense
that it uses struct Instruction but it doesn't define the data type.

This patch moves the struct definition to the header.

llvm-svn: 234947
2015-04-14 21:41:00 +00:00
Rui Ueyama ae9168b718 Revert "ELF: Attempt to simplify Segment::assignVirtualAddress()."
This reverts commit r234944 because it seems to have broken the buildbots.

llvm-svn: 234946
2015-04-14 21:38:39 +00:00
Rui Ueyama 5ec40d6e73 ELF: Attempt to simplify Segment::assignVirtualAddress().
This function is too long and complicated. Looks like new code was
added incrementaly without any refactoring. Maybe no one can describe
its exact semantics any more? It even contains copy-pastes inside it.

This patch is an (incomplete) attempt to simplify the function.
I tried to mechanically translate code to another form more intelligible.
I don't still understand the whole picture, but this patch shouldn't
change the linker's functionality.

llvm-svn: 234944
2015-04-14 21:20:37 +00:00
Davide Italiano b60453fe29 Rename ExecutableAtom.hpp to ExecutableAtom.h
This is for consistency with what's used elsewhere in lld tree.

llvm-svn: 234943
2015-04-14 21:06:56 +00:00
Rui Ueyama 921b8e93bb ELF: Remove redundant namespace qualifiers.
llvm-svn: 234938
2015-04-14 20:39:06 +00:00
Rui Ueyama 16d8e44da5 ELF: Simplify ELFDefinedAtom::contentType().
llvm-svn: 234936
2015-04-14 20:31:56 +00:00
Rui Ueyama 569e11af46 ELF: Split Atoms.h to Atoms.{h,cpp}.
llvm-svn: 234935
2015-04-14 20:21:53 +00:00
Rui Ueyama 2783469116 ELF: Split SegmentChunks.h to SegmentChunks.{h,cpp}.
llvm-svn: 234934
2015-04-14 20:12:50 +00:00
Rui Ueyama 06f70a087b ELF: Split HeaderChunks.h to HeaderChunks.{h,cpp}.
llvm-svn: 234932
2015-04-14 19:48:57 +00:00
Rui Ueyama befc11e007 ELF: Split SectionChunks.h to SectionChunks.{h,cpp}.
The size of AArch64TargetHander.cpp.o is now 4.1MB.

llvm-svn: 234931
2015-04-14 19:31:42 +00:00
Simon Atanasyan bdaab80160 [ELF] Use type helper Elf_Word instead of plain uint32_t data type
That helps to correctly write content of hash table if target and host
endianness are not the same. Right now that commit does not affect
any supported targets.

llvm-svn: 234928
2015-04-14 18:53:21 +00:00
Simon Atanasyan 1bd5d7e623 [ELF] Write whole std::vector using a single `memcpy` call
We do not need to iterate over `_buckets` and `_chains` vectors and
write all elements one by one.

No functional changes.

llvm-svn: 234927
2015-04-14 18:53:14 +00:00
Simon Atanasyan c0c4664618 [ELF] Remove redundant type cast to `char*` before passing array to memcpy
No functional changes.

llvm-svn: 234926
2015-04-14 18:53:09 +00:00
Simon Atanasyan 23025c812e [Mips] Write _DYNAMIC symbol on MIPS targets
llvm-svn: 234925
2015-04-14 18:53:03 +00:00
Simon Atanasyan dd6f1aaa73 [Mips] Make tests more tolerant to the program and section headers offsets
No functional changes.

llvm-svn: 234924
2015-04-14 18:52:55 +00:00
Rui Ueyama a852744a6a ELF: Split OutputELFWriter.h to OutputELFWriter.{h,cpp}.
The size of AArch64TargetHandler.cpp.o is now 4.5MB.

llvm-svn: 234916
2015-04-14 18:14:07 +00:00
Rui Ueyama 9d6ca7e272 ELF: Split TargetLayout.h into TargetLayout.{h,cpp}.
This patch makes AArch64TargetHandler.cpp.o from 8.5MB to 6.8MB.

llvm-svn: 234914
2015-04-14 18:04:57 +00:00
Rui Ueyama cfeb2512fd ELF: Remove ELFT template argument when referring the base class.
We don't need to repeat the template argument. They are not
ambiguous. MIPS is parameterized for ELFT, so we can't do this
for MIPS, though.

llvm-svn: 234913
2015-04-14 17:32:13 +00:00
Rui Ueyama 5557a0e688 Attempt to fix MSVC warning.
This patch tries to fix the following MSVC warning.

  warning C4661: 'bool
  lld:🧝:ELFFile<lld:🧝:ELF32LE>::isCompatible(unsigned
  char,unsigned char)' : no suitable definition provided for explicit
  template instantiation request

llvm-svn: 234909
2015-04-14 17:12:32 +00:00
Denis Protivensky 8f82dff193 [ARM] Implement mapping symbols for PLT0 entry
llvm-svn: 234876
2015-04-14 09:33:04 +00:00
Denis Protivensky 72a7581743 [ARM] Move out mapping atom functionality to a separate class
llvm-svn: 234874
2015-04-14 09:11:05 +00:00
Denis Protivensky e80fd18b45 [ARM] Rename IFUNC-related tests
llvm-svn: 234873
2015-04-14 08:44:55 +00:00
Denis Protivensky 4c895b189a [ARM] Improve IFUNC PLT test
llvm-svn: 234872
2015-04-14 08:40:02 +00:00
Rui Ueyama ff499469e0 Simplify short switch-cases.
llvm-svn: 234869
2015-04-14 07:19:29 +00:00
Rui Ueyama 707504e0f2 Remove excessive parentheses.
llvm-svn: 234868
2015-04-14 07:09:05 +00:00
Rui Ueyama bf138134b0 ELF: Remove a header which is used only by one .cpp file.
The data and the inline function defined in the header is used only
by HexagonRelocationHandler.cpp.

llvm-svn: 234867
2015-04-14 07:09:03 +00:00
Rui Ueyama 92259f7fa3 Fix indentation.
llvm-svn: 234866
2015-04-14 06:58:48 +00:00
Rui Ueyama 76dff95a98 ELF: Fix odd initialization code.
llvm-svn: 234865
2015-04-14 06:58:47 +00:00
Rui Ueyama 25f9b4b752 temporary
llvm-svn: 234864
2015-04-14 06:58:45 +00:00
Rui Ueyama f9fffa7e11 ELF: Move function definitions from .h to .cpp.
llvm-svn: 234863
2015-04-14 06:47:06 +00:00
Rui Ueyama 2f43dbec0a ELF: Inline ELFReader typedefs which are used only once.
llvm-svn: 234862
2015-04-14 06:22:53 +00:00
Rui Ueyama f3691620da ELF: Make common strings file-scoped constants.
llvm-svn: 234861
2015-04-14 06:08:07 +00:00
Rui Ueyama f505ccf451 ELF: Make ARMELFMappingAtom a non-template class.
llvm-svn: 234860
2015-04-14 05:21:26 +00:00
Rui Ueyama da3a9a1b0b ELF: Remove this-> as much as we can.
These this-> are there because their classes were templated.
They are no longer templated.

llvm-svn: 234859
2015-04-14 05:14:49 +00:00
Rui Ueyama 4caff31217 ELF: Remove ELFT parameter from ARMELFFile.
llvm-svn: 234858
2015-04-14 05:14:46 +00:00
Rui Ueyama ff8bc5680a ELF: Make HexagonFile a non-template class.
llvm-svn: 234857
2015-04-14 05:14:44 +00:00
Rui Ueyama 3996563428 Remove dead code.
llvm-svn: 234854
2015-04-14 04:54:01 +00:00
Rui Ueyama 7bda84d25e ELF: Remove ELFT and LinkingContext template parameters from ELFReader.
Previously, ELFReader takes three template arguments: EFLT,
LinkingContextT and FileT. FileT is itself templated.
So it was a bit complicated. Maybe too much.

Most architectures don't actually need to be parameterized for ELFT.
For example, x86 is always ELF32LE and x86-64 is ELF64LE.
However, because ELFReader requires a ELFT argument, we needed
to parameterize a class even if not needed.

This patch removes the parameter from the class. So now we can
de-templatize such classes (I didn't do that in this patch, though).

This patch also removes ContextT parameter since it didn't have to be
passed as a template argument.

llvm-svn: 234853
2015-04-14 04:53:57 +00:00
Rui Ueyama e75e50c045 Define make_dynamic_error_code(const char *).
The function took either StringRef or Twine. Since string literals are
ambiguous when resolving the overloading, many code calls used this
function with explicit type conversion. That led awkward code like
make_dynamic_error_code(Twine("Error occurred")).

This patch adds a function definition for string literals, so that
you can directly call the function with literals.

llvm-svn: 234841
2015-04-14 02:34:09 +00:00
Rui Ueyama 18783cea3f ELF: Remove almost empty class.
llvm-svn: 234834
2015-04-14 01:15:43 +00:00
Rui Ueyama 97d30b87f3 Remove unused variable.
llvm-svn: 234831
2015-04-14 01:10:19 +00:00
Rui Ueyama a5b6859ac4 ELF: Use less templates for ELF types.
These classes are templated but actually instantiated for only
one ELF type.

llvm-svn: 234830
2015-04-14 00:59:04 +00:00
Rui Ueyama ad87e54f1a ELF: Define ELF{32,64}{LE,BE} types and use them everywhere.
llvm-svn: 234823
2015-04-14 00:31:28 +00:00
Rui Ueyama d610a96d15 ELF: Remove useless templates that takes always the same ELF type.
llvm-svn: 234820
2015-04-14 00:08:09 +00:00
Rui Ueyama 243226852f ELF: Fix headers including each other.
HexagonSectionChunks.h and HexagonTargetHandler.h include each other.
This patch removes the former and merge it with the latter.

llvm-svn: 234817
2015-04-13 23:47:53 +00:00
Rui Ueyama 4bd8ece689 ELF: Move definitions from {Dynamic,ELF}File.h to .cpp files.
DynamicFile and ELFFile are instantiated for four different types,
ELF{32,64}{BE,LE}. Because the classes are instantiated in each
compilation unit, including the header file makes object files
10MB larger.

On Windows, issue of excessive template instantiation is critical,
since the regular COFF file supports only up to 65534 sections.
(We could use the extended COFF file format, but generating that
much COMDAT sections is not a good thing in the first place
because it means long compile time and long link time.)

I confirmed that this change makes AArch64TargetHandler.cpp.o
from 21MB to 8.5MB. It feels still too large, but I think it's
a good start.

llvm-svn: 234808
2015-04-13 22:52:11 +00:00
Rui Ueyama fa92b4c9d8 ELF: Simplify alignment check. NFC.
llvm-svn: 234791
2015-04-13 20:04:50 +00:00
Rui Ueyama cfba8b3481 ELF: s/ELFTy/ELFT/ for consistency.
llvm-svn: 234790
2015-04-13 20:04:48 +00:00
Rui Ueyama 3245a395c1 Remove else after return.
llvm-svn: 234784
2015-04-13 19:56:08 +00:00
Rui Ueyama 09dfd2544e Fix formatting and remove excessive parentheses.
llvm-svn: 234781
2015-04-13 19:24:00 +00:00
Simon Atanasyan 44e904581d [Mips] Rollback explicit instantiation of MipsELFFile template class
This is a follow-up to r234728 and r234729. It looks like explicit
instantiation of `MipsELFFile` is redundant and triggers Visual C++ warning.

llvm-svn: 234756
2015-04-13 15:32:42 +00:00