Commit Graph

631 Commits

Author SHA1 Message Date
Shankar Easwaran 2e20049260 [ELF] Fix conditions for max-page-size.
Fix comments from Rui, also adds a test.

llvm-svn: 221860
2014-11-13 04:03:46 +00:00
Shankar Easwaran b43804b6f4 [ELF] Fix max-page-size option.
The user can use the max-page-size option and set the maximum page size. Dont
check for maximum allowed values for page size, as its what the kernel is
configured with.

Fix the test as well.

llvm-svn: 221858
2014-11-13 03:25:38 +00:00
Shankar Easwaran 1987862287 [Gnu][Driver] Use StringRef conversion functions
llvm-svn: 221648
2014-11-11 00:40:32 +00:00
Shankar Easwaran 7757f1ace6 [Gnu] Support --image-base option
The value for --image-base is used as the base address of the program.

llvm-svn: 221589
2014-11-10 14:55:21 +00:00
Shankar Easwaran 78aa81d6ed [Gnu] Add options that are ignored
Add options that are ignored and exists just for compatibility reasons.

llvm-svn: 221585
2014-11-10 14:54:49 +00:00
Shankar Easwaran ba154afa06 [ELF] Support -z max-page-size option
The GNU linker allows the user to change the page size by using the option -z
max-page-size.

llvm-svn: 221584
2014-11-10 14:54:43 +00:00
Shankar Easwaran 22c76a5d79 [ELF] Support --no-align-segments.
lld generates an ELF by adhering to the ELF spec by aligning vma/fileoffset to a
page boundary, but this becomes an issue when dealing with large pages. This
adds support so that lld generated executables adheres to the ELF spec with the
rule vma % p_align = offset % p_align.

This is supported by the flag --no-align-segments.

This could be the default in few targets like X86_64 to save space on disk.

llvm-svn: 221571
2014-11-08 03:44:49 +00:00
Nick Kledzik f04ab0a244 [mach-o] Fix MachOFileNode to own archives same as ELFFileNode
My previous fix to have FileArchive own the member MemoryBuffers was not a
complete solution for darwin because nothing owned the FileArchive object.
Fixed MachOFileNode to be like ELFFileNode and have the graph node own the
archive object.

llvm-svn: 221552
2014-11-07 22:00:23 +00:00
Nick Kledzik 82d24bc932 [mach-o] Add support for -order_file option
The darwin linker lets you rearrange functions and data for better locality
(less paging).  You do this with the -order_file option which supplies a text
file containing one symbol per line.

Implementing this required a small change to LayoutPass to add a custom sorter
hook.

llvm-svn: 221545
2014-11-07 21:01:21 +00:00
Nick Kledzik babee83257 remove unneeded { }
llvm-svn: 221478
2014-11-06 19:33:59 +00:00
Nick Kledzik 24f504001d [mach-o] Add support for -force_load option
The darwin linker has two ways to force all members of an archive to be loaded.
The -all_load option applies to all static libraries.  The -force_load takes
a path to a library and just that library's members are force loaded.

llvm-svn: 221477
2014-11-06 19:33:57 +00:00
Nick Kledzik 8f75da0db3 [mach-o] Add support for -S option
The darwin linker does not process dwarf debug info.  Instead it produces a
"debug map" in the output file which points back to the original .o files for
anything that wants debug info (e.g. debugger).

The -S option means "don't add a debug map".  lld for mach-o currently does
not generate the debug map, so there is nothing to do when this option is used.
But we need to process the option to get existing projects building.

llvm-svn: 221432
2014-11-06 03:03:42 +00:00
Nick Kledzik 80118548d2 Fix shadowed variable warning
llvm-svn: 221414
2014-11-05 23:40:04 +00:00
Rafael Espindola 5a899e332b Use llvm::sys::findProgramByName. NFC.
llvm-svn: 221257
2014-11-04 12:34:32 +00:00
Nick Kledzik cb955ae1a5 [mach-o] Turn -single_module error into a warning
To be more compatible with existing darwin linker.

llvm-svn: 220822
2014-10-28 21:11:02 +00:00
Rui Ueyama 8bae8189b2 [PECOFF] Fix exported symbol in the import library
There are two ways to specify a symbol to be exported in the module
definition file.

1) EXPORT <external name> = <symbol>
2) EXPORT <symbol>

In (1), you give both external name and internal name. In that case,
the linker tries to find a symbol using the internal name, and write
that address to the export table with the external name. Thus, from
the outer world, the symbol seems to be exported as the external name.

In (2), internal name is basically the same as the external name
with an exception: if you give an undecorated symbol to the EXPORT
directive, and if the linker finds a decorated symbol, the external
name for the symbol will become the decorated symbol.

LLD didn't implement that exception correctly. This patch fixes that.

llvm-svn: 220333
2014-10-21 21:41:28 +00:00
Nick Kledzik a721db24c0 Subclass InputGraph to get darwin linker library semantics
The darwin linker operates differently than the gnu linker with respect to
libraries. The darwin linker first links in all object files from the command
line, then to resolve any remaining undefines, it repeatedly iterates over
libraries on the command line until either all undefines are resolved or no
undefines were resolved in the last pass.

When Shankar made the InputGraph model, the plan for darwin was for the darwin
driver to place all libraries in a group at the end of the InputGraph. Thus
making the darwin model a subset of the gnu model. But it turns out that does
not work because the driver cannot tell if a file is an object or library until
it has been loaded, which happens later.

This solution is to subclass InputGraph for darwin and just iterate the graph
the way darwin linker needs.

llvm-svn: 220330
2014-10-21 21:14:11 +00:00
Shankar Easwaran 1b44519a6c [Gnu] Move certain options to a different group.
The -mllvm option is not specific to LTO.

llvm-svn: 220263
2014-10-21 04:02:32 +00:00
Shankar Easwaran 3dadd20fe5 [ELF] Implement demangle.
This adds functionality in the GNU flavor to demangle symbols when
undefined symbols are displayed to the user.

