Commit Graph

675 Commits

Author SHA1 Message Date
Hans Wennborg 04632f1f16 [PECOFF] Handle "--" option explicitly
This used to be handled automagically by the option parsing library,
but after LLVM r188314, we should handle it ourselves.

No functionality change, but adds a test.

llvm-svn: 188318
2013-08-13 21:44:44 +00:00
Rui Ueyama 8432d32c67 [PECOFF] Treat the common symbol as mergeable symbol.
This is a temporary measure because the semantics of the common symbol is
actually more compilcated than the simple mergeable symbol.

llvm-svn: 188235
2013-08-13 00:03:21 +00:00
Rui Ueyama 43e5fd224a [PECOFF] Fixed base images now have the IMAGE_FILE_RELOCS_STRIPPED flag
Patch by Ron Ofir.

llvm-svn: 188187
2013-08-12 18:11:35 +00:00
Rui Ueyama f1ffe8abbf [PECOFF] Trim at most one character from imported symbols.
The import name is not always the same as the symbol name. If the name/type
field in the import header is NOPREFIX or UNDECORATE, we need to strip some
characters from symbol to get its import name.

The Microsoft PE/COFF spec is vague if symbol contains more than two
consecutive characters to be stripped. We used to strip all characters,
but it doesn't seem right as we couldn't link against the system library
because of this name mangling. Looks like we shouldn't strip more than one
character.

llvm-svn: 188154
2013-08-12 04:10:00 +00:00
Rui Ueyama 2db270c895 Revert r188150 to un-break the buildbot.
llvm-svn: 188152
2013-08-12 03:02:23 +00:00
Rui Ueyama bf5610cced [PECOFF] It's an error if subsystem is not specified.
llvm-svn: 188150
2013-08-12 02:23:16 +00:00
Daniel Dunbar bc7bfb1bee [tests] Update to use lit_config and lit package, as appropriate.
llvm-svn: 188093
2013-08-09 18:51:17 +00:00
Rui Ueyama bae7f8ee2d [PECOFF] Add a note about underscore symbol prefix.
llvm-svn: 188090
2013-08-09 18:34:57 +00:00
Rui Ueyama 908606d0a9 [PECOFF] Create __ImageBase symbol.
__ImageBase is a symbol having 4 byte integer equal to the image base address
of the resultant executable. The linker is expected to create the symbol as if
it were read from a file.

In order to emit the symbol contents only when the symbol is actually
referenced, we created a pseudo library file to wrap the linker generated
symbol. The library file member is emitted to the output only when the member
is actually referenced, which is suitable for our purpose.

llvm-svn: 188052
2013-08-09 04:44:15 +00:00
Rui Ueyama 02d0bf0f80 Fix spelling error. s/Libary/Library/g.
llvm-svn: 188049
2013-08-09 04:19:54 +00:00
Rui Ueyama d7414e25da [PECOFF] Fully cover the switch for COMDAT attributes and add a comment.
llvm-svn: 188046
2013-08-09 01:06:21 +00:00
Rui Ueyama 6427ae8ae6 Fix comment typo.
llvm-svn: 188045
2013-08-09 01:06:19 +00:00
Rui Ueyama dd72278fea [PECOFF] Support COMDAT section that contains mergeable atoms.
The COMDAT section is a section with a special attribute to tell the linker
whether the symbols in the section are allowed to be merged or not. This patch
add a function to interpret the COMDAT data and set "merge" attribute to the
atoms accordingly.

LLD supports multiple policies to merge atoms; atoms can be merged by name or
by content. COFF supports them, and in addition to that, it supports
choose-the-largest-atom policy, which LLD currently does not support. I simply
mapped it to merge-by-name attribute for now, but we eventually have to support
that policy in the core linker.

llvm-svn: 188025
2013-08-08 23:31:50 +00:00
Michael J. Spencer 238cc72ec5 Update to llvm changes.
llvm-svn: 188021
2013-08-08 22:26:50 +00:00
Rui Ueyama a05adfaa90 Update the .drectve section to remove reference to nonexistent files.
llvm-svn: 188011
2013-08-08 21:04:09 +00:00
Rui Ueyama 0ca149fce9 Rename TargetInfo -> LinkingContext.
Also change some local variable names: "ti" -> "context" and
"_targetInfo" -> "_context".

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

