Commit Graph

533 Commits

Author SHA1 Message Date
Rui Ueyama f713cced0e [PECOFF] Make a separate pass for /alternatename symbols.
/alternatename is a command line option to define a weak alias. You
can use it as /alternatename:foo=bar to define "foo" as a weak alias
for "bar".

Because it's a command line option, the weak alias mapping is in the
LinkingContext object, and not in a object file being read.

Previously, we looked up the mapping each time we read a new symbol
from a file, to check if there is a weak alias defined for the symbol.
That's not wrong, but had made function signature's a bit complicated --
we had to pass the mapping object to many functions. Now their
parameter lists are much cleaner.

This also has another (unrealized) benefit. parseFile() now read a
file and then add alias symbols to the file. In the first pass a
LinkingContext object is not used at all. That should make it easy
to read files from archive files speculatively, as the first pass
is free from side effect.

llvm-svn: 209486
2014-05-23 00:02:42 +00:00
Nick Kledzik 8a0bc44b71 [mach-o] Fix so that mach-o semantic errors return an error rather than assert
llvm-svn: 209469
2014-05-22 20:05:43 +00:00
Nick Kledzik e39685964b [mach-o] Use lit.local.cfg to enable mach-o test cases to be run
llvm-svn: 209383
2014-05-22 01:47:17 +00:00
Nick Kledzik a0c13a2420 [mach-o] parse literal sections into atoms
llvm-svn: 209379
2014-05-22 01:42:06 +00:00
Rafael Espindola 38eed1b86d Update for llvm's r209253.
llvm-svn: 209293
2014-05-21 13:07:41 +00:00
Rui Ueyama 85a0321b15 [PECOFF] Discard .debug sections.
llvm-svn: 209274
2014-05-21 05:56:31 +00:00
Simon Atanasyan c2ec8c5281 [Mips] Show warning if the linker cannot find a pair for a R_MIPS_HI16
relocation. In fact this case violates ABI but sometimes compilers might
produce such code.

llvm-svn: 209153
2014-05-19 18:48:57 +00:00
Simon Atanasyan 9ab2cd0301 [Mips] Fix calculation of initial GOT entry value when this entry is
referenced by a local symbol.

llvm-svn: 209063
2014-05-17 04:58:26 +00:00
Nick Kledzik e09cfc5f8a [mach-o] Add support for zero-fill sections.
llvm-svn: 208928
2014-05-15 23:03:50 +00:00
Nick Kledzik 61fdef6086 [mach-o] Add support and test cases for parsing tentative definitions
llvm-svn: 208919
2014-05-15 20:59:23 +00:00
Rui Ueyama 50c337a47c Remove trailing whitespaces.
llvm-svn: 208815
2014-05-14 21:49:38 +00:00
Nick Kledzik dba52ad488 [mach-o] Add test case for parsing nlist -> Scope
llvm-svn: 208814
2014-05-14 21:37:14 +00:00
Rui Ueyama 2a52251153 Fix regression introduced in r205566.
In r205566, I made a change to Resolver so that Resolver revisit
only archive files in --start-group and --end-group pair. That's
not correct, as it also has to revisit DSO files.

This patch is to fix the issue.

Added a test to demonstrate the fix. I confirmed that it succeeded
before r205566, failed after r205566, and is ok with this patch.

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

llvm-svn: 208797
2014-05-14 17:29:27 +00:00
Rui Ueyama b18489c8bf [PECOFF] Find symbols with @number suffix for dllexported symbols
As written in the comment in this patch, symbol names specified with
/export option is resolved in a special way; for /export:foo, linker
finds a foo@<number> symbol if such symbols exists.

On Windows, a function in stdcall calling convention is mangled with
a leading underscore and following "@" and numbers. This name
mangling is kind of automatic, so you can sometimes omit _ and @number
when specifying a symbol. /export option is that case.

Previously, if a file in an archive file foo.lib provides a symbol
_fn@8, and /export:fn is specified, LLD failed to resolve the symbol.
It only tried to find _fn, and failed to find _fn@8. With this patch,
_fn@8 will be searched on the second iteration.

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

llvm-svn: 208754
2014-05-14 06:29:32 +00:00
Simon Atanasyan 35687a2fd3 [ELF] Emit DT_TEXTREL dynamic table flag.
If one or more dynamic relocation might modify a read-only section,
dynamic table should contain DT_TEXTREL tag.

The patch introduces new `RelocationTable::canModifyReadonlySection()`
method. This method checks through the relocations to see if any modifies
a read-only section. The DynamicTable class calls this method and emits
the DT_TEXTREL tag if necessary.

The patch reviewed by Rui Ueyama and Shankar Easwaran.