llvm-svn: 220184
2014-10-20 05:04:53 +00:00
Shankar Easwaran 2b67fca033 Sort include files according to convention.
llvm-svn: 220131
2014-10-18 05:33:55 +00:00
NAKAMURA Takumi 8c38df4e9e [CMake] lld: Introduce ${cmake_2_8_12_INTERFACE} onto each target_link_libraries. [PR20254]
FIXME: Dependencies should be reorganized.
llvm-svn: 220000
2014-10-17 00:37:49 +00:00
Nick Kledzik 3a118aa344 [mach-o] Fix crash when -all_load used with dylibs
-all_load tells the darwin linker to immediately load all members of all
archives.  The code do that used reinterpret_cast<> instead of dyn_cast<>.
If the file was a dylib, the reinterpret_cast<> turned a pointer to a dylib
into a pointer to an archive...boom.

Added test case to reproduce the crash, simplified the code and used dyn_cast<>.

llvm-svn: 219990
2014-10-16 23:42:42 +00:00
Nick Kledzik 5172067391 [mach-o] Add support for upward linking
To deal with cycles in shared library dependencies, the darwin linker supports
marking specific link dependencies as "upward".  An upward link is when a
lower level library links against a higher level library.

llvm-svn: 219949
2014-10-16 19:31:28 +00:00
Rui Ueyama b38b96ab4c [PECOFF] Support delay-load import table for x86
This patch creates the import address table and sets its
address to the delay-load import table. This also creates
wrapper functions for __delayLoadHelper2.

x86 only for now.

llvm-svn: 219948
2014-10-16 19:30:44 +00:00
Rui Ueyama 7be03d09cd [PECOFF] Emit the delay-import table
This is a partial patch to emit the delay-import table. With this,
LLD is now able to emit the table that llvm-readobj can read and
dump.

The table lacks a few fields, such as the address of HMODULE, the
import address table, etc. They'll be added in subsequent patches.

llvm-svn: 219384
2014-10-09 02:48:14 +00:00
Rui Ueyama ecbb309e5e [PECOFF] Remember DLL names given with /delayload option.
This is a step toward full support of /delayload.

llvm-svn: 219344
2014-10-08 21:38:10 +00:00
Rafael Auler ce1af1a201 [ELF] Implement --export-dynamic/-E
When creating a dynamic executable and receiving the -E flag, the linker should
export all globally visible symbols in its dynamic symbol table.

This commit also moves the logic that exports symbols in the dynamic symbol
table from OutputELFWriter to the ExecutableWriter class. It is not correct to
leave this at OutputELFWriter because DynamicLibraryWriter, another subclass of
OutputELFWriter, already exports all symbols, meaning we can potentially end up
with duplicated symbols in the dynamic symbol table when creating shared libs.

Reviewers: shankarke

http://reviews.llvm.org/D5585

llvm-svn: 219334
2014-10-08 18:54:26 +00:00
Rui Ueyama 0bc6d5f97d Fix typo in comment
llvm-svn: 219326
2014-10-08 17:50:15 +00:00
Shankar Easwaran c3550f9231 Add support to print version.
Summary: Add support in the universal driver to print the lld version and the
repository version.

Test Plan: A driver test is added

Reviewers: kledzik, ruiu

Reviewed By: ruiu

Subscribers: llvm-commits

Projects: #lld

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

llvm-svn: 219277
2014-10-08 03:47:51 +00:00
Nick Kledzik 14b5d208cb [mach-o] Support fat archives
mach-o supports "fat" files which are a header/table-of-contents followed by a
concatenation of mach-o files (or archives of mach-o files) built for
different architectures.  Previously, the support for fat files was in the
MachOReader, but that only supported fat .o files and dylibs (not archives).

The fix is to put the fat handing into MachOFileNode.  That way any input file
kind (including archives) can be fat.  MachOFileNode selects the sub-range
of the fat file that matches the arch being linked and creates a MemoryBuffer
for just that subrange.

llvm-svn: 219268
2014-10-08 01:48:10 +00:00
Rui Ueyama 8f0c803c26 [PECOFF] Infer machine type from input object file
If /machine option is omitted, the linker needs to infer that from
input object files. This patch implements that.

llvm-svn: 219180
2014-10-07 01:38:46 +00:00
Nick Kledzik 15eba696f6 [mach-o] add -iphoneos_version_min as alias for -ios_version_min
llvm-svn: 219041
2014-10-04 00:19:56 +00:00
Nick Kledzik 09d00bb4d7 [mach-o] Add support for -dependency_info command line option
This option is added by Xcode when it runs the linker.  It produces a binary
file which contains the file the linker used.  Xcode uses the info to
dynamically update it dependency tracking.

To check the content of the binary file, the test case uses a python script
to dump the binary file as text which FileCheck can check.

llvm-svn: 219039
2014-10-04 00:16:13 +00:00
Rui Ueyama 711471ea1e [PECOFF] Resolve __delayLoadHelper2 if /delayload is given
DLL delay importing is a feature to load a DLL lazily, instead of
at program start-up time.

If the feature is turned on with the /delayload flag, the linker
resolves the delay-load helper function. All function pointer table
entries for the DLL are initially pointing to the helper function.
When called, the function loads and resolves the DLL symbols using
dlopen-ish Windows system calls and then write the reuslts to the
function pointer table. The helper function is in "delayimp.lib".

Note that this feature is not completely implemented yet. LLD
also needs to emit the table that's consumed by the delay-load
helper function. That'll be done in another patch.

llvm-svn: 218943
2014-10-03 01:14:50 +00:00
Nick Kledzik 22c9073ada Add MachOLinkingContext parameter to MachOFileNode constructor.
No functionality change.  This removes a down-cast from LinkingContext to
MachOLinkingContext.

Also, remove const from LinkingContext::createImplicitFiles() to remove
the need for another const cast.  Seems reasonable for createImplicitFiles()
to need to modify the context (MachOLinkingContext does).

llvm-svn: 218796
2014-10-01 20:24:30 +00:00
Nick Kledzik be43d7ef29 [mach-o] Implement -demangle.
The darwin linker has the -demangle option which directs it to demangle C++
(and soon Swift) mangled symbol names. Long term we need some Diagnostics object
for formatting errors and warnings. But for now we have the Core linker just
writing messages to llvm::errs(). So, to enable demangling, I changed the
Resolver to call a LinkingContext method on the symbol name.

To make this more interesting, the demangling code is done via __cxa_demangle()
which is part of the C++ ABI, which is only supported on some platforms, so I
had to conditionalize the code with the config generated HAVE_CXXABI_H.

llvm-svn: 218718
2014-09-30 23:15:39 +00:00
Rui Ueyama fa67adc28d [PECOFF] Allow /export:<symbol>,PRTVATE.
PRIVATE option is also an undocumented feature.

