Commit Graph

1394 Commits

Author SHA1 Message Date
Rafael Espindola 3efa4e982e Add a token ppc64 reloc just to have a test showing that we handle BE.
llvm-svn: 248321
2015-09-22 21:12:55 +00:00
Rafael Espindola 01205f79a4 Start adding target abstractions.
This is just enough to get PLT working on 32 bit x86.

The idea behind using a virtual interface is that it should be easy to
convert any of the functions to template parameters if any turns out to be
performance critical.

llvm-svn: 248308
2015-09-22 18:19:46 +00:00
Rafael Espindola 50534c2b6f Fix the creation of Elf_Rel sections.
We were always incrementing the output buffer pointer by sizeof(Elf_Rela).

llvm-svn: 248303
2015-09-22 17:49:38 +00:00
Davide Italiano 25423d42bd [MachO] Use llvm-readobj in lieu of macho-dump.
The latter will be removed from the tree anytime soon.

llvm-svn: 248300
2015-09-22 17:31:01 +00:00
Rafael Espindola a794fd44a1 Add support for R_386_PC32.
llvm-svn: 248275
2015-09-22 13:47:45 +00:00
Rafael Espindola 21585757e6 Handle implicit addends in Elf_Rel.
llvm-svn: 248272
2015-09-22 13:35:00 +00:00
Rui Ueyama 9640173e16 COFF: Add /nosymtab command line option.
This is an LLD extension to MSVC link.exe command line. MSVC linker
does not write symbol tables for executables. We do unless no /debug
option is given.

There's a situation that we want to enable debug info but don't want
to emit the symbol table. One example is when we are comparing output
file size. With this patch, you can tell the linker to not create
a symbol table by just specifying /nosymtab.

llvm-svn: 248225
2015-09-21 23:43:31 +00:00
Lang Hames c803442890 [LLD][MachO] Fix a FIXME: Subtract base address from atom address when building
export trie.

llvm-svn: 248217
2015-09-21 22:06:02 +00:00
Davide Italiano 8ca741d51d [ELF2] Support relocs for local symbols
Differential Revision:	 http://reviews.llvm.org/D12978

llvm-svn: 248196
2015-09-21 19:30:11 +00:00
Rafael Espindola eb79273158 Start adding support for PLT.
For now this doesn't support lazy symbol resolution, but is enough to link
and run a program with

jmp foo@PLT

llvm-svn: 248165
2015-09-21 15:11:29 +00:00
Davide Italiano 5445b2de50 [ELF2] Implement support for -discard-locals.
This is not on by default, but it may make sense to change it in future.

llvm-svn: 248133
2015-09-20 21:58:12 +00:00
Rui Ueyama 5f38915624 COFF: Fix ICF regression.
This patch fixes a regression introduced by r247964. Relocations that
are referring the same symbol should be considered equal, but they
were not if they were pointing to non-section chunks.

llvm-svn: 248132
2015-09-20 20:19:12 +00:00
Michael J. Spencer acf5bdfd88 [elf2] Improve relocation-undefined-weak.s test.
llvm-svn: 248071
2015-09-19 00:15:38 +00:00
Michael J. Spencer 9779535c5d [elf2] Relocate against undefined weak symbols.
llvm-svn: 248056
2015-09-18 22:26:13 +00:00
Michael J. Spencer 658dccd1c8 [elf2] Relocate against common symbols.
llvm-svn: 248054
2015-09-18 22:13:25 +00:00
Rafael Espindola 5c2310c30c Start adding support for creating the GOT.
With this a program can call into a shared library with

  jmp *foo@GOTPCREL(%rip)

llvm-svn: 247992
2015-09-18 14:40:19 +00:00
Davide Italiano b5b47b432b [ELF2] Fill up local symbols fields correctly.
Differential Revision:	http://reviews.llvm.org/D12944

llvm-svn: 247960
2015-09-18 01:08:17 +00:00
Michael J. Spencer 879b597b9d [elf2] Extend program-header-layout.s to check that read only sections are correctly merged into the first PT_LOAD.
llvm-svn: 247947
2015-09-17 21:19:56 +00:00
Michael J. Spencer 55f56320c7 [elf2] Fix dynamic-reloc.s test.
The offset of the .rela.dyn section isn't the same between hosts because a path comes before it. This test doesn't care what the offset is.

