Commit Graph

6442 Commits

Author SHA1 Message Date
George Rimar 28ac19c9ee [ELF] - Linkerscript: do not define _edata,_end,_etext if SECTIONS is used.
I faced that when tried to link FreeBSD kernel. 
It was "duplicate symbol: _edata in (internal) and (internal)" error.
_data was a shared symbol that came from hack.so. At first it was replaced with DefinedRegular by the code
disabled in this patch and later when script tried to define the same symbol - the error was shown.

In the same situation (as given in testcase) ld defines them as UND. gold defines as ABS with zero value. 
Patch just disables any operations of creating these symbols if script do layout.

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

llvm-svn: 277986
2016-08-08 08:42:48 +00:00
Saleem Abdulrasool 45a574130e COFF ARM: Fix typos in the relocation test
Fix comments.  NFC.

Patch by Martin Storsjö!

llvm-svn: 277929
2016-08-06 18:02:51 +00:00
Benjamin Kramer df8f196f9a Unpollute the global namespace. lld edition.
llvm-svn: 277926
2016-08-06 13:52:37 +00:00
Simon Atanasyan 24c24fedba [ELF][MIPS] Produce a correct and complete set of MIPS ELF header flags
The patch extends the `getMipsEFlags` function. Now in that function
we iterate over all object files, parse ELF header flags and merge them.
If a file is incompatible with previously analyzed ones we show an error
or warning. That can happen if, for example, we try to link files with
incompatible ABI, ISA, NAN encoding etc.

There is an alternative solution. We can check and merge flags and
reject incompatible input modules in the `isCompatible` function which
is called from the `SymbolTable::addFile` method. But in that case we
have to save and keep somewhere a merged ELF flags combination to use it
later in the writer.

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

llvm-svn: 277911
2016-08-06 05:11:41 +00:00
Pete Cooper d0de3683ec ExportTrie nodes need to be visisted in order.
The export trie was being emitted in the order the nodes were
added to the vector, but instead needs to be visited in the order
that the nodes are traversed.  This matches the behaviour of ld64.

llvm-svn: 277869
2016-08-05 21:37:12 +00:00
Saleem Abdulrasool fd063e796f COFF ARM: Apply an existing offset in MOV32T relocations
Don't blindly OR in the new value, but clear the existing one, since it can be
nonzero. Read out the existing value before, and add into the desired offset.
(The add is done outside of the applyMOV, to handle potential overflow between
the two.)

Patch by Martin Storsjö!

llvm-svn: 277846
2016-08-05 18:20:31 +00:00
Saleem Abdulrasool eea45bc478 COFF ARM: Error out if 24 bit thumb branches are out of range
In the ELF linker, the same situation already errors out with "relocation
R_ARM_THM_CALL out of range".

Patch by Martin Storsjö!

llvm-svn: 277838
2016-08-05 17:33:24 +00:00
Saleem Abdulrasool 8202c6dbdf COFF ARM: Clear the J1 and J2 bits when applying relocations to 24 bit branches
The opcode for the bl branches can initially be F000 F800, i.e.
the J1 and J2 bits are already set. Therefore mask these bits out
before or'ing in the new bits.

Patch by Martin Storsjö!

llvm-svn: 277836
2016-08-05 17:28:21 +00:00
Rui Ueyama a2acc93140 Simplify. NFC.
llvm-svn: 277794
2016-08-05 01:25:45 +00:00
Rui Ueyama 808d13ea49 Move invariants outside of a lambda. NFC.
llvm-svn: 277791
2016-08-05 01:05:01 +00:00
Rui Ueyama 36c1cd235a Make combine() non-member function.
Because this function depends only on its arguments.

llvm-svn: 277790
2016-08-05 01:04:59 +00:00
Rui Ueyama 742c38361b Split InputSectionDescription::Sort into SortInner and SortOuter.
Summary:
The comparator function to compare input sections as instructed by
SORT command was a bit too complicated because it needed to handle
four different cases. This patch split it into two function calls.

This patch also simplifies the parser.

Reviewers: grimar

Subscribers: llvm-commits

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

llvm-svn: 277780
2016-08-04 22:27:00 +00:00
Rui Ueyama bdade36769 Use "llvm-objdump -s" instead of hexdump command.
llvm-svn: 277771
2016-08-04 21:23:30 +00:00
Davide Italiano d62d116add [MachO] Factor out some common code in the Driver.
llvm-svn: 277761
2016-08-04 19:56:26 +00:00
Davide Italiano 6bb5d2ddd3 [MachO/Core] Remove (now) unused static member function. NFCI.
llvm-svn: 277760
2016-08-04 19:49:11 +00:00
Rafael Espindola a4b41dca31 Remove redundant argument.
But always set Script<ELFT>::X->OutputSections.

llvm-svn: 277720
2016-08-04 12:13:05 +00:00
George Rimar 54a5486918 [ELF] - Attemp to fix buildbot.
http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/25733/steps/test_lld/logs/stdio

