Commit Graph

927 Commits

Author SHA1 Message Date
Rui Ueyama beacd25780 Re-submit r207884: Remove dead code
Differential Revision: http://reviews.llvm.org/D3599

llvm-svn: 207989
2014-05-05 18:56:04 +00:00
Simon Atanasyan b9b9e36187 [ELF] Use a range based access to the ELFFile's sections collection.
No functional changes.

llvm-svn: 207953
2014-05-05 07:17:40 +00:00
Simon Atanasyan e22ca46681 [Mips] R_MIPS_GPREL32 relocation support.
llvm-svn: 207949
2014-05-05 05:56:06 +00:00
Rui Ueyama 82d62c4420 Revert "Remove dead code."
This reverts commit r207884 which was prematurely committed by accident.

llvm-svn: 207886
2014-05-02 23:45:28 +00:00
Rui Ueyama 3872d0ae26 Remove "virtual" and add "override".
llvm-svn: 207885
2014-05-02 23:44:02 +00:00
Rui Ueyama d50ed14d92 Remove dead code.
isAlias always returns false and no one is using it. It was
originally added Atom to query if an atom is an alias for another
atom, assuming that alias atoms are different from normal atoms.

We now support atom aliasing, but the way that's implemented is
in a different way than what isAlias assumed. An alias atom is
just a regular defined atom with no content, and it has a layout-
before edge to alias-to atom so that they are layed out at the
same location in the result. So this is dead code, and it doesn't
make much sense to keep it.

llvm-svn: 207884
2014-05-02 23:43:59 +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 db2fc6d756 Make the variable scope narrower. No functionality change.
llvm-svn: 207821
2014-05-02 01:17:40 +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
Rui Ueyama a665de8f38 Fix FreeBSD buildbots.
llvm-svn: 207802
2014-05-01 22:13:39 +00:00
Rui Ueyama da808c39e6 [PECOFF] Do not call addDllExport to mutate export descriptors.
This is more efficient than before.

llvm-svn: 207791
2014-05-01 20:40:30 +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 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
Simon Atanasyan db8a4a8578 [ELF] Return result from the function ASAP.
No functional changes.

llvm-svn: 207690
2014-04-30 19:03:56 +00:00
Simon Atanasyan a54d34d4ad [ELF] Factor out the code builds a library search directory path
into the separate function.

No functional changes.

llvm-svn: 207689
2014-04-30 19:03:51 +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 105d6abe50 [Mips] Re-order include headers.
llvm-svn: 207495
2014-04-29 05:46:02 +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
Simon Atanasyan f293b3e52c [Mips] 80 column.
llvm-svn: 207493
2014-04-29 05:21:36 +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 15dce7a8f3 [Mips] Convert MipsDynamicSymbolTable to the class template.
llvm-svn: 207435
2014-04-28 19:34:34 +00:00
Simon Atanasyan 0053796a08 [Mips] Add the 'const' qualifier to the couple RelocationPass class
member functions.

llvm-svn: 207434
2014-04-28 19:34: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 51d7efdb57 [PECOFF] Assign unique ordinals to __imp_ symbols.
llvm-svn: 207168
2014-04-25 01:18:40 +00:00
Rui Ueyama ae13a45d4d [PECOFF] Do not copy-construct ExportDesc.
llvm-svn: 207154
2014-04-24 22:57:17 +00:00
Rui Ueyama f550eba39c [PECOFF] Define implicit symbols for exported ones.
This patch is to fix a compatibility issue with MSVC link.exe as to
use of dllexported symbols inside DLL.

A DLL exports two symbols for a function. One is non-decorated one,
and the other is with __imp_ prefix. The former is a function that
you can directly call, and the latter is a pointer to the function.
These dllexported symbols are created by linker for programs that
link against the DLL. So, I naturally believed that __imp_ symbols
become available when you once create a DLL and link against it, but
they don't exist until then. And that's not true.

MSVC link.exe is smart enough to allow users to use __imp_ symbols
locally. That is, if a symbol is specified with /export option, it
implicitly creates a new symbol with __imp_ prefix as a pointer to
the exported symbol. This feature allows the following program to
be linked and run, although _imp__hello is not defined in this code.

  #include <stdio.h>

  __declspec(dllexport)
  void hello(void) { printf("Hello\n"); }

  extern void (*_imp__hello)(void);

  int main() {
    _imp__hello();
    return 0;
  }