llvm-svn: 247946
2015-09-17 21:13:41 +00:00
Michael J. Spencer 2f0082424f [elf2] Combine adjacent compatible OutputSections in PT_LOADs.
llvm-svn: 247925
2015-09-17 19:58:07 +00:00
Rafael Espindola 40102eb27f Use a MapVector to output symbols in a deterministic order.
We used to sort the symbols at the very end, but we need to know the order
earlier so that we can create reference to them in the dynamic relocations.

Thanks to Igor Kudrin for pointing out the problem.

llvm-svn: 247911
2015-09-17 18:26:25 +00:00
Rafael Espindola 67a5da60ed Add support of Elf_Rel dynamic relocations.
llvm-svn: 247888
2015-09-17 14:02:10 +00:00
Rafael Espindola eade07ba59 Start adding support for Elf_Rel.
I don't intend to add full i686 support right now, just make sure we have all
the infrastructure in place for it.

llvm-svn: 247858
2015-09-16 21:57:07 +00:00
Rui Ueyama 4dbff20c91 COFF: Fix bug that not all symbols were written to symtab if /opt:noref.
Only live symbols are written to the symbol table. Because isLive()
returned false if dead-stripping was disabled entirely, only
non-COMDAT sections were written to the symbol table. This patch fixes
the issue.

llvm-svn: 247856
2015-09-16 21:40:47 +00:00
Rui Ueyama 3b153e6541 COFF: Fix bug that /opt:noicf was ignored.
llvm-svn: 247854
2015-09-16 21:30:55 +00:00
Davide Italiano 6d328d3841 [ELF2] Initial support for local symbols.
Symbol table is now populated correctly, but some fields are missing,
they'll be added in the future. This patch also adds --discard-all
flag, which was the default behavior until now.

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

llvm-svn: 247849
2015-09-16 20:45:57 +00:00
Rafael Espindola 6569522f4b Relax the test to fix some bots.
The string table contains a file path, so addresses and offsets can be
different on some setups.

llvm-svn: 247839
2015-09-16 19:48:57 +00:00
Rafael Espindola 2b92d8f184 Move code computing NumEntries to finalize.
When DynamicSection is constructed we still don't know if there will be
any dynamic relocations or not.

llvm-svn: 247838
2015-09-16 19:26:31 +00:00
Rafael Espindola 3887ebfc21 Add DT_RELA and DT_RELASZ to the dynamic table.
llvm-svn: 247837
2015-09-16 18:52:42 +00:00
Rui Ueyama b02a320f5e COFF: Enable ICF by default.
MSVC linker enables ICF as long as /opt:ref is eanbled, so do we.

llvm-svn: 247817
2015-09-16 16:41:38 +00:00
Rui Ueyama c04d5dbf20 COFF: Rename /opt:lldicf -> /opt:icf.
Now that ICF is complete, we can rename this option so that
the driver accepts the MSVC-compatible command line option.

llvm-svn: 247816
2015-09-16 16:33:57 +00:00
Rafael Espindola 19e3889dba Start creating dynamic relocations.
For now we don't create got/plt and only Elf_Rela is supported.

llvm-svn: 247811
2015-09-16 15:54:15 +00:00
Simon Atanasyan 92480f9a20 [Mips] Rejects all --hash-style arguments except 'sysv' in case of MIPS target
MIPS ABI supports only --hash-style=sysv variant.

llvm-svn: 247796
2015-09-16 13:36:32 +00:00
Simon Atanasyan 49c67236f1 [Mips] Do not show an error if R_MIPS_GPREL32 relocation has a non-local target
This matches GNU linker behaviour.

