Commit Graph

1968 Commits

Author SHA1 Message Date
Rui Ueyama 83095b5e8f [PECOFF] addDeadStripRoot is not thread-safe.
llvm-svn: 214835
2014-08-05 01:44:43 +00:00
Rui Ueyama 145ef0186c [PECOFF] Fix /include option in .drectve section.
/INCLUDE arguments passed as command line options are handled in the
same way as Unix -u. All option values are converted to an undefined
symbol and added to a dummy input file, so that the specified symbols
are resolved.

One tricky thing on Windows is that the option is also allowed to
appear in the object file's directive section. At the time when
it's being read, all (regular) command line options have already
been processed. We cannot add undefined atoms to the dummy file
anymore.

Previously, we added such /INCLUDE to a set that has already been
processed. As a result the options were ignored.

This patch fixes the issue. Now, /INCLUDE symbols in the directive
section are handled as real undefined symbol in the COFF file.
We create an undefined symbol for each /INCLUDE argument and add
it to the file being parsed.

llvm-svn: 214824
2014-08-04 23:48:57 +00:00
Rui Ueyama dd44a7fb0f [PECOFF] Remove unused paraemter.
llvm-svn: 214791
2014-08-04 22:19:53 +00:00
Simon Atanasyan 0670abdd2e [Mips] Replace assembler code by YAML to make the 'gotsym.test' test
target independent.

llvm-svn: 214641
2014-08-02 20:18:31 +00:00
Simon Atanasyan 91af42fb7b [Mips] Replace assembler code by YAML to make the 'interpreter.test' test
target independent.

llvm-svn: 214495
2014-08-01 09:47:21 +00:00
Rui Ueyama 140f6029ce [PECOFF] Fix section header.
The PE/COFF spec says that SizeOfRawData field in the section
header must be a multiple of FileAlignment from the optional
header. LLD emits 512 as FileAlignment, so it must have been
a multiple of 512.

LLD did not follow that. It emitted the actual section size
without the last padding as the SizeOfRawData. Although it's
not correct as per the spec, the Windows loader doesn't seem
to actually bother to check that. Executables created by LLD
worked fine.

However, tools dealing with executalbe files may expect it
to be the correct value, and one instance of it is mt.exe
tool distributed as a part of Windows SDK.

If CMake is invoked with "-E vs_link_exe" option, it silently
run mt.exe to embed a resource file to the resulting file.
And mt.exe sometimes breaks an input file if it's section
header does not follow the standard. That caused a misterous
error that CMake with Ninja occasionally produces a broken
executable.

This patch fixes the section header to make mt.exe and
other tools happy.

llvm-svn: 214453
2014-07-31 22:40:35 +00:00
Simon Atanasyan d7bc5d0119 XFAIL the ARM test when we don't have this target.
llvm-svn: 214420
2014-07-31 19:02:10 +00:00
Nick Kledzik 0f4fbf17f5 [mach-o] wire up -t option
llvm-svn: 214414
2014-07-31 18:19:03 +00:00
Rafael Espindola 091d371cbc Update for llvm api change.
llvm-svn: 214378
2014-07-31 03:17:04 +00:00
Nick Kledzik 76689d0202 [mach-o] Fix test case comment and stray file copy
llvm-svn: 214278
2014-07-30 01:43:21 +00:00
Nick Kledzik 9b7b8ff32d [mach-o] Fix arm interworking with movw/movt
In some cases the address of a function will be materialized with a movw/movt
pair.  If the function is a thumb function, the low bit needs to be set on
the movw immediate value.

llvm-svn: 214277
2014-07-30 01:41:38 +00:00
Nick Kledzik 2fcbe822c0 [mach-o] Add support for -sectalign option
The -sectalign option is used to increase the alignment required for a section.
It required some reworking of how the __TEXT segment is laid out because that
segment also contains the mach_header and load commands. And the size of load
commands depend on the number of segments, sections, and dependent dylibs used.

Using this option will simplify some future test cases because the final
address of code can be pinned down, making tests of its content easier.

llvm-svn: 214268
2014-07-30 00:58:06 +00:00
Nick Kledzik 3fc5ffecf8 [mach-o] fix non-debug warnings
llvm-svn: 214145
2014-07-28 23:40:26 +00:00
Nick Kledzik 54fd4e5fcb [mach-o] Implement interworking between thumb and arm code
All iOS arm processor support switching between arm and thumb mode at call sites
by using the BLX instruction (instead of BL).  But the compiler does not know
the implementation mode for extern functions, so the linker must update BL/BLX
instructions to match what is linked is actually linked together.  In addition,
pointers to functions (such as vtables) must have the low bit set if the target
of the pointer is a thumb mode function.

llvm-svn: 214140
2014-07-28 23:06:09 +00:00
Rui Ueyama 7385120d65 [PECOFF] Fix failing test.
This should be covered by the Driver's unit tests.