llvm-svn: 208670
2014-05-13 07:37:09 +00:00
Rui Ueyama a131bdb77e Indent continuation lines
llvm-svn: 208630
2014-05-12 20:51:21 +00:00
Simon Atanasyan 20b043b24c [Mips] Update test case expectations to reflect changes in the
llvm-readobj output format.

llvm-svn: 208490
2014-05-11 08:54:30 +00:00
Rui Ueyama 629d201c97 [PECOFF] Resolve dllexported symbols.
We did not actively try to resolve dllexported symbols specified
by /export or by a module definition file. So if exported symbols
would be resolved for other reasons, like other symbols refer to
them, that was fine, but if (unreferenced) exported symbols were
in an archive file, and no one refers to that file in the archive,
they remained unresolved.

That would obviously cause the issue that dllexported symbols are
not in a resultant DLL.

In this patch, we create an undefined symbol for each dllexported
symbol, to let the core linker to resolve it.

llvm-svn: 208452
2014-05-09 22:19:49 +00:00
Rui Ueyama 457aa3bbdd [PECOFF] Fix dllexported name.
Previously the handling of exported symbol was wrong if it's
specified in a module definition file in the form of
<externalname>=<internalname>. Export the correct symbol.

llvm-svn: 208446
2014-05-09 21:37:43 +00:00
Simon Atanasyan e22ca46681 [Mips] R_MIPS_GPREL32 relocation support.
llvm-svn: 207949
2014-05-05 05:56:06 +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
Rui Ueyama efa8076c29 [PECOFF] Drop stdcall's atsign suffix only.
You can omit @number suffix when specifying /export option,
but you can do that only for stdcall functions.

llvm-svn: 207809
2014-05-01 22:44:42 +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
Simon Atanasyan 4e480de0cc [Mips] Follow-up to the r207744. Replace numerical e_flags constants by their names.
llvm-svn: 207745
2014-05-01 11:10:47 +00:00
Simon Atanasyan f01ce1990c [Mips] Follow-up to the r207687. Add the test to check MIPS specific
arguments of the -m command line option.

llvm-svn: 207738
2014-05-01 05:12:32 +00:00
Rui Ueyama e1452c22e5 [PECOFF] Fix exported symbol name.
When creating a .lib file, we should strip the leading underscore,
but should not strip stdcall atsign suffix. Otherwise produced .lib
files cannot be linked.

llvm-svn: 207729
2014-05-01 00:23:07 +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
Rui Ueyama 680210fe7d [PECOFF] Fix priority of locally imported symbols.
Linker should create _imp_ symbols for local use only when such
symbols cannot be resolved in any other way. If it overrides real
imported symbols, such symbols remain virtually unresolved without
error, causing odd issues. I observed that a program linked with
LLD entered an infinite loop before reaching main() because of
this issue.

This patch moves the virtual file creating _imp_ symbols to the
very end of the input file list. Previously, the file is at the end
of the library file group. Linker might revisit the group many times,
so it was not really at the end of the input file list.

llvm-svn: 207605
2014-04-30 03:31:46 +00:00
Simon Atanasyan 8de2b8fb81 [Mips] Implement emitting of R_MIPS_REL32 relocations:
1. Re-implement PLT entries and dynamic relocations emitting to keep PLT
and relocations table in a consistent state.

2. Initialize st_value and st_other fields for dynamic symbols table
entry if this entry corresponds to an external function which address is
taken in a non-PIC executable. In that case the st_value field holds an
address of the function's PLT entry. Also set STO_MIPS_PLT bit in the
st_other field.

llvm-svn: 207494
2014-04-29 05:21:54 +00:00
Rui Ueyama 7f4162bd06 [PECOFF] /export accepts non-decorated symbols.
You usually have to specify the exact name of a symbol to export it,
but for stdcall functions you can omit the @numbers suffix.

llvm-svn: 207491
2014-04-29 02:50:35 +00:00
Rui Ueyama 72d57ab32e [PECOFF] Fix _imp_ implicit symbols.
Implicit symbol for local use implemented in r207141 was not fully
compatible with MSVC link.exe. In r207141, I implemented the feature
in such way that implicit symbols are defined only when they are
exported with /EXPORT option.

After that I found that implicit symbols are defined not only for
dllexported symbols but for all defined symbols. Actually _imp_
implicit symbols have no relationship with the dllexport feature. You
could add _imp_ to any symbol to get a pointer to the symbol, whether
the symbol is dllexported or not.  It looks pretty weird to me but
that's what we want if link.exe behaves that way.

Here is a bit about the implementation: Creating all implicit symbols
beforehand is going to be a huge waste of resource. This feature is
rarely used, and MSVC link.exe even prints out a warning message when
it finds this feature is being used. So we create implicit symbols
on demand. There is an archive file that creates implicit symbols when
they are needed.