llvm-svn: 218696
2014-09-30 20:09:31 +00:00
Rui Ueyama 3837e10002 [PECOFF] Fix /export option.
MSDN doesn't say about /export:foo=bar style option, but
it turned out MSVC link.exe actually accepts that. So we need that
too.

It also means that the export directive in the module definition
file and /export command line option are functionally equivalent.

llvm-svn: 218695
2014-09-30 20:03:11 +00:00
Nick Kledzik b166d45730 [mach-o] Move implementation of MachOFileNode::parse
Move method implementation from header file to .cpp file.  No functionality
change.

llvm-svn: 218639
2014-09-29 23:04:24 +00:00
Rui Ueyama de18f9657b [PECOFF] Keep unmangled name in the export table descriptor
The export table descriptor is a data structure to keep information
about the export table. It contains a symbol name, and the name may
or may not be mangled.

We need unmangled names for the export table, so we demangle them
before writing them to the export table.

Obviously this is not a correct round-trip conversion. That could
drop a leading underscore from a symbol because that's
indistinguishable from a mangled name.

What we need to do is to keep unmangled names. This patch does that.

llvm-svn: 218345
2014-09-24 00:55:15 +00:00
Rui Ueyama 251d9a34e2 [PECOFF] Simplify /machine option handling
/machine:ebc was previously recognized but rejected. Unknown architecture
names were handled differently but eventually rejected too. We don't need
to distinguish them.

llvm-svn: 218344
2014-09-24 00:21:45 +00:00
Rui Ueyama a3eff3afd9 Make -core/-flavor options have higher priority than linker name
Also allows -core/flavor to appear at any position in the command line.
Patch from Oleg Ranevskyy!

http://reviews.llvm.org/D5384

llvm-svn: 218321
2014-09-23 18:09:38 +00:00
Rui Ueyama 117ef70c98 [PECOFF] Handle PRIVATE keyword in the module definition file
A symbol in a module definition file may be annotated with the
PRIVATE keyword like this.

  EXPORTS
    func PRIVATE

The PRIVATE keyword does not affect the resulting .dll file.
But it prevents the symbol to be listed in the .lib (import
library) file.

llvm-svn: 218273
2014-09-22 20:50:46 +00:00
Saleem Abdulrasool c2c2937d55 Driver: accept /machine:arm for Windows linker
Accept /machine:arm as an argument.  This is changed to support ARM NT.
Although there is no way to differentiate between ARM (Windows CE) and ARM NT
(Windows on ARM), since LLVM currently only supports Windows on ARM, simply take
/machine:arm to mean Windows on ARM.

llvm-svn: 218105
2014-09-19 06:09:30 +00:00
Rui Ueyama f47c7fab71 Make anonymous namespace as small as possible.
LLVM coding style says that "static" is preferred for file-scope
functions.

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

llvm-svn: 217692
2014-09-12 17:30:13 +00:00
Nick Kledzik ad0184056f [mach-o] support "0x" or "0X" as prefix on hex numbers on command line
This matches the strtoull() behavior in ld64.

llvm-svn: 217650
2014-09-12 00:16:29 +00:00
Tim Northover 1684a614b3 [mach-o]: support optional "0x" prefix for -image_base
llvm-svn: 217578
2014-09-11 10:31:46 +00:00
Tim Northover 5d95bd7037 [mach-o]: tighten up diagnostics for -image_base option
The provided base must also be a multiple of the system's page size, which is a
reasonable enough demand.

Also check the other diagnostics more thoroughly.

llvm-svn: 217577
2014-09-11 10:31:42 +00:00
Tim Northover 7b33f21f3d [mach-o]: Support deprecated -seg1addr alias for -image_base
Because NO LINKER MAY CHANGE. EVER. Even if it's a complete rewrite
from scratch.

llvm-svn: 217572
2014-09-11 07:56:20 +00:00
Rui Ueyama a726ef12a4 Make getFlavor function.
The dangling "else" at the end of #if looked a bit error-prone.
Make it a separate function. No functionality change.

llvm-svn: 217568
2014-09-11 03:13:20 +00:00
Nick Kledzik 50bda292c8 If lld is renamed (or symlinked) to "ld" automatically pick the right flavor.
The existing system linkers on Darwin and Linux are called "ld".  We'd like to
eventually drop in lld as "ld" and have it just work.  But lld is a universal
linker that requires the first option to be -flavor to know which command line
mode to emulate (gnu or darwin).

This change tests if argv[0] is "ld" and if so, if the tool was built on MacOSX
then assume the darwin flavor otherwise the gnu flavor.  There are two test
cases which copy lld to "ld" and then run it. One for darwin and one for linux.

llvm-svn: 217566
2014-09-11 00:52:05 +00:00
Tim Northover 936e053da0 [MSVC]: use StringRef::getAsInteger instead of strtoull
This keeps non-conformant MSVC implementations happy.

llvm-svn: 217491
2014-09-10 11:15:36 +00:00
Tim Northover af3075b93f [mach-o]: implement -image_base option on Darwin.
As suggested by Nick, this will make __unwind_info implementation more natural,
and it'd have to be done at some point anyway.

llvm-svn: 217486
2014-09-10 10:39:57 +00:00
Nick Kledzik 1944bb6cf9 [mach-o] Fix missing { }
llvm-svn: 217411
2014-09-09 02:20:32 +00:00
Nick Kledzik 4ce63c2a54 [mach-o] Fix so no options causes usage message to be printed
llvm-svn: 217409
2014-09-09 00:45:35 +00:00
Nick Kledzik b7035ae367 [mach-o] Add support for -pie and -no_pie
There is a bit (MH_PIE) in the flags field of the mach_header which tells
the kernel is a program was built position independent (for ASLR).  The linker
automatically attempts to build programs PIE if they are built for a recent
OS version.  But the -pie and -no_pie options override that default behavior.

llvm-svn: 217408
2014-09-09 00:17:52 +00:00
Shankar Easwaran c7701e9a8c [ELF][Driver] Produce a proper error when file is not found
When a file is not found, produce a proper error message. The previous error
message produced a file format error, which made me wonder for a while why
there is a file format error, but essentially the file was not found.

This fixes the problem by producing a proper error message.

llvm-svn: 217359
2014-09-08 04:18:11 +00:00
Shankar Easwaran 595e056dce [ELF] Implement --rosegment
By default linker would not create a separate segment to hold read only data.