MSVC link.exe prints out the following warning when linking it.

  LNK4217: locally defined symbol _hello imported in function _main

Using __imp_ symbols locally is I think not a good coding style. One
should just take an address using "&" operator rather than appending
__imp_ prefix. However, there are programs in the wild that depends
on this link.exe's behavior, so we need this feature.

llvm-svn: 207141
2014-04-24 20:12:01 +00:00
Rui Ueyama 11f3f1f7d5 [PECOFF] Allow symbols not starting with '_' in x86
Not all symbols are decorated with an underscore in x86. You can
write undecorated symbols in assembly, for example. Thus this
assertion is too strong.

llvm-svn: 207125
2014-04-24 17:04:19 +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
Chandler Carruth 9afe32d11d [Modules] Fix potential ODR violations by sinking the DEBUG_TYPE
definition below all of the header #include lines, LLD edition.

IF you want to know more details about this, you can see the recent
commits to Debug.h in LLVM. This is just the LLD segment of a cleanup
I'm doing globally for this macro.

llvm-svn: 206851
2014-04-22 03:21:31 +00:00
Rui Ueyama d48665b1fd [ELF] Fix GNU_RELRO section name.
llvm-svn: 206560
2014-04-18 06:01:43 +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 dca4162aa5 [Mips] Factor out MIPS relocation addend reading to the separate
function.

No functional changes.

llvm-svn: 206023
2014-04-11 07:25:35 +00:00
Simon Atanasyan e5b156810a [ELF] Remove redundant conversion of section content from ArrayRef to
StringRef before calling the createSectionAtom() method and reverse
conversion inside the method.

No functional changes.

llvm-svn: 206022
2014-04-11 07:25:29 +00:00
Simon Atanasyan 62377c6875 [Mips] R_MIPS_PC32 relocation support.
llvm-svn: 206018
2014-04-11 04:33:21 +00:00
David Majnemer 678088148c Update to match changes made in r205955
llvm-svn: 205956
2014-04-10 07:49:18 +00:00
Rui Ueyama 20b075e526 [PECOFF] Fix common symbol alignment.
Differential Revision: http://reviews.llvm.org/D3322

llvm-svn: 205826
2014-04-09 01:01:51 +00:00
Simon Atanasyan 2f5d6ae73f [ELF] Use typedefs to make class field declarations shorter.
No functional changes.

llvm-svn: 205692
2014-04-06 19:44:50 +00:00
Michael J. Spencer ead3b1a544 [X86-64] Add missing relocation.
llvm-svn: 205645
2014-04-04 19:22:14 +00:00
Rui Ueyama 60ea496448 This is yet another case clang-modernize failed to add "override".
llvm-svn: 205644
2014-04-04 19:17:59 +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 fb44f5e278 Fix comments.
llvm-svn: 205568
2014-04-03 21:06:23 +00:00
Rui Ueyama 4469ce6c7b Add empty() to atom_collection.
"x.empty()" is more idiomatic than "x.size() == 0". This patch is to
add such method and use it in LLD.

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

llvm-svn: 205558
2014-04-03 19:51:14 +00:00
Rui Ueyama b461b1c785 s/llvm::dyn_cast/dyn_cast/
llvm-svn: 205404
2014-04-02 06:54:46 +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
Shankar Easwaran 9316c40a1b [core] support .gnu.linkonce sections
.gnu.linkonce sections are similar to section groups.

They were supported before section groups existed and provided a way
to resolve COMDAT sections using a different design.

There are few implementations that use .gnu.linkonce sections
to store simple floating point constants which doesnot require complex section
group support but need a way to store only one copy of the floating point
constant in a binary.

.gnu.linkonce based symbol resolution achieves that.

Review : http://llvm-reviews.chandlerc.com/D3242

llvm-svn: 205280
2014-04-01 03:49:55 +00:00
Shankar Easwaran 50136f1f4e Revert "[core] support .gnu.linkonce sections"
This reverts commit 5d5ca72a7876c3dd3dd1db83dc6a0d74be9e2cd1.

Discuss on a better design to raise error when there is a similar group with Gnu
linkonce sections and COMDAT sections.

llvm-svn: 205224
2014-03-31 17:12:06 +00:00