llvm-svn: 247795
2015-09-16 13:36:24 +00:00
Rafael Espindola 72373fb5b7 Fix test to actually test something.
llvm-svn: 247790
2015-09-16 12:50:32 +00:00
Rui Ueyama 9cb2870ce0 ICF: Improve ICF to reduce more sections than before.
This is a patch to make LLD to be on par with MSVC in terms of ICF
effectiveness. MSVC produces a 27.14MB executable when linking LLD.
LLD previously produced a 27.61MB when self-linking. Now the size
is reduced to 27.11MB. Note that without ICF the size is 29.63MB.

In r247387, I implemented an algorithm that handles section graphs
as cyclic graphs and merge them using SCC. The algorithm did not
always work as intended as I demonstrated in r247721. The new
algortihm implemented in this patch is different from the previous
one. If you are interested the details, you want to read the file
comment of ICF.cpp.

llvm-svn: 247770
2015-09-16 03:26:31 +00:00
Michael J. Spencer 141dd91ac5 [elf2] Simplify overflow checks.
llvm-svn: 247768
2015-09-16 02:02:04 +00:00
Michael J. Spencer 75e5fda3de [elf2] Add R_X86_64_32S.
llvm-svn: 247758
2015-09-16 00:24:19 +00:00
Michael J. Spencer dff84070da [elf2] Add error checking for the R_X86_64_32 relocation.
llvm-svn: 247745
2015-09-15 23:36:30 +00:00
Michael J. Spencer 3c1ac0a17a [elf2] Relocate absolute symbols.
llvm-svn: 247738
2015-09-15 23:12:02 +00:00
Rui Ueyama c26bbfe6b6 COFF: Add a test for ICF which LLD cannot handle yet.
In this test, we have two functions, foo and bar. MSVC linker can
choose one and discard the other using ICF. LLD cannot. I add this
test as a TODO.

foo and bar are conceptually equivalent to the following:

  void foo() { foo(); }
  void bar() { foo(); }

foo and bar are effectively the same function. If foo and bar are
compiled to the same instructions, both their contents (foo and bar)
and relocation targets (foo) become the same, so from the ICF point
of view, they are reducible. But their graphs are not isomorphic!
LLD's ICF algorithm cannot handle this case yet.

llvm-svn: 247721
2015-09-15 21:17:12 +00:00
Rafael Espindola a5c97d9025 Add support for R_X86_64_64.
llvm-svn: 247688
2015-09-15 13:52:06 +00:00
Rafael Espindola d1062bbd89 Make this test a bit more robust in preparation to adding more cases.
The first test (call) is now the only test to use .text, which makes it
resistant to more tests being added.

llvm-objdump -d already prints the addresses of symbols. We can use that in the
tests.

llvm-svn: 247685
2015-09-15 13:30:08 +00:00
Rafael Espindola 80faee82e6 Add content to the .hash section.
This also sets DT_HASH.

With this simple shared libraries created by lld can be loaded by the dynamic
linker.

llvm-svn: 247625
2015-09-14 22:08:55 +00:00
Rafael Espindola 601771ebc0 Start adding the .hash output section.
It is still empty. Content will be added in the next patch.

llvm-svn: 247609
2015-09-14 20:20:34 +00:00
Rafael Espindola bfcdfb32af Correctly align sections.
We have to align the start, not the end.

This should fix crashes on systems where memcpy enforces the expected
alignment.

llvm-svn: 247599
2015-09-14 19:00:35 +00:00
Rui Ueyama 8e186df2f5 COFF: Corrected error message if a section failed to load.
There is no sense to use Name in these lines as it is not initialized yet.

Patch from Igor Kudrin!

llvm-svn: 247531
2015-09-13 20:22:22 +00:00
Rafael Espindola 4340aad144 Start adding support for creating shared libraries.
They are not fully functional yet, but this implements enough support for lld
itself to read them.

With that, delete the .so binary we were using for tests and start eating our
own dog food.

llvm-svn: 247487
2015-09-11 22:42:45 +00:00
Rafael Espindola 1d12ab3db1 Fix handling of _start being undefined.
We were crashing before.

llvm-svn: 247481
2015-09-11 21:44:55 +00:00
Rafael Espindola 2e9eac13c7 Implement -rpath.
llvm-svn: 247475
2015-09-11 21:18:56 +00:00