This option overrides that behavior by creating the a separate read only segment
for read only data.

llvm-svn: 217358
2014-09-08 04:05:52 +00:00
Shankar Easwaran 24511fc426 [ELF] Undefined symbols should be allowed when building dynamic libraries
When dynamic libraries are built, undefined symbols should always be allowed and
the linker should not exit with an error.

llvm-svn: 217356
2014-09-08 03:11:50 +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
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
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 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
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
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 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
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
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
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
Nick Kledzik 0f4fbf17f5 [mach-o] wire up -t option
llvm-svn: 214414
2014-07-31 18:19:03 +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
Rui Ueyama 55a6e762ee [PECOFF] Add /profile command line option.
llvm-svn: 213984
2014-07-25 22:28:49 +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 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 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
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
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
Rui Ueyama aea2bcf559 [PECOFF] s/context/ctx/ for consistency.
llvm-svn: 212766
2014-07-10 21:55:28 +00:00
Rui Ueyama 31fd9d09b2 [PECOFF] Invoke cvtres.exe in the driver.
Previously we invoked cvtres.exe for each compiled Windows
resource file. The generated files were then concatenated
and embedded to the executable.

That was not the correct way to merge compiled Windows
resource files. If you just concatenate generated files,
only the first file would be recognized and the rest would
be ignored as trailing garbage.

The right way to merge them is to call cvtres.exe with
multiple input files. In this patch we do that in the
Windows driver.

llvm-svn: 212763
2014-07-10 20:53:37 +00:00
Tim Northover 73c532e8a9 [mach-o]: support -Z option to skip standard library paths
llvm-svn: 212713
2014-07-10 11:46:13 +00:00
Tim Northover 18af0573df [mach-o]: support user-specified (-L) library search paths
llvm-svn: 212712
2014-07-10 11:46:08 +00:00
Tim Northover 77d82202d1 [mach-o]: support -syslibroot and -l options
These behave slightly idiosyncratically in the best of cases, and have
additional hacks layered on top of that for compatibility with badly behaved
build systems (via ld64).

For -lXYZ:
  + If XYZ is actually XY.o then search all library paths for XY.o
  + Otherwise search all library paths, first for libXYZ.dylib, then libXYZ.a
  + By default the library paths are /usr/lib and /usr/local/lib in that order.

For -syslibroot:
  + -syslibroot options apply to absolute paths in the search order.
  + All -syslibroot prefixes that exist are added to the search path *instead*
    of the original.
  + If no -syslibroot prefixed path exists, the original is kept.
  + Hacks^WExceptions:
      + If only 1 -syslibroot is given and doesn't contain /usr/lib or
        /usr/local/lib, that path is dropped entirely. (rdar://problem/6438270).
      + If the last -syslibroot is "/", all of them are ignored entirely.
        (rdar://problem/5829579).

At least, that's my best interpretation of what ld64 does in buildSearchPaths.

llvm-svn: 212706
2014-07-10 11:21:06 +00:00
Tim Northover b44143f496 [all]: Use range-based ArgList adapter instead of filtered_begin/filtered_end
Some of those loops were pretty monstrous.

llvm-svn: 212616
2014-07-09 13:03:54 +00:00
Rafael Espindola c2199ecf1e Update for llvm api change.
llvm-svn: 212407
2014-07-06 17:43:22 +00:00
Tim Northover 9bdf90e5c2 [mach-o]: make the default dylib install-name the output filename.
llvm-svn: 212094
2014-07-01 08:41:45 +00:00
Simon Atanasyan 65e2464667 [Driver] Improve the `isPathUnderSysroot()` function. Now it returns a
correct result even if checking paths: a) symlinks and/or b) contains relative
parts like /dir1/dir2/../dir2.

llvm-svn: 211772
2014-06-26 10:48:52 +00:00
Tim Northover d30a1f2cb2 MachO: rename _outputFileType to avoid shadowing parent field.
llvm-svn: 211367
2014-06-20 15:59:00 +00:00
Rafael Espindola 372bc70c63 Update for llvm api change.
llvm-svn: 210919
2014-06-13 17:20:48 +00:00
Rafael Espindola b1a4d3a26c Don't import error_code into the lld namespace.
llvm-svn: 210785
2014-06-12 14:53:47 +00:00
Rafael Espindola 7b8b9ae1cb Use std::error_code instead of llvm::error_code.
This is an update for a llvm api change.

llvm-svn: 210689
2014-06-11 19:05:58 +00:00
Simon Atanasyan 6790b14ebb [ELF] Fix the bug -- LLD crashes if the --whole-archive option
is around non-archive.

llvm-svn: 210530
2014-06-10 13:43:13 +00:00
Iain Sandoe c4d9bedcfc Initial set of Makefiles
This provides support for the autoconfing & make build style.
The format, style and implementation follows that used within the llvm and clang projects.

TODO: implement out-of-source documentation builds.
llvm-svn: 210177
2014-06-04 09:54:07 +00:00
Rafael Espindola 63ed1a3519 Use error_code() instead of error_code::succes()
There is no std::error_code::success, so this removes much of the noise
in transitioning to std::error_code.

llvm-svn: 209948
2014-05-31 01:22:21 +00:00
Nick Kledzik 0224e3475d Add -print_atoms options to DarwinLdDriver which dumps final state of all atoms in yaml
llvm-svn: 208813
2014-05-14 21:32:21 +00:00
Rui Ueyama c7c47681f6 Revert "temporary commit."
This reverts accidental commit r208427.

llvm-svn: 208433
2014-05-09 16:47:20 +00:00
Rui Ueyama 1127fe4704 [PECOFF] DLL extension can be omitted in .def file.
llvm-svn: 208428
2014-05-09 16:35:26 +00:00
Rui Ueyama 4e0b17dd3c temporary commit.
llvm-svn: 208427
2014-05-09 16:35:23 +00:00
Rui Ueyama b13cda8f3e Call normalize() in the common driver.
Previously only GNU driver calls InputGraph::normalize, but its
functionality is not and should not be limited to GNU ld. Other
driver should be able to use it.

Currently only linker scripts use the feature, so this change
won't change the existing behavior.

