Commit Graph

2012 Commits

Author SHA1 Message Date
Rui Ueyama 2feff785fc [PECOFF] Run lib.exe with /machine:x64.
llvm-svn: 217219
2014-09-05 01:35:23 +00:00
Rui Ueyama 30a6bc286b [PECOFF] Run cvtres.exe with /machine:x64.
If we are creating a PE+ executable, we need to run cvtres with
/machine:x64 instead of /machine:x86. Otherwise the resulting executable
would be invalid.

llvm-svn: 217214
2014-09-05 00:26:28 +00:00
Nick Kledzik 635f9c7158 [mach-o] Let darwin driver infer arch from .o files if -arch not used.
Mach-O has a "fat" (or "universal") variant where the same contents built for
different architectures are concatenated into one file with a table-of-contents
header at the start.  But this leaves a dilemma for the linker - which
architecture to use.

Normally, the linker command line -arch is used to force which slice of any fat
files are used.  The clang compiler always passes -arch to the linker when
invoking it.  But some Makefiles invoke the linker directly and don’t specify
the -arch option.  For those cases, the linker scans all input files in command
line order and finds the first non-fat object file.  Whatever architecture it
is becomes the architecture for the link.

llvm-svn: 217189
2014-09-04 20:08:30 +00:00
Rui Ueyama 879b0126f4 Move function. No functionality change.
llvm-svn: 217121
2014-09-04 02:52:26 +00:00
Nick Kledzik 54e0614efd Fix unit test now that 'ld' is host specific
llvm-svn: 217114
2014-09-04 00:16:04 +00:00
Nick Kledzik cec33b84f2 If lld binary is named 'ld' on darwin, use darwin driver mode
llvm-svn: 217112
2014-09-04 00:03:36 +00:00
Nick Kledzik 0e3e6155fe [mach-o] Improve x86_64 reference kind switch statements.
The use of default: was disabling the warning about unused enumerators. Fix
that, then fix the one enumerator that was not handled. Add coverage for
it in test suite.

llvm-svn: 217078
2014-09-03 21:09:24 +00:00
Nick Kledzik 141330aef6 [mach-o] Add support for using export tries
On Darwin at runtime, dyld will prefer to use the export trie of a dylib instead
of the traditional symbol table (which is large and requires a binary search).

This change enables the linker to generate an export trie and to prefer it if
found in a dylib being linked against.  This also simples the yaml for dylibs
because the yaml form of the trie can be reduced to just a sequence of names.

llvm-svn: 217066
2014-09-03 19:52:50 +00:00
Rui Ueyama 495a031ce4 [PECOFF] Fix AMD64_REL_[1-5] and AMD64_SECTION relocations
I hope this is the last fix for x64 relocations as I've wasted
a few days on this.

This caused a mysterious issue that some C++ programs crash on
startup. It was because a null pointer is passed as argv to main.
__tmainCRTStartup calls main, but before that it calls all
initialization routines between .text$xc_a and .text$xc_z.
pre_cpp_init is one of such routines, and it is the one who
initializes a heap pointer for argv for later use. That routine
was not called for some reason.

It turned out that __tmainCRTStartup was skipping a block of
code because of the relocation bug. A condition in the function
depends on a memory load, and that memory load was referring
a wrong location. As a result a jump instruction took the
wrong branch, skipping pre_cpp_init and so on.

This patch fixes the issue. Also added more tests to fix them
once and for all.

llvm-svn: 216772
2014-08-29 20:33:27 +00:00
Rui Ueyama 4a6ead7a9f [PECOFF] Another Win64 relocation bug fix
When a relocation is applied to a location, the new value needs
to be added to the existing value at the location. Existing
value is in most cases zero, but if not, the current code does
not work.

llvm-svn: 216680
2014-08-28 19:00:40 +00:00
Rui Ueyama f4b0d5e050 [PECOFF] Implement Win64 base relocations
Image Base field in the PE/COFF header is used as hint for the loader.
If the loader can load the executable at the specified address, that's
fine, but if not, it has to load it at a different address.

If that happens, the loader has to fix up the addresses in the
executable by adding the offset. The list of addresses that need to
be fixed is in .reloc section.

This patch is to emit x64 .reloc section contents.

llvm-svn: 216636
2014-08-28 00:47:11 +00:00
Rui Ueyama 06970fe7fd [PECOFF] Fix AMD64_ADDR64 relocation.
IMAGE_REL_AMD64_ADDR64 relocation should set 64-bit *VA* (virtual
address) instead of *RVA* (relative virtual address), so we have
to add the iamge base to the target's RVA.

llvm-svn: 216512
2014-08-27 01:10:01 +00:00
Rui Ueyama d718c73f0b [PECOFF] Add /HighEntropyVA.
This is yet another command line flag to set a bit in
DLLCharacteristics. Default on Win64 is "on".