llvm-svn: 214134
2014-07-28 22:31:37 +00:00
Simon Atanasyan 6052f045d7 [Mips] Remove redundant REQUIRES clause.
The exe-got.test test case is target independent.

llvm-svn: 214085
2014-07-28 14:19:18 +00:00
Rui Ueyama 55a6e762ee [PECOFF] Add /profile command line option.
llvm-svn: 213984
2014-07-25 22:28:49 +00:00
Rui Ueyama a821d32729 Fix unsafe memory access
The following expression

  m[i] = m[j]

where m is a DenseMap and i != j is not safe. m[j] returns a
reference, which would be invalidated when a rehashing occurs.
If rehashing occurs to make room for m[i], m[j] becomes
invalid, and that invalid reference would be used as the RHS
value of the expression.

llvm-svn: 213969
2014-07-25 19:46:31 +00:00
Nick Kledzik 21921375cc [mach-o] Add support for LC_DATA_IN_CODE
Sometimes compilers emit data into code sections (e.g. constant pools or
jump tables). These runs of data can throw off disassemblers.  The solution
in mach-o is that ranges of data-in-code are encoded into a table pointed to
by the LC_DATA_IN_CODE load command.

The way the data-in-code information is encoded into lld's Atom model is that
that start and end of each data run is marked with a Reference whose offset
is the start/end of the data run.  For arm, the switch back to code also marks
whether it is thumb or arm code.

llvm-svn: 213901
2014-07-24 23:06:56 +00:00
Simon Atanasyan 4b6d090bd3 [Mips] Replace assembler code by YAML to make the 'exe-dynsym.test' test
target independent.

llvm-svn: 213868
2014-07-24 15:42:11 +00:00
Rui Ueyama abea8fa61d Change the signature of insertElementAt and rename addInputElementFront
insertElementAt(x, END) does the identical thing as addInputElement(x),
so the only reasonable use of insertElementAt is to call it with the
other possible argument, BEGIN. That means the second parameter of the
function is just redundant. This patch is to remove the second
parameter and rename the function accordingly.

llvm-svn: 213821
2014-07-24 00:08:22 +00:00
Rui Ueyama cad746439f [PECOFF] Simplify.
insertElementAt(x, END) is the same as addInputElement(x).

llvm-svn: 213818
2014-07-23 23:47:28 +00:00
Rui Ueyama 7c60a98f16 [PECOFF] Add the entry point file at the right place.
The entry point file needs to be processed after all other
object files and before all .lib files. It was processed
after .lib files. That caused an issue that the entry point
function was not resolved from the standard library files.

llvm-svn: 213804
2014-07-23 21:41:20 +00:00
Rui Ueyama 23314e1ca6 [PECOFF] Fix entry point address.
Because of a bug, the entry point address in the PE/COFF header
was not correct.

llvm-svn: 213802
2014-07-23 20:51:04 +00:00
Rui Ueyama a27bb08e73 [PECOFF] Fix entry point functions selection
On Windows there are four "main" functions -- main, wmain, WinMain,
or wWinMain. Their parameter types are diffferent. The standard
library provides four different entry functions (i.e.
{w,}{WinMain,main}CRTStartup) for them. You need to use the right
entry routine for your "main" function.

If you give an /entry option, the specified name is used
unconditionally.

Otherwise, the linker needs to select the right one based on
user-supplied entry point function. This can be done after the
linker reads all the input files.

This patch moves the code to determine the entry point function
from the driver to a virtual input file. It also implements the
correct logic for the entry point function selection.

llvm-svn: 213713
2014-07-23 00:57:57 +00:00
Nick Kledzik 7e9808f7de [mach-o] add initial support for modes in arm code.
This patch just supports marking ranges that are thumb code (vs arm code).
Future patches will mark data and jump table ranges. The ranges are encoded
as References with offsetInAtom being the start of the range and the target
being the same atom.

llvm-svn: 213712
2014-07-23 00:51:37 +00:00
Nick Kledzik b78ad899e5 [mach-o] add support for round tripping all arm/thumb relocations
Update the parse-arm-relocs.yaml test case to run the linker back to back
to ensure all relocations round trip in and out of mach-o.

llvm-svn: 213700
2014-07-22 23:07:49 +00:00
Rui Ueyama 97d7c29fbc [PECOFF] Parameterize ResovalbeSymbols object.
So that it can be shared by multiple input files.

llvm-svn: 213699
2014-07-22 22:55:06 +00:00
Rui Ueyama d0a480a6f2 [PECOFF] Remember /noentry option so that later passes can handle it.
This is a part of a larger change to move the entry point
processing to a later pass than the driver. On Windows the default
entry point function varies depending on user-provided functions.
That means the driver is not able to correctly know the entry point
function name. Only passes after the core linker can infer it.

llvm-svn: 213697
2014-07-22 22:19:42 +00:00
Simon Atanasyan bcb865a8ce [Mips] Replace assembler code by YAML to make the 'entry-name.test' test target
independent.