llvm-svn: 208266
2014-05-07 23:33:48 +00:00
Rui Ueyama d6a0604180 Trivial simplification
llvm-svn: 208145
2014-05-07 00:04:48 +00:00
Rui Ueyama 0e363b75a4 [PECOFF] Support =internalName syntax in .def file.
Export definitions in a module definition file is as follows:

  exportedname[=internalname] [@ordinal [NONAME]] [PRIVATE] [DATA]

Previously we did not support =internalname, so users couldn't export
symbols from a DLL with a different name.

llvm-svn: 207827
2014-05-02 03:43:51 +00:00
Joerg Sonnenberger c8f36d2d55 Sort.
llvm-svn: 207798
2014-05-01 21:40:22 +00:00
Simon Atanasyan ffc1c6af49 [ELF] Fix the file look up algorithm used in the linker script GROUP command.
In general the linker scripts's GROUP command works like a pair
of command line options --start-group/--end-group. But there is
a difference in the files look up algorithm.

The --start-group/--end-group commands use a trivial approach:
a) If the path has '-l' prefix, add 'lib' prefix and '.a'/'.so'
   suffix and search the path through library search directories.
b) Otherwise, use the path 'as-is'.

The GROUP command implements more compicated approach:
a) If the path has '-l' prefix, add 'lib' prefix and '.a'/'.so'
   suffix and search the path through library search directories.
b) If the path does not have '-l' prefix, and sysroot is configured,
   and the path starts with the / character, and the script being
   processed is located inside the sysroot, search the path under
   the sysroot. Otherwise, try to open the path in the current
   directory. If it is not found, search through library search
   directories.

https://www.sourceware.org/binutils/docs-2.24/ld/File-Commands.html

The patch reviewed by Shankar Easwaran, Rui Ueyama.

llvm-svn: 207769
2014-05-01 16:22:08 +00:00
Rui Ueyama e18ed4e16b [PECOFF] Add a test for lib.exe subcommand.
Previously the input file for the lib.exe command would be removed
as soon as the command exits, so we couldn't write a test to check
the file contents are correct.

This patch adds /lldmoduledeffile: option to retain a copy of the
temporary file at the given file path, so that you can see the file
if you want.

llvm-svn: 207727
2014-05-01 00:06:56 +00:00
Simon Atanasyan a64f34b759 [Driver] Check type of InputElement before request a error message. If the
element is a FileNode, request error description. If the element is Group,
print hard coded error message. We need to implement a better diagnostics
here but even current solution is better than a segmentation fault output.

llvm-svn: 207691
2014-04-30 19:04:01 +00:00
Simon Atanasyan 76d8d36c3c [Driver] Remove the redundant cast.
No functional changes.

llvm-svn: 207688
2014-04-30 19:03:45 +00:00
Simon Atanasyan e33f2add5d [Mips] Recognize MIPS emulation name 'elf32ltsmip'.
llvm-svn: 207687
2014-04-30 19:03:40 +00:00
Rui Ueyama f33946d51d [PECOFF] Allow multiple directives in one module-definition file.
I'm a bit surprised that I have not implemented this yet. This is
definitely needed to handle real-world module definition files.
This patch contains a unit test for r207294.

llvm-svn: 207297
2014-04-26 00:25:02 +00:00
Rui Ueyama 637300ea4e [PECOFF] Fix off-by-one error in .def file parser.
I'm fixing another bug in the parser, and I wanted to submit this
fix as a separate change as it's logically independent from the other.
I'll add a test for this shortly.

llvm-svn: 207294
2014-04-25 23:59:27 +00:00
Rui Ueyama 409ac186bb [PECOFF] Add /IMPLIB command line option.
This option is to override the default import file path.

llvm-svn: 207175
2014-04-25 03:35:13 +00:00
Rui Ueyama 0e32610fb5 [PECOFF] Better handling of /OPT option.
Previously LLD would fail if /OPT:icf, /OPT:lbr or such are specified,
because these command line flags would be handled as unknown ones. We
rather want LLD to ignore these known but yet-to-be-implemented options
for now.

Added tests for the driver as well.

llvm-svn: 206863
2014-04-22 03:57:07 +00:00
Rui Ueyama f171ace07d [PECOFF] Handle line comment in module-definition file.
In .def files, ';' is the start of line comment.

llvm-svn: 206831
2014-04-22 00:11:52 +00:00
Rui Ueyama 311a162f26 [PECOFF] Win64 DLL entry function name is _DllMainCRTStartup.
Unlike Win32/x86, it has no "@12" suffix.

llvm-svn: 206648
2014-04-18 21:05:59 +00:00
Rui Ueyama 83743ccca4 [PECOFF] Support LIBRARY directive.
LIBRARY directive in a module definition file specifies the output
DLL file name. It also takes an optional value for the base address.

llvm-svn: 206647
2014-04-18 20:48:20 +00:00
Rui Ueyama a2b0334e93 Use switch for readability.
llvm-svn: 206638
2014-04-18 19:59:33 +00:00
Rui Ueyama 28da676709 [PECOFF] Ignore /ignore option.
/ignore:<number> is a linker option to disable warning specified by
the number. We ignore the option because it does not make sense for
LLD.

llvm-svn: 206636
2014-04-18 19:49:24 +00:00
Rui Ueyama 38cf6ddc30 [PECOFF] Support /manifestuac:NO.
If the value for /manifestuac is "NO", LLD will create a manifest XM
file but won't emit <trustinfo> element.

llvm-svn: 206633
2014-04-18 19:43:07 +00:00
Rui Ueyama 327db80dd5 [ELF] Support --defsym=<symbol>=<symbol>.
Currently LLD supports --defsym only in the form of
--defsym=<symbol>=<integer>, where the integer is interpreted as the
absolute address of the symbol. This patch extends it to allow other
symbol name to be given as an RHS value. If a RHS value is a symbol
name, the LHS symbol will be defined as an alias for the RHS symbol.

Internally, a LHS symbol is represented as a zero-size defined atom
who has an LayoutAfter reference to an undefined atom, whose name is
the RHS value. Everything else is already implemented -- Resolver
will resolve the undefined symbol, and the layout pass will layout
the two atoms at the same location. Looks like it's working fine.

Note that GNU LD supports --defsym=<symbol>=<symbol>+<addend>. That
feature is out of scope of this patch.

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

