Commit Graph

203 Commits

Author SHA1 Message Date
Rui Ueyama 569851f1d6 Partially revert r287009: Remove trailing whitespace.
This reverts part of r287009 because I accidentally changed binary files.

llvm-svn: 287010
2016-11-15 19:09:13 +00:00
Rui Ueyama d7cfb1b6dd Remove trailing whitespace.
llvm-svn: 287009
2016-11-15 19:07:17 +00:00
Rui Ueyama b66260ac17 Remove trailing whitespace.
llvm-svn: 283372
2016-10-05 20:09:50 +00:00
Chris Bieneman 5a805df1a5 [CMake] Fix linker-as-ld to symlink instead of copy lld
Summary: This test fails if you're building with BUILD_SHARED_LIBS because the LLVM libraries are found via @rpath. Symlinking instead of copying should be sufficiently robust for the test case.

Reviewers: llvm-commits

Subscribers: davide

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

llvm-svn: 281271
2016-09-12 22:38:43 +00:00
Pete Cooper ef5bea9dca Dead strip DESC bits should only be set on object files.
It only makes sense to set on N_NO_DEAD_STRIP on a relocatable object file.  Otherwise the bits aren't useful for anything.  Matches the ld64 behaviour.

llvm-svn: 278419
2016-08-11 21:27:18 +00:00
Pete Cooper 1ed8f1f6e5 Better compress lazy binding info to match ld64.
We should be using one of BIND_OPCODE_SET_DYLIB_SPECIAL_IMM, BIND_OPCODE_SET_DYLIB_ORDINAL_IMM,
and BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB depending on whether ordinals are <= 0, <= 15, > 15.

This matches the behaviour of ld64.

llvm-svn: 278407
2016-08-11 20:59:27 +00:00
Pete Cooper 21f475e1c4 Generate slightly more compressed binding opcodes when entries are the same as last time.
We already had logic for binding opcodes had the same addend as last time.  This adds
the cases where the ordinal, symbol name, type, and segment offsets are the same as
the last emitted ordinal.

This gets us one step closer to emitting rebase opcodes as compressed as ld64 can manage.

llvm-svn: 278405
2016-08-11 20:37:02 +00:00
Pete Cooper 91db988dfb Add test for rebase opcodes. We didn't have one. NFC.
This will be used to test upcoming changes to improve binding opcode
emission to match the more compressed form ld64 can generate.

llvm-svn: 278400
2016-08-11 20:31:50 +00:00
Pete Cooper 1e885c529d Add missing RUN line from r278398. This test works with this line but i forgot to push it
llvm-svn: 278399
2016-08-11 20:23:15 +00:00
Pete Cooper 732f1ef9de Arm64 stubs alignment is 2, not 4.
This matches the behaviour of ld64 when looking at the alignment of the stubs section in the final image.

llvm-svn: 278398
2016-08-11 20:18:05 +00:00
Pete Cooper 46cd113c87 Change when we choose to add an LC_LOAD_DYLIB to the final image.
Currently we do this when an atom is used, but we need to do it when a
dylib is referenced on the cmdline as this matches ld64.

This fixes much confusion over which maps are indexed with installName
vs path.  There is likely other confusion so i'll be seeing if i can remove
path() completely in a future commit as path() shouldn't really be needed by anyone.

llvm-svn: 278396
2016-08-11 20:10:14 +00:00
Pete Cooper d9e0f71195 Change all the libSystem test files to be dylibs instead of normalized files. Currently NFC.
A future commit will change when we choose to add an LC_LOAD_DYLIB to the final image.  Currently
we do this when an atom is used, but we need to do it when a dylib is referenced on the cmdline as
this matches ld64.

To allow this change, libsystem (and other future yaml files representing dylibs) need to be dylibs
so that the loader can see to add them to the referenced dylib list.

llvm-svn: 278386
2016-08-11 18:46:21 +00:00
Pete Cooper 363e7f6914 Fix one more test missed by r278372. The next commit will update libsystem in a way which broke without this fix as it referenced the wrong file
llvm-svn: 278385
2016-08-11 18:43:42 +00:00
Pete Cooper 932bce6ade Fix off-by-one error in default currentVersion.
A version of 0x1000 is 0.16.0, not 1.0.0 as the comment said.  Fix the
value to match the comment, and also the one test case which had this
wrong.

