Commit Graph

3293 Commits

Author SHA1 Message Date
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