llvm-svn: 206417
2014-04-16 20:58:57 +00:00
Benjamin Kramer afa371debb Add missing includes.
llvm-svn: 206113
2014-04-12 16:32:42 +00:00
Rui Ueyama e6c499acd7 Early continue to reduce nesting.
llvm-svn: 205737
2014-04-07 21:13:33 +00:00
Rui Ueyama 5de951d8c1 No else after return.
llvm-svn: 205736
2014-04-07 21:01:11 +00:00
Rui Ueyama 595026e071 [ELF] Accept "-rpath=<foo>" as well as "-rpath <foo>".
llvm-svn: 205694
2014-04-06 21:23:24 +00:00
Rui Ueyama c141c8c59a [ELF] Fix driver bug.
GNU LD-comptaible driver wrongly requires a space after '=' for a few
options such as "-init=<symbol>" or "-entry=<symbol>". This patch is
to fix that bug and add a few tests for it.

llvm-svn: 205693
2014-04-06 21:15:05 +00:00
Rui Ueyama ac0f7ca3a8 [ELF] Fix --soname option.
Currently LLD accepts only "-soname <string>", but all the following
options are actually valid.

  --soname=foo
  --soname foo
  -soname=foo
  -soname foo
  -h foo

This patch fixes that issue.

llvm-svn: 205662
2014-04-05 02:07:04 +00:00
Rui Ueyama e36fbea175 [ELF] Diagnose malformed --dynsym option.
llvm-svn: 205654
2014-04-04 22:36:30 +00:00
Rui Ueyama 8bd093b1e5 Rename getInputGraph() and getNextFile().
Seems getSomething() is more common naming scheme than just a noun
to get something, so renaming these members.

Differential Revision: http://llvm-reviews.chandlerc.com/D3285

llvm-svn: 205589
2014-04-04 00:14:04 +00:00
Rui Ueyama 69fcde8b0a Expand 'auto' that's hard for human to deduce its real type.
llvm-svn: 205564
2014-04-03 20:47:50 +00:00
Rui Ueyama b0e3b66fa5 Remove ordinals from Input Graph elements.
An ordinal is set to each child of Input Graph, but no one actually
uses it. The only piece of code that gets ordinaly values is
sortInputElements in InputGraph.cpp, but it does not actually do
anything -- we assign ordinals in increasing order just before
calling sort, so when sort is called it's already sorted. It's no-op.
We can simply remove it. No functionality change.

Differential Revision: http://llvm-reviews.chandlerc.com/D3270

llvm-svn: 205501
2014-04-03 02:21:44 +00:00
Rui Ueyama f819851b65 Fix style.
llvm-svn: 205490
2014-04-03 00:01:57 +00:00
Rui Ueyama 519a45ce36 Minor style fix.
llvm-svn: 205486
2014-04-02 23:17:39 +00:00
Shankar Easwaran bef1f22aaa [TODO] revisit features TODO in the driver
llvm-svn: 205395
2014-04-02 05:45:52 +00:00
Shankar Easwaran 086f8a6ef5 [ELF] Create Attribute class associated with Input files.
The attribute class holds positional attributes for Input files specified on the
command line for the Gnu flavor.

llvm-svn: 205392
2014-04-02 03:57:39 +00:00
Shankar Easwaran a00abba152 [ELF] Add -z muldefs option.
This adds -z muldefs option which is widely used over
--allow-multiple-definition.

This option is supported by the GNU linker.

llvm-svn: 205391
2014-04-02 03:57:37 +00:00
Rui Ueyama 2243015825 Merge ELFGroup with Group.
Group class is designed for GNU LD's --start-group and --end-group. There's
no obvious need to have two classes for it -- one as an abstract base class
and the other as a concrete class.

llvm-svn: 205375
2014-04-01 23:55:20 +00:00
Rui Ueyama ce749af25b Rename insertOneElementAt -> insertElementAt.
insertElementsAt() is removed, so "One" in insertOneElementAt() no longer
make much sense. Rename it for brevity.

llvm-svn: 205372
2014-04-01 23:17:28 +00:00
Rui Ueyama 5632e26d36 Greatly simplify InputGraph.
InputGraph has too many knobs and controls that are not being used. This
patch is to remove dead code, unused features and a class. There are two
things that worth noting, besides simple dead code removal:

1. ControlNode class is removed. We had it as the base class of Group
class, but it provides no functionality particularly meaningful. We now
have shallower class hierarchy that is easier to understand.

2. InputGraph provides a feature to replace a node with its internal data.
It is being used to "expand" some type of node, such as a Linker Script
node, with its actual files. We used to have two options when replacing
it -- ExpandOnly or ExpandAndReplace. ExpandOnly was to expand it but not
remove the node from the tree. There is no use of that option in the code,
so it was a dead feature.

Differential Revision: http://llvm-reviews.chandlerc.com/D3252

llvm-svn: 205363
2014-04-01 21:55:36 +00:00
Rui Ueyama 068fc01234 Remove dynamic casts.
Asserting with cast<T> did not actually make much sense because there was no
need to use dynamic casting in the first place. We could make the compiler to
statically type check these objects.

llvm-svn: 205350
2014-04-01 19:00:21 +00:00
Rui Ueyama 46fd56d0df s/dyn_cast/cast/ where return value should never be null.
cast<X> asserts the type is correct and does not return null on failure.
So we should use cast<X> rather than dyn_cast<X> at such places where we
don't expect type conversion could fail.

llvm-svn: 205332
2014-04-01 18:04:56 +00:00
Rui Ueyama e081e22036 [PECOFF] Make PECOFFFileNode::parse idempotent.
PECOFFFileNode::parse can be called twice -- once by WinLink driver and
once more by Driver. We want to make sure that the second call won't mess
up the internal data.

llvm-svn: 205284
2014-04-01 06:18:19 +00:00
Rui Ueyama 1e7d0721ae [PECOFF] Treat .imp as an import library file.
Some Clang build uses .imp not .lib file extension for an import library file,
so we need to treat such file as a library file.

Ideally we should not rely on file extensions to detect file type. Instead
we should use magic bytes at beginning of a file. The GNU-compatible driver
actually does that but it made writing unit tests hard, so I chose an ad-hoc
approach for now.

llvm-svn: 205283
2014-04-01 06:11:09 +00:00
Rui Ueyama aa6c9285f4 [ELF] Terminate argv with nullptr.
Also remove unused vector.

llvm-svn: 205052
2014-03-28 20:51:07 +00:00
Rui Ueyama 6d010e8d42 [ELF] Support response file.
Response file is a command line argument in the form of @file. The GNU-
compatible driver expands the file contents, replacing @file argument.