llvm-svn: 216414
2014-08-25 22:23:34 +00:00
Rui Ueyama 768cc6d31d Use LLD naming style.
llvm-svn: 216402
2014-08-25 19:38:57 +00:00
Rafael Espindola 0941b568ce Update for LLVM api change
llvm-svn: 216395
2014-08-25 18:16:56 +00:00
Rui Ueyama 4c6847aab9 [PECOFF] Explicitly pass machine type
x86 and x64 are created equal -- taking x86 as the default argument
made it hard to find bugs.

llvm-svn: 216295
2014-08-22 22:03:16 +00:00
Rui Ueyama 839fb2f10c Simplify. No functionality changes.
llvm-svn: 216257
2014-08-22 02:00:58 +00:00
Rui Ueyama 5711df44b8 [PECOFF] Fix PE+ relocations
The implementation of AMD64 relocations was imcomplete
and wrong. On AMD64, we of course have to use AMD64
relocations instead of i386 ones. This patch fixes the
issue.

LLD is now able to link hello64.obj (created from
hello64.asm) against user32.lib and kernel32.lib to
create a Win64 binary.

llvm-svn: 216253
2014-08-22 01:15:43 +00:00
Hans Wennborg 2bf6c5c371 Fix build after r216223: Explicitly pass ownership of the MemoryBuffer to AddNewSourceBuffer using std::unique_ptr
llvm-svn: 216252
2014-08-22 01:13:29 +00:00
Nick Kledzik 7820c80f7d [mach-o] support N_NO_DEAD_STRIP nlist.desc bit
Mach-O symbols can have an attribute on them means their content should never be
dead code stripped.  This translates to deadStrip() == deadStripNever.

llvm-svn: 216234
2014-08-21 22:18:30 +00:00
Nick Kledzik 77afc71426 [mach-o] Fix initial live atoms with -dead_strip
When -dead_strip is used with -exported_symbols_list the initial set of
live atoms are those in the export list.

llvm-svn: 216213
2014-08-21 20:25:50 +00:00
Nick Kledzik e484075d82 [mach-o] Add support for -single_module and -multi_module
These are both obsolete options that controled how dylibs were built.

llvm-svn: 216205
2014-08-21 18:57:42 +00:00
Dan Liew 31f2f1befe Fixed typo (from r215544) that caused the lld-sphinx-docs buildbot
to fail.

llvm-svn: 216165
2014-08-21 10:06:34 +00:00
Rui Ueyama 6f579ac5f5 [PECOFF] Don't use default argument.
I'm adding new parameters to the function, and the existing
parameter with a default argument is found confusing.

llvm-svn: 216153
2014-08-21 03:40:33 +00:00
Rui Ueyama 5b6532fa49 Remove dead code.
llvm-svn: 216152
2014-08-21 03:05:12 +00:00
Nick Kledzik 8c0bf75ef5 [mach-o] Add support for -exported_symbols_list and -keep_private_externs
Both options control the final scope of atoms.

When -exported_symbols_list <file> is used, the file is parsed into one
symbol per line in the file.  Only those symbols will be exported (global)
in the final linked image.

The -keep_private_externs option is only used with -r mode. Normally, -r
mode reduces private extern (scopeLinkageUnit) symbols to non-external. But
add the -keep_private_externs option keeps them private external.

llvm-svn: 216146
2014-08-21 01:59:11 +00:00
Nick Kledzik bb38f7bdaa Add notifier hooks to symbol table.
This is the one interesting aspect from:
   http://reviews.llvm.org/D4965

These hooks are useful for flavor specific processing, such as recording that
a DefinedAtom replaced a weak SharedLibraryAtom.

llvm-svn: 216122
2014-08-20 20:46:28 +00:00
Rui Ueyama a0b988cb63 [PECOFF] Emit PE+ idata tables.
Import tables in the PE+ format is an array of 64 bit numbers,
although the executable size is still limited to 4GB in PE+.

llvm-svn: 216039
2014-08-20 01:09:42 +00:00
Rafael Espindola 2ed1c57b34 Update for llvm api change.
llvm-svn: 216003
2014-08-19 18:44:51 +00:00
Nick Kledzik 0cc040780e [mach-o] improve darwin driver 'usage' message when run with no args
llvm-svn: 215781
2014-08-15 22:42:46 +00:00
Nick Kledzik 94174f755c [mach-o] Support -filelist option in darwin driver
The darwin linker has an option, heavily used by Xcode, in which, instead
of listing all input files on the command line, the input file paths are
written to a text file and the path of that text file is passed to the linker
with the -filelist option (similar to @file).

In order to make test cases for this, I generalized the -test_libresolution
option to become -test_file_usage.