llvm-svn: 207476
2014-04-29 00:32:00 +00:00
Simon Atanasyan 0804610e9f [Mips] Rename the test case.
llvm-svn: 207437
2014-04-28 19:34:46 +00:00
Simon Atanasyan 9b5e5d7942 [Mips] Rewrite the R_MIPS_COPY relocation test using yaml2obj tool.
llvm-svn: 207436
2014-04-28 19:34:39 +00:00
Reid Kleckner 64e7a03f24 lld: Silence CMake warning about a target that doesn't exist
lld-test.deps doesn't exist in a non-standalone build.

llvm-svn: 207431
2014-04-28 18:34:11 +00:00
Filipe Cabecinhas cd8c610cb0 XFAIL the Mips tests when we don't have the target.
These tests shouldn't even try to use the Mips target, but let's make
them not fail when we don't have it while they don't get fixed.

llvm-svn: 206947
2014-04-23 05:35:26 +00:00
Filipe Cabecinhas 47f07f8c9a winlib should be lib.exe, not just lib.
This avoids setting the winlib feature on machines with a lib dir in a
$PATH dir.

llvm-svn: 206940
2014-04-23 04:38:13 +00:00
Rui Ueyama 7ad715d871 [PECOFF] Skip IMAGE_SYM_DEBUG sections correctly.
We don't use sections with IMAGE_SYM_DEBUG attribute so we basically
want to the symbols for them when reading symbol table. When we skip
them, we need to skip auxiliary symbols too. Otherwise weird error
would happen because aux symbols would be interpreted as regular ones.

llvm-svn: 206931
2014-04-22 23:48:42 +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 e5097d0ed4 Fix broken test.
llvm-svn: 206651
2014-04-18 21:19:22 +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 4aaea17dc9 [PECOFF] Add one more test for r206633.
llvm-svn: 206645
2014-04-18 20:44:05 +00:00
Rui Ueyama 3511b02a85 [ELF] Fix typo that caused a test to fail on FreeBSD.
llvm-svn: 206538
2014-04-17 23:38:01 +00:00
Simon Atanasyan d874ea281f [Mips] Fix typo in the test.
llvm-svn: 206484
2014-04-17 18:18:51 +00:00
Rui Ueyama 08587f8ccd Silence the test failure on FreeBSD for now.
It's hard to debug this failure on remote machine only with lit logs.
I'm trying to reproduce it locally on a FreeBSD machine.

llvm-svn: 206432
2014-04-17 00:55:54 +00:00
Rui Ueyama d0848a6fa8 Second attempt to unbreak the buildbot.
llvm-svn: 206428
2014-04-16 23:35:12 +00:00
Rui Ueyama a4d93b5062 Attempt to unbreak FreeBSD/AMD64 buildbot.
llvm-svn: 206419
2014-04-16 21:19:35 +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
Simon Atanasyan 60536ee625 [Mips] Emit PLT entries for more static relocations.
llvm-svn: 206358
2014-04-16 06:16:32 +00:00
Simon Atanasyan e3e8a0a913 [ELF] Regroup code creates ELF relocations references ELFReference into
a couple of new virtual functions.

Follow-up to the rL203408. Two virtual functions `createRelocationReference()`
responsible for creation of `ELFReference` have been replaced by a couple of
new virtual functions `createRelocationReferences()` (plural). Each former
function creates a //single// ELFReference for a specified `Elf_Rela`
or `Elf_Rel` relocation records. The new functions responsible for creation
of //all// relocation references for provided symbol.

For all targets except MIPS there are no functional changes.

MIPS ABI has a notion of //paired// relocations. An effective addend of such
relocations are calculated using addends of both pair's members.
Each `R_MIPS_HI16` and `R_MIPS_GOT16` (for local symbols) relocations must have
an associated `R_MIPS_LO16` entry immediately following it in the list
of relocations. Immediately does not mean "next record" in relocations section
but "next record referenced the same symbol". Moreover a single `R_MIPS_LO16`
relocation can be paired with multiple preceding `R_MIPS_HI16/R_MIPS_GOT16`
relocations.

The paired relocation can have offsets belong to the different symbols.
That is why we need to have access to list of all relocations during
construction of `ELFReference` for MIPS target.

The patch reviewed by Shankar Easwaran.

llvm-svn: 206102
2014-04-12 03:59:46 +00:00
Simon Atanasyan 5eb139fc7c [Mips] Rewrite R_MIPS_26 handling test using the yaml2obj tool.
llvm-svn: 206020
2014-04-11 04:44:05 +00:00