Fix: removed excessive whitespace.
llvm-svn: 277711
2016-08-04 09:49:26 +00:00
George Rimar eefa758ee2 [ELF] - Linkerscript: implemented ASSERT() keyword.
ASSERT(exp, message)
Ensure that exp is non-zero. If it is zero, then exit the linker with an error
code, and print message.

ASSERT is useful and was seen in few projects in the wild.

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

llvm-svn: 277710
2016-08-04 09:29:31 +00:00
George Rimar 9e5386ceae [ELF] - Linkerscript: Fixed SORT_BY_ALIGNMENT sorting order.
According to spec:
"SORT_BY_ALIGNMENT will sort sections into descending order by 
alignment before placing them in the output file"

Previously they were sorted into ascending order.

llvm-svn: 277706
2016-08-04 08:56:17 +00:00
George Rimar b32733423f [ELF] - Remove trailing whitespaces. NFC.
llvm-svn: 277705
2016-08-04 08:26:02 +00:00
Eugene Leviant c7611fc567 [ELF] Linkerscript: remove repeated sections in filter()
llvm-svn: 277703
2016-08-04 08:20:23 +00:00
Rui Ueyama c163318b21 Remove buggy PROVIDE-in-output-description command.
With the previous change, it is now obvious that readProvide in
this context appended new commands to a wrong command list.
It was mistakenly adding new commands to the top level.
Thus, all commands inside output section descriptions were
interpreted as they were written on top level.

PROVIDE command naturally requires symbol assignment support
in the output section description. We don't have that one yet.
I removed the implementation because there's no way to fix it now.
We can resurrect the test once we support the symbol assignment
(with a modification to detect errors that we failed to find as
described.)

llvm-svn: 277687
2016-08-04 02:03:29 +00:00
Rui Ueyama 104165643e Make ScriptParser::read* functions more functional style.
Previously, many read* functions created new command objects and
add them directly to the top-level data structure. This is not
work for some commands because some commands, such as the assignment,
can appear inside and outside of the output section description.

This patch is to not append objects to the top-level data structure.
Callers are now responsible to do that.

llvm-svn: 277686
2016-08-04 02:03:27 +00:00
Rui Ueyama 965827d674 Make filler expression compatible with gold.
Previously, a decimal filler expression is interpreted as a byte value.
Gold on the other hand use it as a 32-bit big-endian value.
This patch fixes the compatibility issue.

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

llvm-svn: 277680
2016-08-03 23:25:15 +00:00
Kevin Enderby 0fa9fd0f28 Needed change to lld for the changes to libObject/Archive interfaces now returning Expected<>
for the llvm trunk change in r277656

llvm-svn: 277657
2016-08-03 21:58:48 +00:00
Rui Ueyama e7f912cd8f Create only one vector instead of two.
In this for-loop, we append elements from one vector to another,
which is a bit inefficient.

llvm-svn: 277653
2016-08-03 21:12:09 +00:00
Rui Ueyama 803568866c Rename functions that handle bitcode files.
getELFKind was overloaded with bitcode files and regular object files,
and I found that is a bit confusing. This patch renames them.

llvm-svn: 277646
2016-08-03 20:33:17 +00:00
Rui Ueyama 7fdb4389a2 Do not instantiate Triple twice.
Also removes redundant variables. NFC.

llvm-svn: 277644
2016-08-03 20:25:29 +00:00
Rui Ueyama 6c50990df6 Add EM_IAMCU support.
This patch adds "-m elf_iamcu" to ldd for IAMCU psABI:
https://github.com/hjl-tools/x86-psABI/wiki/X86-psABI

Patch by H.J Lu.

llvm-svn: 277643
2016-08-03 20:15:56 +00:00
Nico Weber 204f7dc56e lld-link: Include the name of bad input files in several "input file is bad" diagnostics.
Also change a few getName() calls to getShortName() calls.
https://reviews.llvm.org/D23123
Part of PR28553.

llvm-svn: 277616
2016-08-03 18:07:28 +00:00
Nico Weber c9d9b31ba7 Revert an unintentional change from r277599
llvm-svn: 277600
2016-08-03 14:38:52 +00:00
Nico Weber 2e36772caf Revert 277594, it caused PR28827
llvm-svn: 277599
2016-08-03 14:37:57 +00:00
Rafael Espindola a348532ec3 Remove redundant argument.
llvm-svn: 277594
2016-08-03 13:21:16 +00:00
George Rimar 350ece4efb [ELF] - Linkerscript: support all kinds of sorting (including nested).
Previously we supported only sorting by name.

When there are nested section sorting commands in linker script, there can be at most 1
level of nesting for section sorting commands.

SORT_BY_NAME (SORT_BY_ALIGNMENT (wildcard section pattern)). It will sort the input
sections by name first, then by alignment if 2 sections have the same name.

SORT_BY_ALIGNMENT (SORT_BY_NAME (wildcard section pattern)). It will sort the input
sections by alignment first, then by name if 2 sections have the same alignment.