Differential Revision: http://llvm-reviews.chandlerc.com/D3210

llvm-svn: 205038
2014-03-28 19:34:34 +00:00
Rui Ueyama 3907f2a802 [ELF] Support --defsym option to define an absolute symbol.
This patch is to support --defsym option for ELF file format/GNU-compatible
driver. Currently it takes a symbol name followed by '=' and a number. If such
option is given, the driver sets up an absolute symbol with the specified
address. You can specify multiple --defsym options to define multiple symbols.

GNU LD's --defsym provides many more features. For example, it allows users to
specify another symbol name instead of a number to define a symbol alias, or it
even allows a symbol plus an offset (e.g. --defsym=foo+3) to define symbol-
relative alias. This patch does not support that, but will be supported in
subsequent patches.

Differential Revision: http://llvm-reviews.chandlerc.com/D3208

llvm-svn: 205029
2014-03-28 19:02:06 +00:00
Rui Ueyama a9a5129ec1 [ELF] Add --allow-multiple-definition option.
If --allow-multiple-definition option is given, LLD does not treat duplicate
symbol error as a fatal error. GNU LD supports this option.

Differential Revision: http://llvm-reviews.chandlerc.com/D3211

llvm-svn: 205015
2014-03-28 16:26:38 +00:00
Rui Ueyama 49f91b346c Replace nested switches with if.
llvm-svn: 204987
2014-03-28 03:29:01 +00:00
Rui Ueyama 14a1e0c0fc Remove extraneous parentheses.
llvm-svn: 204986
2014-03-28 03:26:24 +00:00
Rui Ueyama 9024c36f5a Make anonymous namespace as small as possible.
llvm-svn: 204982
2014-03-27 23:34:32 +00:00
Rui Ueyama 69a6f0e79a [PECOFF] Avoid C-style cast.
llvm-svn: 204855
2014-03-26 21:10:40 +00:00
Rui Ueyama 9e8ac37d89 [PECOFF] Use RAII object for mutex.
llvm-svn: 204853
2014-03-26 21:08:17 +00:00
Rui Ueyama 85093df3bd [PECOFF] Print out command line if we have expanded response files.
If a response file is given via command line, the final command line
arguments will not appear in the log because the actual arguments are
in the given file.

This patch is to show the final command line if /verbose is specified
to help users.

llvm-svn: 204754
2014-03-25 20:40:27 +00:00
Rui Ueyama 83ba74fa3f [PECOFF] Rename link.exe -> lld-link.exe.
Creating the file "link.exe" made some confusion, so it's better to
name it lld-link.exe, as we did for CL (clang-cl.exe).

llvm-svn: 204509
2014-03-21 20:41:48 +00:00
Rui Ueyama b4c358fab8 [PECOFF] Fix possible response file buffer overrun.
Response file is not NUL terminated, so when creating a StringRef for
the buffer contents, we need to pass the buffer size as well as the
pointer pointing to the buffer.

llvm-svn: 204420
2014-03-21 00:48:26 +00:00
Rui Ueyama bc6b52e68e Move RoundTrip tests behind LLVM_RUN_ROUNDTRIP_TEST env flag.
If the environment variable is defined and not empty, RoundTrip tests
are run. The reason to move the tests behind the flag is because they
are too slow to enable by default.

LLD linking time on llvm-tblgen improved from 2m7s to 2.3s. About 60x
faster now in this case.

Differential Revision: http://llvm-reviews.chandlerc.com/D3126

llvm-svn: 204296
2014-03-20 02:49:33 +00:00
Michael J. Spencer 05c152b5d1 [gnu-ld] Support -m on non-NetBSD targets.
llvm-svn: 204293
2014-03-20 01:28:36 +00:00
Rui Ueyama aca3c7c6f4 [PECOFF] Fix link order.
LLD fails to link symbol "_main" if the symbol is in a library file and
the library file is given as a bare argument (i.e. not with /defaultlib
option). It's because library files given as bare arguments are processed
before other libraries given with /defaultlib, so when Linker finds msvcrtd
needs a definition for "_main", the file providing the main function has
already been processed and skipped. Linker don't revisit libraries if it's
not given with /defaultlib.

To fix it this patch change the way of command line handling; files end with
".lib" are treated as if they are given with /defaultlib. I don't believe
it's 100% correct behavior but it's better than before.

llvm-svn: 203892
2014-03-14 05:59:16 +00:00
Rui Ueyama ebffa9b4be [PECOFF] Fix arguments passed to lib.exe.
llvm-svn: 203891
2014-03-14 05:04:08 +00:00
Rui Ueyama 516273ba99 [PECOFF] Make WinLinkDriver::parse() and allocate*() functions thread-safe.
Looks like a major cause of instability on Windows is this thread-safety bug.

llvm-svn: 203889
2014-03-14 04:28:38 +00:00
Rui Ueyama f88731f293 [PECOFF] Implement /lib option.
This option is not documented and seems weird, but yeah we need it anyway.

llvm-svn: 203884
2014-03-14 03:06:55 +00:00
Rui Ueyama 7d96f0cc38 Use short identifier, s/diagnostics/diag/.
llvm-svn: 203876
2014-03-14 00:38:34 +00:00
Rui Ueyama b3f679e1ab [PECOFF] Support response files.
If the driver finds a command line option in the form of "@filename", the
option will be replaced with the content of the given file. It's an error
if a response file cannot be read.

llvm-svn: 203875
2014-03-14 00:36:30 +00:00
Ahmed Charles 13c70b6d4b Replace OwningPtr with std::unique_ptr.
This results in some simplifications to the code where an OwningPtr had to
be used with the previous api and then ownership moved to a unique_ptr for
the rest of lld.

llvm-svn: 203809
2014-03-13 16:20:38 +00:00
Ahmed Charles d6432c8aed [Cleanup] Sort includes.
llvm-svn: 203666
2014-03-12 15:55:13 +00:00
Michael J. Spencer e1de2a39df [docs] Add list of missing GNU ld command line options.
llvm-svn: 203491
2014-03-10 21:25:43 +00:00
Ahmed Charles d779459f21 [C++11] Add #include's for OwningPtr.
Allows removing #include's in LLVM while switching to std::unique_ptr.