llvm-svn: 187823
2013-08-06 22:31:59 +00:00
Rui Ueyama 05f1ae987b Remove unused using's.
llvm-svn: 187690
2013-08-02 23:22:46 +00:00
Rui Ueyama 707754f3e8 [PECOFF] Move more code from Atoms.h to ReaderCOFF.cpp.
llvm-svn: 187688
2013-08-02 22:58:22 +00:00
Rui Ueyama 35947af012 [PECOFF] Remove special treatment of "--" option.
Thanks to Hans' patch (r187675), OptTable now handles "--", so we don't
need this code in LLD.

llvm-svn: 187683
2013-08-02 22:34:12 +00:00
Rui Ueyama f6e90afbf4 [PECOFF] Remove COFFDefinedFileAtom::originalOffset().
The aim of this patch is to reduce the dependency from COFFDefinedAtom
to COFF structs defined in llvm/Object/COFF.h. Currently many attributes
of the atom are computed in the atom. That provide a simple interface but
does not work well in some cases.

There are some cases that the same type atom is created from different
parts of a COFF file. One example is the BSS atom, which can be created
from the defined symbol in the .bss section or from the undefined symbol.
Computing attributes from different sources in the atom complicates the
code. We should compute it outside the atom.

In the next patch, I'll move more code from Atoms.h to ReaderCOFF.cpp.

llvm-svn: 187681
2013-08-02 22:27:15 +00:00
Rui Ueyama 4ecc59afce [PECOFF] Handle .drectve section.
Summary:
The .drectve section contains linker command line options, and the linker is
expected to interpret them as if they were given via the command line. In this
patch, the command line parser in the driver is called from the object file
reader to parse the string.

I think this patch is important, because this is the first step towards mutable
TargetInfo. We had a discussion about that on llvm-commits mailing list before.
I haven't removed "const" from the function signature yet. Instead, I just use
cast to remove "const". This is a temporary aid for an experiment. If we don't
see any issue with this mutable TargetInfo appraoch, I'll change the function
signature, and rename the class LinkerContext from TargetInfo.

Reviewers: kledzik

CC: llvm-commits

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

llvm-svn: 187677
2013-08-02 21:26:14 +00:00
Rui Ueyama f29065d0c6 [PECOFF] Return an error_code instead of calling report_fatal_error().
For an invalid input we should not call report_fatal_error(), because
when LLD is used as a library, we don't want to kill the whole app
because of a malformed input.

llvm-svn: 187673
2013-08-02 21:10:17 +00:00
Rui Ueyama 53f4660680 Use report_fatal_error() instead of llvm_unreachable() to show broken input file error.
llvm-svn: 187670
2013-08-02 20:45:25 +00:00
Rui Ueyama 8e091352c9 [PECOFF] Remove an assertion that's too heavy.
llvm-svn: 187665
2013-08-02 19:10:29 +00:00
Rui Ueyama 8a14aa1bd9 [PECOFF] Relocations now take into account the address which is stored at the relocation site
Patch by Ron Ofir.

llvm-svn: 187664
2013-08-02 18:40:50 +00:00
Rui Ueyama 8344be8407 [PECOFF] A symbol with symbol with section number 0 and non-zero value represents a BSS atom.
llvm-svn: 187645
2013-08-02 05:25:31 +00:00
Rui Ueyama 740e402b8b [PECOFF] Simplify COFFBSSAtom.
A instance of the class always represents a BSS atom, so we don't need
to look at the symbol or the section to retrieve its attributes.

llvm-svn: 187643
2013-08-02 05:04:06 +00:00
Hans Wennborg 03cd107364 Remove the SUPPORT_ALIASARGS define
It is not needed after LLVM r187546.

llvm-svn: 187551
2013-08-01 00:12:38 +00:00
Rui Ueyama 527abc9b09 Use StringRef::equals_lower(). No functionality change.
llvm-svn: 187548
2013-07-31 23:53:58 +00:00
Rui Ueyama 395958ea6f [PECOFF][Driver] Prefer "/" over "-" as the indicator of the option.
This patch does not change the behavior of LLD, but changes the output of the
help text. We want to show the help text with Windows style indicator rather
than Unix style indicator.

llvm-svn: 187544
2013-07-31 23:23:25 +00:00
Hans Wennborg 88b7aad3e1 Option parsing tables: pick up AliasArgs from the OPTION macro.
This depends on LLVM r187537.

The SUPPORT_ALIASARGS macro will be removed once all option parsing
clients have been updated.

llvm-svn: 187541
2013-07-31 23:17:41 +00:00
Rui Ueyama 44a6ed8d4e [PECOFF][Driver] Rewrite the tablegen def file using multiclass to remove duplicates.
llvm-svn: 187539
2013-07-31 23:12:06 +00:00
Rui Ueyama 3adc09e9fc Revert "[PECOFF][Driver] Remove quotes from command line arguments."
This reverts commit r187390 because we should not handle argv's quotes ourselves.