llvm-svn: 278381
2016-08-11 18:41:14 +00:00
Pete Cooper c4a12a08e2 Have one version of libSystem for each arch. NFC.
An upcoming commit will change how we choose to reference a dylib.  Currently
dylibs are only given an LC_LOAD_DYLIB in the final image if an atom is used.
This is different from ld64 which adds the load command when the dylib is referenced
on the cmdline.

In order to change this behaviour, we need libSystem.yaml to actually contain a mach header
so that it is parsed as a dylib, instead of currently being parsed as a normalised file.

To get a mach header, we also require an arch, so now we have one libsystem per arch and
all the tests have been updated to choose the correct one.

llvm-svn: 278372
2016-08-11 18:08:59 +00:00
Lang Hames 8c2406b1fc [lld][MachO] Fix LC_SEGEMENT[_64] filesize computation in -r mode.
Using vmsize to populate this file works when outputing MachO images, but fails
when outputting relocatable objects. This patch fixes the computation to use
file offsets, which works for both output types.

Fixes <rdar://problem/27727666>

llvm-svn: 278297
2016-08-10 22:15:09 +00:00
Pete Cooper 5559b24935 The first string table entry should be a null terminated space, not just null.
This matches the behaviour of ld64 which initializes the string table with
' ' then '\0'.  lld only had the '\0' and needed the ' '.

llvm-svn: 278071
2016-08-08 23:20:04 +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
Rafael Espindola 1415cb9cbe Trying to fix this test on windows.
llvm-svn: 277022
2016-07-28 19:18:22 +00:00
Lang Hames 1b81e75a60 [lld][MachO] Fix bugs in the debug-syms test case.
The previous run line depended on libSystem.dylib being present, which it's not
on non-darwin platforms. The new run line uses libSystem.yaml instead.

llvm-svn: 276999
2016-07-28 16:56:26 +00:00
Lang Hames 436f7d6606 [lld][MachO] Re-apply r276921 with fix - initialize strings for debug string
copies.

llvm-svn: 276935
2016-07-27 22:55:30 +00:00
Lang Hames f2260567ca [lld][MachO] Temporarily revert r276921 - it's causing bot-failures on Linux.
llvm-svn: 276928
2016-07-27 22:46:02 +00:00
Lang Hames 560333749f [lld][MachO] Add debug info support for MachO.
This patch causes LLD to build stabs debugging symbols for files containing
DWARF debug info, and to propagate existing stabs symbols for object files
built using '-r' mode. This enables debugging of binaries generated by LLD
from MachO objects.

llvm-svn: 276921
2016-07-27 21:31:25 +00:00
Lang Hames 3b3b4d792f [lld][MachO] Add support for x86-64 negDelta64 references and fix negDelta32.
These references are used to implement MachO/x64-64 subtractor relocations
where the minuend is being fixed up, rather than the subtrahend. The 64-bit
version was not previously supported, the 32-bit version was partially
implemented but contained bugs not caught by existing test cases. This
patch fixes both functionality and test coverage.

llvm-svn: 273759
2016-06-25 00:29:54 +00:00
Pete Cooper 3f564a52d0 Parsed alignment should be a power of 2.
The .o path always makes sure to store a power of 2 value in the
Section alignment.  However, the YAML code didn't verify this.

Added verification and updated all the tests which had a 3 but meant
to have 2^3.

llvm-svn: 264228
2016-03-24 00:36:37 +00:00
Pete Cooper ebecd6c543 Fix EHFrame processing to add implicit references when needed.
The current code for processCIE and processFDE returns out if it sees
any references.  The problem with this is that some references could be
explicit in the binary, while others are implicit as they can be
inferred from the content of the EHFrame itself.

This change walks the references we have against the references we
need, and verifies that all explicit references are in the correct place,
and generates any missing implicit ones.

Reviewed by Lang Hames and Nick Kledzik.

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

llvm-svn: 263590
2016-03-15 21:33:10 +00:00
Pete Cooper e8d9df4ea5 Use __nl_symbol_ptr instead of __got in the stubs pass on x86 archs.
The non lazy atoms generated in the stubs pass use an image cache to
hold all of the pointers.  On arm archs, this is the __got section,
but on x86 archs it should be __nl_symbol_ptr.