llvm-svn: 202679
2014-03-03 07:20:05 +00:00
Benjamin Kramer 3445d9edad [C++11] Work around an incompatibility between llvm::tie and std::tie.
llvm-svn: 202645
2014-03-02 13:45:18 +00:00
Rafael Espindola f27f9fa136 Update for LLVM api change.
llvm-svn: 202054
2014-02-24 18:20:36 +00:00
Rafael Espindola 27810169cb Don't assume that F_None is the default. It is about to change.
llvm-svn: 202039
2014-02-24 15:06:34 +00:00
Rui Ueyama d9e7c22ee4 [PECOFF] Driver support for /SAFESEH option.
Syntactically /SAFESEH is a boolean flag -- you can pass /SAFESEH or /SAFESEH:no.

The meaning of /SAFESEH is as follows.

 - If /SAFESEH is specified, the linker will produce an executable with SEH table.
   If any input files are not compatible with SEH, it's an error.
 - If /SAFESEH:no is specified, the linker will not emit SEH table even if all
   input files are compatible with SEH.
 - If no option is specified, the linker emits SEH table if all input files are
   compatible with SEH.

llvm-svn: 201895
2014-02-21 22:30:43 +00:00
Rui Ueyama c5326ca9bb [PECOFF] Add a TODO.
llvm-svn: 200599
2014-02-01 00:26:33 +00:00
Rui Ueyama 9661bcf2e1 [PECOFF] Handle /machine option before handling all the other options.
The target machine type affects the meaning of other options, in particular
how to mangle symbols. So we want to handle the option first and then parse
all the other options.

llvm-svn: 200589
2014-01-31 22:58:19 +00:00
Shankar Easwaran 3d8de47f76 Fix trailing whitespace.
llvm-svn: 200182
2014-01-27 03:09:26 +00:00
Shankar Easwaran e7b831ad35 [ELF] Add Target specific Readers.
No change in functionality.

llvm-svn: 200175
2014-01-27 01:02:03 +00:00
Rui Ueyama ab9deb5466 [PECOFF] Support STACKSIZE module-definition file directive.
llvm-svn: 199170
2014-01-14 00:48:25 +00:00
Rui Ueyama 415625028c [PECOFF] Support VERSION directive.
llvm-svn: 199022
2014-01-11 22:45:00 +00:00
Rui Ueyama 605f7791a3 Make anonymous namespace as small as possible.
llvm-svn: 199021
2014-01-11 22:15:54 +00:00
Rui Ueyama b214e1aba2 [PECOFF] Support NAME directive.
llvm-svn: 199020
2014-01-11 21:53:46 +00:00
Rui Ueyama 66a4445658 [PECOFF] Add a helper function to read an integer from .def file.
llvm-svn: 199019
2014-01-11 21:37:25 +00:00
Rui Ueyama 6cc96bf2d2 [PECOFF] Print a better error message for unknown module-definition file directive.
llvm-svn: 199018
2014-01-11 21:24:43 +00:00
Rui Ueyama 6a5f7c22ad [PECOFF] Support HEAPSIZE directive.
llvm-svn: 198994
2014-01-11 01:58:21 +00:00
Rui Ueyama f98a18acb7 [PECOFF] Refactor module-defintion file parser.
Refactor the parser so that the parser can return arbitrary type of parse
result other than a vector of ExportDesc. Parsers for non-EXPORTS directives
will be implemented in different patches. No functionality change.

llvm-svn: 198993
2014-01-11 01:33:42 +00:00
Rui Ueyama 8b14d14209 [PECOFF] Support module-definition file.
Module-definition (.def) files are the file containing linker directives,
such as export symbols. Because link.exe supports the same features as command
line options, just as some Linker Script commands overlaps with command line
options, use of module-definition file is not really necessary. It provides
an alternative way to specify some linker options.

This patch implements EXPORTS directive. Other directives will be implemented
in the future.

llvm-svn: 198925
2014-01-10 10:19:47 +00:00
Rafael Espindola d28918b289 Use getError instead of the error_code operator.
llvm-svn: 198797
2014-01-08 22:00:09 +00:00
Rui Ueyama 54174c6f16 [PECOFF] Simplify: Replace two-value enum with bool.
llvm-svn: 198634
2014-01-06 19:55:58 +00:00
Rui Ueyama 14133d5551 Replace nested switch statements.
Differential Revision: http://llvm-reviews.chandlerc.com/D2501

llvm-svn: 198535
2014-01-05 02:41:07 +00:00
Rui Ueyama 76bc5157c2 Use scoped enum.
llvm-svn: 198396
2014-01-03 03:29:15 +00:00
Joerg Sonnenberger 4dcee6960f Add default search path if -nostdlib is not provided.
Add basic emulation mapping for NetBSD/amd64, so that clang -m32 works
as expected.

llvm-svn: 198337
2014-01-02 19:18:36 +00:00
Rui Ueyama e6ed0f255f [PECOFF] Change the DLL entry symbol.
I'm not 100% sure but it looks like DLL entry symbol (DLL initializer function
name) should be _DllMainCRTStartup@12. The reason why I'm not very sure is
because I have no idea what "@12" suffix is, but without it the symbol won't
be resolved...

llvm-svn: 198072
2013-12-27 07:14:34 +00:00
Rui Ueyama 9e26f5f397 Fix comment.
llvm-svn: 198066
2013-12-27 02:51:53 +00:00
Rui Ueyama 610d90b283 [PECOFF] Do not accept "/include <string>" option.
Command line argument separator on Windows is colon. We used to accept space
as a separator, but we removed most of the code for that. This patch is to
delete the remaining code.

llvm-svn: 198032
2013-12-26 06:00:26 +00:00
Joey Gouly 2008d31d06 Fix copy/paste error.
llvm-svn: 197990
2013-12-24 20:43:54 +00:00
Rui Ueyama 090a7cd76d [PECOFF] Fix /export option in the .drectve section.
/EXPORT option has slightly different semantics if it appears in the .drectve
section. This patch implements it.

llvm-svn: 197970
2013-12-24 09:15:57 +00:00
Nick Kledzik 6960b07b92 [mach-o] add MachOLinkingContext::configure(type, arch, os)
It will configure resonable defaults for other settings in the 
MachOLinkingContext object based on the parameters.  

Patch by Joe Ranieri

llvm-svn: 197851
2013-12-21 01:47:17 +00:00
Nick Kledzik f30e848432 Restore vertical alignment lost by clang-format
llvm-svn: 197834
2013-12-20 20:34:19 +00:00