llvm-svn: 215762
2014-08-15 19:53:41 +00:00
Nick Kledzik 2d835dad0a [mach-o] Support -F and -framework options in darwin driver
Darwin has a packaging mechanism for shared libraries and headers called
frameworks.  A directory Foo.framework contains a shared library binary file
"Foo" and a subdirectory "Headers". Most OS frameworks are all in one
directory /System/Library/Frameworks/.  As a linking convenience, the linker
option "-framework Foo" means search the framework directories specified
with -F (analogous to -L) looking for a shared library Foo.framework/Foo.

llvm-svn: 215680
2014-08-14 22:20:41 +00:00
Nick Kledzik 8fc67fba01 [mach-o] Support re-exported dylibs
In general two-level namespace means each program records exactly which dylib
each undefined (imported) symbol comes from.  But, sometimes the implementor
wants to hide the implementation dylib.  For instance libSytem.dylib is the base
dylib all Darwin programs must link with.  A few years ago it was split up
into two dozen dylibs by all are hidden behind libSystem.dylib which re-exports
each sub-dylib.  All clients still think libSystem.dylib is the implementor.

To support this, the linker must load "indirect" dylibs and not just the
"direct" dylibs specified on the command line.  This is done in the
createImplicitFiles() method after all command line specified files are
loaded.  Since an indirect dylib may have already been loaded as a direct dylib
(or indirectly via a previous direct dylib), the MachOLinkingContext keeps
a list of all loaded dylibs.

With this change hello world can now be linked against the real OS or SDK.

llvm-svn: 215605
2014-08-13 23:55:41 +00:00
Nick Kledzik ebf09360ec [mach-o] Fix stub generation to work for dylibs and bundles
Split up the CRuntimeFile into one part for output types that need an entry
point and another part for output types that use stubs.

Add file 'test/mach-o/Inputs/libSystem.yaml' for use by test cases that
use -dylib and therefore may now need the helper symbol in libSystem.dylib.

llvm-svn: 215602
2014-08-13 23:31:07 +00:00
Nick Kledzik b47683223f [mach-o] set ordinal in n_desc for undefined symbols
Mach-o uses "two-level namespace" where each undefined symbols is associated
with a specific dylib. This means at runtime the loader (dyld) does need to
search all loaded dylibs for that symbol but rather just the one specified.

Now that llvm-nm -m prints out that info, properly set that info, and test
it in the hello world test cases.

llvm-svn: 215598
2014-08-13 23:11:42 +00:00
Hans Wennborg d2228c0f72 AArch64: replace __func__ with LLVM_FUNCTION_NAME
MSVC doesn't define __func__.

llvm-svn: 215578
2014-08-13 21:08:39 +00:00
Chad Rosier 0a5eb23bbd Remove unused private fields from r215544 to appease buildbots.
llvm-svn: 215547
2014-08-13 13:57:24 +00:00
Chad Rosier 69e2881070 [AArch64] Initial ELF/AArch64 Support
This patch adds the initial ELF/AArch64 support to lld. Only a basic "Hello
World" app has been successfully tested for both dynamic and static compiling.

Differential Revision: http://reviews.llvm.org/D4778
Patch by Daniel Stewart <stewartd@codeaurora.org>!

llvm-svn: 215544
2014-08-13 13:16:38 +00:00
Daniel Sanders df153c1a7e [mips] Remove .end and .end from test/elf/Mips/hilo16-3.test
The commit of the .ent/.end implementation will change the result of the
relocation evaluations (because of a new section and additional relocations)
which will lead to a failure if the .ent/.end directives are present in this
test.
We don't really need the .ent/.end directives in this test so let's just remove
them to preserve the current output.

llvm-svn: 215534
2014-08-13 10:04:59 +00:00
Rui Ueyama bff29b78b5 [PECOFF] Fix /profile option.
/profile implies /fixed:no -- so we had to *enable* base
relocations rather than disabling it.

llvm-svn: 215389
2014-08-11 21:31:07 +00:00
Rui Ueyama 57a2953ba0 Fix mach-o tests on Windows
The tests assume the path separator is '/', but if you run
them on Windows it is '\'. As a result the tests are failing
on Windows. This should be the minimal change to make these
tests to pass on Windows platform.

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

llvm-svn: 214990
2014-08-06 19:37:35 +00:00
Dan Liew 7f1a97bda0 Fix missing favicon.ico warning (Sphinx 1.2.2). The comments next to
``html_favicon`` seem to conflict with [what it in the sphinx
docs](http://sphinx-doc.org/config.html#confval-html_favicon).

So I've copied the comments from there to conf.py and changed its
value appropriately to remove the missing favicon.ico warning.

llvm-svn: 214971
2014-08-06 14:37:00 +00:00
Dan Liew ce5377afa0 Fix sphinx warning.
llvm-svn: 214968
2014-08-06 14:11:47 +00:00
Rui Ueyama ce49b5ba98 [PECOFF] Exported symbols are dead-strip roots.
llvm-svn: 214948
2014-08-06 03:29:17 +00:00
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