rdar://problem/24572729

llvm-svn: 260271
2016-02-09 20:11:17 +00:00
Pete Cooper 35c3318edc Aligned __stub_helper section to 4-bytes.
ld64 aligns most of the stub's to 2 byte alignment, expect for
the stub helper common atoms which are 4 byte aligned.

This adds a new field to StubInfo which tracks this alignment
and ensures that this is the alignment we get in the final image.

rdar://problem/24570220

llvm-svn: 260248
2016-02-09 18:56:37 +00:00
NAKAMURA Takumi 3725978b10 lld/test/mach-o/dependency_info.yaml: Forgot to remove XFAIL:win32.
llvm-svn: 260209
2016-02-09 07:44:10 +00:00
NAKAMURA Takumi 9eee62f558 lld/test/mach-o/dependency_info.yaml: Tweak for dos path.
llvm-svn: 260208
2016-02-09 07:30:24 +00:00
NAKAMURA Takumi 127295492d check-lld: Introduce %python.
llvm-svn: 260207
2016-02-09 07:30:18 +00:00
Pete Cooper 9b28a4559e Add cmdline options for LC_DATA_IN_CODE load command.
Also added the defaults for whether to generate this load command, which
the cmdline options are able to override.

There was also a difference to ld64 which is fixed here in that ld64 will
generate an empty data in code command if requested.

rdar://problem/24472630

llvm-svn: 260191
2016-02-09 02:10:39 +00:00
Pete Cooper 41f3e8e408 Generate LC_FUNCTION_STARTS load command.
This load command generates data in the LINKEDIT section which
is a list of ULEB128 delta's to all of the functions in the __text section.

It is then 0 terminated and pointer aligned to pad.

ld64 exposes the -function-starts and no-function-starts cmdline options
to override behaviour from the defaults based on file types.

rdar://problem/24472630

llvm-svn: 260188
2016-02-09 01:38:13 +00:00
Pete Cooper 841a978d22 We should never dead strip mach header symbols.
This was a bug in our handling of these symbols compared to ld64.

Turns out that ld64 always marks these symbols as being not dead stripped.

llvm-svn: 260185
2016-02-09 01:34:13 +00:00
Pete Cooper b8fec3ea62 Set max segment protection level.
The initial segment protection was also being used to set the maximum
segment protection level.  Instead, the maximum should be set according
to the architecture we are linking.  For example on Mac OS it should be
RWX on most pages, but on iOS is often on R_X.

rdar://problem/24515136

llvm-svn: 259966
2016-02-06 00:51:16 +00:00
Pete Cooper 8563e5a362 Set CPU_SUBTYPE_LIB64 in mach_header.
On Mac OS 10.5 and later, with X86_64 and outputting a dynamic executable,
ld64 set the CPU_SUBTYPE_LIB64 mask on the cpusubtype in the mach_header.

This adds the same functionality to lld.

rdar://problem/24507177

llvm-svn: 259826
2016-02-04 20:43:43 +00:00
Pete Cooper 4c3eee78f1 Add test missed from r259746
llvm-svn: 259747
2016-02-04 02:50:07 +00:00
Pete Cooper f8abe8c825 Set S_ATTR_SOME_INSTRUCTIONS on __text section.
ld64 sets both S_ATTR_PURE_INSTRUCTIONS and S_ATTR_SOME_INSTRUCTIONS
on __TEXT, __text.  We only had the S_ATTR_PURE_INSTRUCTIONS attribute.

rdar://problem/24495801

llvm-svn: 259744
2016-02-04 02:23:34 +00:00
Pete Cooper ceee5de088 Generate version min load commands when the platform is unknown.
In the case where we are emitting to an object file, the platform is
possibly unknown, and the source object files contained load commands
for version min, we can take the maximum of those min versions and
emit in in the output object file.

This test also tests r259739.

llvm-svn: 259742
2016-02-04 02:16:08 +00:00
Pete Cooper 451ec4b68e Add support for -sdk_version cmdline option.
This option is emitted in the min_version load commands.