SORT_BY_NAME (SORT_BY_NAME (wildcard section pattern)) is treated the same as SORT_
BY_NAME (wildcard section pattern).

SORT_BY_ALIGNMENT (SORT_BY_ALIGNMENT (wildcard section pattern)) is treated the
same as SORT_BY_ALIGNMENT (wildcard section pattern).

All other nested section sorting commands are invalid.

Patch implements that all above.

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

llvm-svn: 277583
2016-08-03 08:35:59 +00:00
Rui Ueyama 3ebc71eb91 Do not handle zero-sized mergeable section as mergeable.
Mergeable sections with size zero are useless because they don't
actually contain data, and therefore there's no merit ot merge them.
However, in reality, there are object files in the wild containing
such sections. Currently, LLD can't handle them proerply.

This patch makes LLD to handle such sections as if they are non-
mergeable to fix the issue.

Fixes bug 28822.

llvm-svn: 277568
2016-08-03 05:28:02 +00:00
Rui Ueyama d6bd1371fc Include filenames and section names to error messages.
llvm-svn: 277566
2016-08-03 04:39:42 +00:00
Rafael Espindola eb685cd798 Support expressions inside FLAGS.
This is an undocumented bfd feature. It is reasonable for making the
scripts a bit more readable.

llvm-svn: 277532
2016-08-02 22:14:57 +00:00
Davide Italiano a9210ef4f5 [ELF] Ignore -g option for compatibility.
Also ld.bfd and ld.gold ignore this options. I hit this one in
the wild, and just ignoring it's trivial, so, let's do it.

llvm-svn: 277531
2016-08-02 22:14:00 +00:00
George Rimar 7b360f2441 [ELF] - Fix: do not ignore relocations addends when using lld -r
Previously addends were ignored. This is PR28779.
Patch fixes the issue.

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

llvm-svn: 277432
2016-08-02 08:49:57 +00:00
Rui Ueyama 0778490428 Remove DefinedCommon::Section.
Since CommonInputSection is a singleton class, we don't need
to store pointers to all DefinedCommon symbols.

llvm-svn: 277410
2016-08-02 01:35:13 +00:00
Davide Italiano 38115ffcef [ELF/ARM] Add support for R_ARM_TARGET1 relocation.
Differential Revision:  https://reviews.llvm.org/D22990

llvm-svn: 277369
2016-08-01 19:28:13 +00:00
Rui Ueyama 400fc1af43 Remove dead ctor.
llvm-svn: 277255
2016-07-30 00:13:30 +00:00
Rui Ueyama 3a5be750bb Remove trailing whitespace.
llvm-svn: 277253
2016-07-29 23:48:09 +00:00
Davide Italiano 5ac0d7c5ad [LinkerScript] Filler can have a decimal value.
llvm-svn: 277222
2016-07-29 22:21:28 +00:00
Lang Hames 70c80b336b [lld][MachO] Replace some std::string with char* buffers to eliminate mem leaks.
The MachO debug support code (committed in r276935) occasionally needs to
allocate string copies, and was doing so by creating std::strings on a
BumpPtrAllocator. The strings were untracked, so the destructors weren't being
run and we were leaking the memory when the allocator was thrown away. Since
it's easier than tracking the strings, this patch switches the copies to char
buffers allocated directly in the bump-ptr allocator.

llvm-svn: 277208
2016-07-29 20:04:18 +00:00
Rafael Espindola 716a94787c Don't crash if PT_TLS is empty.
llvm-svn: 277202
2016-07-29 19:24:27 +00:00
Kevin Enderby 01e41f11a7 Matching change needed to lld for llvm trunk change r277177.
Where Archive::getMemoryBufferRef() was changed to return Expected<>

llvm-svn: 277183
2016-07-29 17:56:00 +00:00
George Rimar 9e69450ec7 [ELF] - Linkerscript: implemented SIZEOF(section)
SIZEOF(section)
Return the size in bytes of the named section, if that section has been allocated.

SIZEOF(section) often used in scripts. Few examples from the wild:
https://github.com/chipKIT32/pic32-Arduino-USB-Bootloader-original/blob/master/boot-linkerscript.ld
https://github.com/devkitPro/buildscripts/blob/master/dkarm-eabi/crtls/gba_cart.ld

Patch implements it.

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

llvm-svn: 277165
2016-07-29 16:18:47 +00:00
Rui Ueyama 1acefcd11e Remove dead declaration.
llvm-svn: 277159
2016-07-29 16:08:04 +00:00
George Rimar 0702c4e86e [ELF] - Linkerscript: Implemented SORT command.
When the SORT keyword is used, the linker will sort the files or sections into ascending order by name before placing them in the output file.
It is used in FreeBSD script:
https://svnweb.freebsd.org/base/head/sys/conf/ldscript.amd64?revision=284870&view=markup#l139

This is PR28689.

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

llvm-svn: 277153
2016-07-29 15:32:46 +00:00