In Windows, unlike Unix, quotes are not processed by the shell. Instead the C
startup routine parses it as described in
http://msdn.microsoft.com/en-us/library/a1y7w461.aspx and pass the results to
main(). So, at the time when the control reaches main(), quotes that should be
removed has already been removed.

We still need to handle quotes in the response file and in .drectve section
ourselves. That will be addressed in different patches.

llvm-svn: 187534
2013-07-31 22:13:15 +00:00
Rui Ueyama 3361fa49f5 [PECOFF] Add a comment about .bss section.
llvm-svn: 187505
2013-07-31 17:45:48 +00:00
Rui Ueyama 87b9703ec4 [PECOFF] Add a comment on the idata section fragments.
llvm-svn: 187484
2013-07-31 05:10:20 +00:00
Rui Ueyama a0016db818 Fix comment.
llvm-svn: 187461
2013-07-30 23:20:10 +00:00
Rui Ueyama dcf09476ff [PECOFF] Emit BSS section.
llvm-svn: 187460
2013-07-30 22:56:46 +00:00
Rui Ueyama 7ae6ffd3d2 [PECOFF] Split COFFDefinedAtom to add COFFBSSAtom class.
The BSS atom is similar to the regular defined atom, but it's different
in the sense that it does not have contents. Until now we assumed all the
defined atoms have its contents. That did not fit well to the BSS atom.

llvm-svn: 187453
2013-07-30 21:54:10 +00:00
Rui Ueyama 85cd10ffa0 [PECOFF][Driver] Remove quotes from command line arguments.
The command line option in .drectve section may be quoted by double
quotes, and if that's the case we have to remove them.

llvm-svn: 187390
2013-07-29 23:32:22 +00:00
Rui Ueyama b469aeb164 [PECOFF] Process Import Name/Type field in the import library.
This patch removes hacky mangle() function, which strips all decorations
uncondtitionally. LLD now interprets Import Name/Type field in the import
library properly as described in the Microsoft PE/COFF Spec.

llvm-svn: 187388
2013-07-29 22:55:39 +00:00
Rui Ueyama 7ac447fdfc [PECOFF] Replace the magic number with sizeof().
llvm-svn: 187382
2013-07-29 21:54:43 +00:00
Rui Ueyama 5b274f3414 Fix test failure introduced in r187271 by enabling pipefail.
llvm-svn: 187381
2013-07-29 21:50:33 +00:00
Rui Ueyama 35f72ac818 [PECOFF] Simplicy FileCOFF ctor. No functionality change.
Member functions to read the symbol table had too many parameters to propagate
all the temporary information from one to another. By storing the information
to data members, we can simplify the function signatures and improve the
readability.

llvm-svn: 187321
2013-07-28 04:29:30 +00:00
Rui Ueyama fbfd102b9e Removed unnecessary parameter.
llvm-svn: 187317
2013-07-28 01:50:24 +00:00
Rui Ueyama c3ab5117c9 [PECOFF] Skip a section if there's no atom in the section.
Some sections, such as with IMAGE_SCN_LNK_REMOVE attribute, is skipped
in the first pass. Such sections need to be skipped in the latter passes.

llvm-svn: 187281
2013-07-27 00:37:50 +00:00
Rui Ueyama 3939101d6f [PATCH] [PECOFF] Fill size field of IMAGE_DATA_DIRECTORY
Patch by Ron Ofir.

llvm-svn: 187262
2013-07-26 22:33:28 +00:00
Rui Ueyama 28084dc6cd [PECOFF][Driver] Add ".lib" extension to the path given with /defaultlib.
llvm-svn: 187259
2013-07-26 22:22:26 +00:00
Rui Ueyama 3e0bbb4b02 [PECOFF][Driver] Add a library file even if it does not exist.
Missing files will be reported as errors in the later pass, so this patch
does not change the behavior of the LLD linker, but it helps writing unit
tests for the driver.

llvm-svn: 187256
2013-07-26 22:17:08 +00:00
Rui Ueyama 9dcbf8b3f6 [PECOFF][Driver] Fix a bug that -mllvm does not take any arguments.
llvm-svn: 187243
2013-07-26 20:54:36 +00:00
Rui Ueyama d5b49de621 [PECOFF] Don't set IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE if "-fixed" is provided
Based on Ron Ofir's patch.

llvm-svn: 187221
2013-07-26 17:30:39 +00:00