Note, there's currently a difference in behaviour compared to ld64 in
that we emit a warning if we generate a min_version load command and
didn't give an sdk_version.  We need to decide what the correct behaviour
is here as its possible we want to emit an error and force clients to
provide the option.

llvm-svn: 259729
2016-02-03 23:39:05 +00:00
Pete Cooper 354809e139 Add generation of LC_VERSION_MIN load commands.
If the command line contains something like -macosx_version_min and we
don't explicitly disable generation with -no_version_load_command then
we generate the LC_VERSION_MIN command in the output file.

There's a couple of FIXME's in here.  These will be handled soon with
more tests but I didn't want to grow this patch any more than it already was.

rdar://problem/24472630

llvm-svn: 259718
2016-02-03 22:28:29 +00:00
Pete Cooper 3a92c35539 __mh_execute_header atoms should be global and never dead strippped.
In r259574 I fixed some of the issues with the mach header symbols
and DSO handles.

This is the next issue whereby the __mh_execute_header has to not
be dead stripped, and (to match ld64) should be dynamically referenced.

The test here should also have been added in r259574 to make sure that
we emit this symbol.  But checking that it is not only emitted but also
has the correct reference type is fine.

llvm-svn: 259589
2016-02-02 22:19:01 +00:00
Pete Cooper d4f414583a Fix handling of mach header and DSO handle symbols.
The magic file which contained these symbols inherited from archive
which meant that the resolver didn't add the required atoms as archive
members only get added when referenced.  Instead we now inherit from
SimpleFile which always links in the atoms needed.

The second issue was in the handling of these symbols when we emit
the MachO.  The mach header symbol needs to be in the atom list as
it gets an offset (0), and being in the atom list makes sure it is
emitted to the symbol table.  DSO handles are not emitted to the
symbol table.

rdar://problem/24450654

llvm-svn: 259574
2016-02-02 21:37:15 +00:00
Pete Cooper 55634d8e8d MachoFile should default to using subsections_via_symbols.
When we parse a MachoFile, we set a number of members from the parsed
file, for example, subsectionsViaSymbols.

However, a number of passes, such as ObjCPass, create local copies of
MachoFile and don't get the benefit of setting flags and other fields in
the parser.  Instead we can just give a more sensible default as the parser
will definitely get the correct value from the file anyway.

llvm-svn: 259426
2016-02-01 22:24:44 +00:00
Pete Cooper 4a92469260 Atomize the ObjC category list section.
__DATA, __objc_catlist contains a list of pointers to categories.

We want to atomize it so that the ObjC pass can later optimize and remove
categories.  That will be a later patch.

llvm-svn: 259386
2016-02-01 19:10:10 +00:00
Pete Cooper 351164504a Add support for export_dynamic cmdline option and behaviour.
This option matches the behaviour of ld64, that is it prevents globals
from being dead stripped in executables and dylibs.

Reviewed by Lang Hames

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

llvm-svn: 258554
2016-01-22 21:13:24 +00:00
Pete Cooper 90dbab0b0d Add an ObjCPass to the MachO linker.
This pass currently emits an objc image info section if one is required.

This section contains the aggregated version and flags for all of the input
files.

llvm-svn: 258197
2016-01-19 21:54:21 +00:00
Pete Cooper 0872e46c9d Set the objc constraint on the context based on the parsed files.
Like arch, os, etc, when we know we are going to use a file, we check
that the file has compatible objc constraints to the context, throw
appropriate errors where that is not the case, and hopefully set the
objc constraints on the context for use later.

Added 2 tests to ensure that we don't have incompatibilities between
host and simulator code as both will get x86 based architectures.

llvm-svn: 258173
2016-01-19 19:46:41 +00:00
Pete Cooper 12b094d5f4 Only emit files with subsections_via_symbols if all inputs had that set.
When generating a relocatable file, its only valid to set this flag if
all of the inputs also had the flag.  Otherwise we may atomize incorrectly
when we link the relocatable file again.

Reviewed by Lang Hames.

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

llvm-svn: 257976
2016-01-16 01:09:23 +00:00
Pete Cooper 4b6bed98e2 Give error on binaries containing GC objc image infos.
The image info struct contains flags for what kind of GC/retain/release is required.

Give an error if we parse GC flags as these are unsupported.

llvm-svn: 257974
2016-01-16 00:57:07 +00:00