llvm-svn: 213690
2014-07-22 21:47:34 +00:00
Nick Kledzik e1aaced0cb [mach-o] Add test case for armv6 (arm not thumb) hello world
llvm-svn: 213592
2014-07-22 00:49:49 +00:00
Nick Kledzik 03e16f2ab4 [mach-o] add support for old x86 __eh_frame sections
Over time the symbols and relocations have changed for dwarf unwind info
in the __eh_frame section.  Add test cases for older and new style.

llvm-svn: 213585
2014-07-21 22:06:57 +00:00
David Blaikie ced7b43a06 Fix lld build for llvm API changes committed in r213557
llvm-svn: 213560
2014-07-21 16:46:14 +00:00
Simon Atanasyan 6f3382cd44 [Mips] Fix typo in the comment.
llvm-svn: 213520
2014-07-21 13:16:53 +00:00
Simon Atanasyan 09f45ca39b [Mips] Replace assembler code by YAML to make the 'dynlib-fileheader.test'
test target independent.

llvm-svn: 213480
2014-07-20 20:03:46 +00:00
Simon Atanasyan 5ecadda642 [Mips] Replace assembler code by YAML to make the test 'dynlib-dynamic.test'
target independent.

llvm-svn: 213462
2014-07-19 20:18:46 +00:00
Simon Atanasyan f7ce3ea024 [Mips] Replace assembler code by YAML to make the test 'base-address.test'
target independent.

llvm-svn: 213390
2014-07-18 17:23:21 +00:00
Artyom Skrobov 7a86a548b9 swapStruct extracted into include/llvm/Support/MachO.h (no functional change)
llvm-svn: 213362
2014-07-18 09:28:10 +00:00
Nick Kledzik 7e246a47f9 [mach-o] Add support for x86 pointers which use scattered relocations
llvm-svn: 213344
2014-07-18 01:05:35 +00:00
Nick Kledzik 68a1abdf14 [mach-o] Add support for x86 CALL instruction that uses a scattered relocation
llvm-svn: 213340
2014-07-18 00:37:52 +00:00
Nick Kledzik 2d432353ba [mach-o] implement more x86 and x86_64 relocation support
Add support for adding section relocations in -r mode.  Enhance the test
cases which validate the parsing of .o files to also round trip.  They now
write out the .o file and then parse that, verifying all relocations survived
the round trip.

llvm-svn: 213333
2014-07-17 23:16:21 +00:00
Joerg Sonnenberger bbe75b99f0 References cannot be bound to null.
llvm-svn: 213323
2014-07-17 22:30:09 +00:00
Rui Ueyama f2dcc9139b [PECOFF] Split ExportedSymbolRenameFile.
The code to manage resolvable symbols is now separated from
ExportedSymbolRenameFile so that other class can reuse it.
I'm planning to use it to find the entry function symbol
based on resolvable symbols.

llvm-svn: 213322
2014-07-17 22:17:10 +00:00
Rui Ueyama 9ec7e659d8 Remove all uses of llvm::function_ref from LLD.
llvm-svn: 213313
2014-07-17 21:33:21 +00:00
Rui Ueyama d5ba2a6994 Use std::function instead of llvm::function_ref.
llvm-svn: 213312
2014-07-17 21:23:52 +00:00
Simon Atanasyan c2d8d6d489 [Mips] s/context/ctx/ for consistency and reduce lines lengths.
No functional changes.

llvm-svn: 213310
2014-07-17 20:57:54 +00:00
Rui Ueyama 286691ad5e [PECOFF] Set DLL bit in PE header if DLL.
Windows loader can load a DLL without this bit but it wouldn't
call the initializer function in the DLL if the bit is absent.

llvm-svn: 213216
2014-07-17 00:22:26 +00:00
Nick Kledzik 9185115abb Update .gitignore to ignore hidden MacOSX Finder droppings
llvm-svn: 213195
2014-07-16 21:01:17 +00:00
Nick Kledzik 2458bec7e7 [mach-o] refactor KindHandler into ArchHandler and simplify passes.
All architecture specific handling is now done in the appropriate
ArchHandler subclass.

The StubsPass and GOTPass have been simplified.  All architecture specific
variations in stubs are now encoded in a table which is vended by the
current ArchHandler.

llvm-svn: 213187
2014-07-16 19:49:02 +00:00
Simon Atanasyan 64c0ac2b35 [ELF] Implement parsing `-l` prefixed items in the `GROUP` linker script command.
There are two forms of `-l` prefixed expression:

* -l<libname>
* -l:<filename>

In the first case a linker should construct a full library name
`lib + libname + .[so|a]` and search this library as usual. In the second case
a linker should use the `<filename>` as is and search this file through library
search directories.

The patch reviewed by Shankar Easwaran.

llvm-svn: 213077
2014-07-15 17:17:30 +00:00