Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 1 | //===- Driver.cpp ---------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Linker |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Rui Ueyama | afff74e2 | 2015-08-05 23:24:46 +0000 | [diff] [blame] | 10 | #include "Driver.h" |
Rafael Espindola | 192e1fa | 2015-08-06 15:08:23 +0000 | [diff] [blame] | 11 | #include "Config.h" |
| 12 | #include "Error.h" |
Rui Ueyama | afff74e2 | 2015-08-05 23:24:46 +0000 | [diff] [blame] | 13 | #include "InputFiles.h" |
| 14 | #include "SymbolTable.h" |
Rui Ueyama | ff77768 | 2015-10-09 21:12:40 +0000 | [diff] [blame] | 15 | #include "Target.h" |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 16 | #include "Writer.h" |
| 17 | #include "llvm/ADT/STLExtras.h" |
Rafael Espindola | 2e9eac1 | 2015-09-11 21:18:56 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/StringExtras.h" |
Rui Ueyama | a467240 | 2015-10-11 02:03:03 +0000 | [diff] [blame] | 19 | #include "llvm/Support/raw_ostream.h" |
Rui Ueyama | cacf967 | 2015-10-11 02:22:31 +0000 | [diff] [blame] | 20 | #include <utility> |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 21 | |
| 22 | using namespace llvm; |
Denis Protivensky | 1ef7b3f | 2015-10-07 09:13:03 +0000 | [diff] [blame] | 23 | using namespace llvm::ELF; |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 24 | using namespace llvm::object; |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 25 | |
| 26 | using namespace lld; |
| 27 | using namespace lld::elf2; |
| 28 | |
Rui Ueyama | 983ed2b | 2015-10-01 15:23:09 +0000 | [diff] [blame] | 29 | Configuration *lld::elf2::Config; |
| 30 | LinkerDriver *lld::elf2::Driver; |
Rui Ueyama | f5c4aca | 2015-09-30 17:06:09 +0000 | [diff] [blame] | 31 | |
Rui Ueyama | 983ed2b | 2015-10-01 15:23:09 +0000 | [diff] [blame] | 32 | void lld::elf2::link(ArrayRef<const char *> Args) { |
Rui Ueyama | 570752c | 2015-08-18 09:13:25 +0000 | [diff] [blame] | 33 | Configuration C; |
Rui Ueyama | 983ed2b | 2015-10-01 15:23:09 +0000 | [diff] [blame] | 34 | LinkerDriver D; |
Rui Ueyama | 570752c | 2015-08-18 09:13:25 +0000 | [diff] [blame] | 35 | Config = &C; |
Rui Ueyama | 983ed2b | 2015-10-01 15:23:09 +0000 | [diff] [blame] | 36 | Driver = &D; |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 37 | Driver->main(Args.slice(1)); |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Rui Ueyama | cacf967 | 2015-10-11 02:22:31 +0000 | [diff] [blame] | 40 | static std::pair<ELFKind, uint16_t> parseEmulation(StringRef S) { |
Rui Ueyama | a561e78 | 2015-10-11 19:46:00 +0000 | [diff] [blame] | 41 | if (S == "elf32btsmip") |
| 42 | return {ELF32BEKind, EM_MIPS}; |
| 43 | if (S == "elf32ltsmip") |
| 44 | return {ELF32LEKind, EM_MIPS}; |
| 45 | if (S == "elf32ppc") |
| 46 | return {ELF32BEKind, EM_PPC}; |
| 47 | if (S == "elf64ppc") |
| 48 | return {ELF64BEKind, EM_PPC64}; |
| 49 | if (S == "elf_i386") |
| 50 | return {ELF32LEKind, EM_386}; |
| 51 | if (S == "elf_x86_64") |
| 52 | return {ELF64LEKind, EM_X86_64}; |
Igor Kudrin | 2f610d5 | 2015-11-20 02:48:53 +0000 | [diff] [blame] | 53 | if (S == "aarch64linux") |
| 54 | return {ELF64LEKind, EM_AARCH64}; |
Rui Ueyama | 9aa5686 | 2015-11-24 18:55:36 +0000 | [diff] [blame] | 55 | if (S == "i386pe" || S == "i386pep" || S == "thumb2pe") |
| 56 | error("Windows targets are not supported on the ELF frontend: " + S); |
Rui Ueyama | cacf967 | 2015-10-11 02:22:31 +0000 | [diff] [blame] | 57 | error("Unknown emulation: " + S); |
Denis Protivensky | 1ef7b3f | 2015-10-07 09:13:03 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Rui Ueyama | 983ed2b | 2015-10-01 15:23:09 +0000 | [diff] [blame] | 60 | // Opens and parses a file. Path has to be resolved already. |
| 61 | // Newly created memory buffers are owned by this driver. |
| 62 | void LinkerDriver::addFile(StringRef Path) { |
Rui Ueyama | f5c4aca | 2015-09-30 17:06:09 +0000 | [diff] [blame] | 63 | using namespace llvm::sys::fs; |
Rui Ueyama | a467240 | 2015-10-11 02:03:03 +0000 | [diff] [blame] | 64 | if (Config->Verbose) |
| 65 | llvm::outs() << Path << "\n"; |
Rui Ueyama | 983ed2b | 2015-10-01 15:23:09 +0000 | [diff] [blame] | 66 | auto MBOrErr = MemoryBuffer::getFile(Path); |
Rui Ueyama | 1c42afc | 2015-10-12 15:49:06 +0000 | [diff] [blame] | 67 | error(MBOrErr, "cannot open " + Path); |
Rui Ueyama | 983ed2b | 2015-10-01 15:23:09 +0000 | [diff] [blame] | 68 | std::unique_ptr<MemoryBuffer> &MB = *MBOrErr; |
| 69 | MemoryBufferRef MBRef = MB->getMemBufferRef(); |
| 70 | OwningMBs.push_back(std::move(MB)); // take MB ownership |
| 71 | |
| 72 | switch (identify_magic(MBRef.getBuffer())) { |
| 73 | case file_magic::unknown: |
Rui Ueyama | a47ee68 | 2015-10-11 01:53:04 +0000 | [diff] [blame] | 74 | readLinkerScript(&Alloc, MBRef); |
Rui Ueyama | 983ed2b | 2015-10-01 15:23:09 +0000 | [diff] [blame] | 75 | return; |
| 76 | case file_magic::archive: |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 77 | if (WholeArchive) { |
| 78 | auto File = make_unique<ArchiveFile>(MBRef); |
| 79 | for (MemoryBufferRef &MB : File->getMembers()) |
| 80 | Files.push_back(createELFFile<ObjectFile>(MB)); |
| 81 | OwningArchives.emplace_back(std::move(File)); |
| 82 | return; |
| 83 | } |
| 84 | Files.push_back(make_unique<ArchiveFile>(MBRef)); |
Rui Ueyama | 983ed2b | 2015-10-01 15:23:09 +0000 | [diff] [blame] | 85 | return; |
Rafael Espindola | af70764 | 2015-10-12 01:55:32 +0000 | [diff] [blame] | 86 | case file_magic::elf_shared_object: |
| 87 | Files.push_back(createELFFile<SharedFile>(MBRef)); |
Rui Ueyama | 983ed2b | 2015-10-01 15:23:09 +0000 | [diff] [blame] | 88 | return; |
| 89 | default: |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 90 | Files.push_back(createELFFile<ObjectFile>(MBRef)); |
Rui Ueyama | 983ed2b | 2015-10-01 15:23:09 +0000 | [diff] [blame] | 91 | } |
Rui Ueyama | f5c4aca | 2015-09-30 17:06:09 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Rui Ueyama | 2cac584 | 2015-10-07 19:34:51 +0000 | [diff] [blame] | 94 | static StringRef |
| 95 | getString(opt::InputArgList &Args, unsigned Key, StringRef Default = "") { |
| 96 | if (auto *Arg = Args.getLastArg(Key)) |
| 97 | return Arg->getValue(); |
| 98 | return Default; |
| 99 | } |
| 100 | |
Rui Ueyama | 1a8fffa | 2015-11-12 19:00:37 +0000 | [diff] [blame] | 101 | static bool hasZOption(opt::InputArgList &Args, StringRef Key) { |
| 102 | for (auto *Arg : Args.filtered(OPT_z)) |
| 103 | if (Key == Arg->getValue()) |
| 104 | return true; |
| 105 | return false; |
| 106 | } |
| 107 | |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 108 | void LinkerDriver::main(ArrayRef<const char *> ArgsArr) { |
Rui Ueyama | 9aa5686 | 2015-11-24 18:55:36 +0000 | [diff] [blame] | 109 | initSymbols(); |
Rui Ueyama | 9ea49c7 | 2015-10-07 23:46:11 +0000 | [diff] [blame] | 110 | |
Rui Ueyama | c6e1b97 | 2015-10-11 18:19:01 +0000 | [diff] [blame] | 111 | opt::InputArgList Args = parseArgs(&Alloc, ArgsArr); |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 112 | createFiles(Args); |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 113 | |
Rui Ueyama | f5bcf2a | 2015-11-12 18:54:15 +0000 | [diff] [blame] | 114 | // Traditional linkers can generate re-linkable object files instead |
| 115 | // of executables or DSOs. We don't support that since the feature |
| 116 | // does not seem to provide more value than the static archiver. |
| 117 | if (Args.hasArg(OPT_relocatable)) |
| 118 | error("-r option is not supported. Use 'ar' command instead."); |
| 119 | |
Rui Ueyama | e717a71 | 2015-10-13 16:20:50 +0000 | [diff] [blame] | 120 | switch (Config->EKind) { |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 121 | case ELF32LEKind: |
| 122 | link<ELF32LE>(Args); |
| 123 | return; |
| 124 | case ELF32BEKind: |
| 125 | link<ELF32BE>(Args); |
| 126 | return; |
| 127 | case ELF64LEKind: |
| 128 | link<ELF64LE>(Args); |
| 129 | return; |
| 130 | case ELF64BEKind: |
| 131 | link<ELF64BE>(Args); |
| 132 | return; |
| 133 | default: |
| 134 | error("-m or at least a .o file required"); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | void LinkerDriver::createFiles(opt::InputArgList &Args) { |
Rui Ueyama | 2cac584 | 2015-10-07 19:34:51 +0000 | [diff] [blame] | 139 | for (auto *Arg : Args.filtered(OPT_L)) |
Rui Ueyama | 52a1509 | 2015-10-11 03:28:42 +0000 | [diff] [blame] | 140 | Config->SearchPaths.push_back(Arg->getValue()); |
Igor Kudrin | 1309fc0 | 2015-09-28 15:01:59 +0000 | [diff] [blame] | 141 | |
Rafael Espindola | 2e9eac1 | 2015-09-11 21:18:56 +0000 | [diff] [blame] | 142 | std::vector<StringRef> RPaths; |
| 143 | for (auto *Arg : Args.filtered(OPT_rpath)) |
| 144 | RPaths.push_back(Arg->getValue()); |
| 145 | if (!RPaths.empty()) |
| 146 | Config->RPath = llvm::join(RPaths.begin(), RPaths.end(), ":"); |
| 147 | |
Rui Ueyama | 9aa5686 | 2015-11-24 18:55:36 +0000 | [diff] [blame] | 148 | if (auto *Arg = Args.getLastArg(OPT_m)) { |
| 149 | StringRef S = Arg->getValue(); |
| 150 | std::pair<ELFKind, uint16_t> P = parseEmulation(S); |
| 151 | Config->EKind = P.first; |
| 152 | Config->EMachine = P.second; |
| 153 | Config->Emulation = S; |
| 154 | } |
| 155 | |
Rui Ueyama | d7c417c | 2015-09-29 22:33:18 +0000 | [diff] [blame] | 156 | Config->AllowMultipleDefinition = Args.hasArg(OPT_allow_multiple_definition); |
Davide Italiano | cebb449 | 2015-10-13 21:02:34 +0000 | [diff] [blame] | 157 | Config->Bsymbolic = Args.hasArg(OPT_Bsymbolic); |
Rui Ueyama | d7c417c | 2015-09-29 22:33:18 +0000 | [diff] [blame] | 158 | Config->DiscardAll = Args.hasArg(OPT_discard_all); |
| 159 | Config->DiscardLocals = Args.hasArg(OPT_discard_locals); |
| 160 | Config->DiscardNone = Args.hasArg(OPT_discard_none); |
Davide Italiano | c39c75d | 2015-10-06 16:20:00 +0000 | [diff] [blame] | 161 | Config->EnableNewDtags = !Args.hasArg(OPT_disable_new_dtags); |
Rui Ueyama | d7c417c | 2015-09-29 22:33:18 +0000 | [diff] [blame] | 162 | Config->ExportDynamic = Args.hasArg(OPT_export_dynamic); |
Rui Ueyama | c4aaed9 | 2015-10-22 18:49:53 +0000 | [diff] [blame] | 163 | Config->GcSections = Args.hasArg(OPT_gc_sections); |
Rui Ueyama | d7c417c | 2015-09-29 22:33:18 +0000 | [diff] [blame] | 164 | Config->NoInhibitExec = Args.hasArg(OPT_noinhibit_exec); |
George Rimar | 57e40de | 2015-10-01 20:14:45 +0000 | [diff] [blame] | 165 | Config->NoUndefined = Args.hasArg(OPT_no_undefined); |
George Rimar | a5fbebc | 2015-12-10 09:12:18 +0000 | [diff] [blame] | 166 | Config->PrintGcSections = Args.hasArg(OPT_print_gc_sections); |
Rui Ueyama | d7c417c | 2015-09-29 22:33:18 +0000 | [diff] [blame] | 167 | Config->Shared = Args.hasArg(OPT_shared); |
George Rimar | 5dad7c1 | 2015-10-24 08:52:46 +0000 | [diff] [blame] | 168 | Config->StripAll = Args.hasArg(OPT_strip_all); |
Rui Ueyama | a467240 | 2015-10-11 02:03:03 +0000 | [diff] [blame] | 169 | Config->Verbose = Args.hasArg(OPT_verbose); |
Rui Ueyama | d7c417c | 2015-09-29 22:33:18 +0000 | [diff] [blame] | 170 | |
Rui Ueyama | 2cac584 | 2015-10-07 19:34:51 +0000 | [diff] [blame] | 171 | Config->DynamicLinker = getString(Args, OPT_dynamic_linker); |
| 172 | Config->Entry = getString(Args, OPT_entry); |
| 173 | Config->Fini = getString(Args, OPT_fini, "_fini"); |
| 174 | Config->Init = getString(Args, OPT_init, "_init"); |
Rui Ueyama | 964ffb3 | 2015-10-09 00:33:44 +0000 | [diff] [blame] | 175 | Config->OutputFile = getString(Args, OPT_o); |
Rui Ueyama | 2cac584 | 2015-10-07 19:34:51 +0000 | [diff] [blame] | 176 | Config->SoName = getString(Args, OPT_soname); |
| 177 | Config->Sysroot = getString(Args, OPT_sysroot); |
| 178 | |
Rui Ueyama | 7b19c34 | 2015-11-24 18:48:16 +0000 | [diff] [blame] | 179 | Config->ZExecStack = hasZOption(Args, "execstack"); |
Rui Ueyama | 1a8fffa | 2015-11-12 19:00:37 +0000 | [diff] [blame] | 180 | Config->ZNodelete = hasZOption(Args, "nodelete"); |
| 181 | Config->ZNow = hasZOption(Args, "now"); |
| 182 | Config->ZOrigin = hasZOption(Args, "origin"); |
George Rimar | e3336c0 | 2015-11-24 10:15:50 +0000 | [diff] [blame] | 183 | Config->ZRelro = !hasZOption(Args, "norelro"); |
Rui Ueyama | 1a8fffa | 2015-11-12 19:00:37 +0000 | [diff] [blame] | 184 | |
Rafael Espindola | 2c1217d | 2015-10-23 19:02:19 +0000 | [diff] [blame] | 185 | if (auto *Arg = Args.getLastArg(OPT_O)) { |
| 186 | StringRef Val = Arg->getValue(); |
| 187 | if (Val.getAsInteger(10, Config->Optimize)) |
| 188 | error("Invalid optimization level"); |
| 189 | } |
| 190 | |
Igor Kudrin | 1b0d706 | 2015-10-22 08:21:35 +0000 | [diff] [blame] | 191 | if (auto *Arg = Args.getLastArg(OPT_hash_style)) { |
| 192 | StringRef S = Arg->getValue(); |
| 193 | if (S == "gnu") { |
| 194 | Config->GnuHash = true; |
| 195 | Config->SysvHash = false; |
| 196 | } else if (S == "both") { |
| 197 | Config->GnuHash = true; |
| 198 | } else if (S != "sysv") |
| 199 | error("Unknown hash style: " + S); |
| 200 | } |
| 201 | |
George Rimar | 83f406c | 2015-10-19 17:35:12 +0000 | [diff] [blame] | 202 | for (auto *Arg : Args.filtered(OPT_undefined)) |
| 203 | Config->Undefined.push_back(Arg->getValue()); |
| 204 | |
Igor Kudrin | d912ee9 | 2015-10-01 16:42:03 +0000 | [diff] [blame] | 205 | for (auto *Arg : Args) { |
| 206 | switch (Arg->getOption().getID()) { |
| 207 | case OPT_l: |
| 208 | addFile(searchLibrary(Arg->getValue())); |
| 209 | break; |
| 210 | case OPT_INPUT: |
Davide Italiano | 4e47d58 | 2015-10-11 03:53:36 +0000 | [diff] [blame] | 211 | case OPT_script: |
Igor Kudrin | d912ee9 | 2015-10-01 16:42:03 +0000 | [diff] [blame] | 212 | addFile(Arg->getValue()); |
| 213 | break; |
Rui Ueyama | 35da9b6 | 2015-10-11 20:59:12 +0000 | [diff] [blame] | 214 | case OPT_as_needed: |
| 215 | Config->AsNeeded = true; |
| 216 | break; |
| 217 | case OPT_no_as_needed: |
| 218 | Config->AsNeeded = false; |
| 219 | break; |
Igor Kudrin | d912ee9 | 2015-10-01 16:42:03 +0000 | [diff] [blame] | 220 | case OPT_Bstatic: |
| 221 | Config->Static = true; |
| 222 | break; |
| 223 | case OPT_Bdynamic: |
| 224 | Config->Static = false; |
| 225 | break; |
Igor Kudrin | 2696bbe | 2015-10-01 18:02:21 +0000 | [diff] [blame] | 226 | case OPT_whole_archive: |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 227 | WholeArchive = true; |
Igor Kudrin | 2696bbe | 2015-10-01 18:02:21 +0000 | [diff] [blame] | 228 | break; |
| 229 | case OPT_no_whole_archive: |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 230 | WholeArchive = false; |
Igor Kudrin | 2696bbe | 2015-10-01 18:02:21 +0000 | [diff] [blame] | 231 | break; |
Rui Ueyama | f5c4aca | 2015-09-30 17:06:09 +0000 | [diff] [blame] | 232 | } |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 235 | if (Files.empty()) |
Rui Ueyama | f5c4aca | 2015-09-30 17:06:09 +0000 | [diff] [blame] | 236 | error("no input files."); |
Igor Kudrin | f4cdfe88 | 2015-11-12 04:08:12 +0000 | [diff] [blame] | 237 | |
| 238 | if (Config->GnuHash && Config->EMachine == EM_MIPS) |
| 239 | error("The .gnu.hash section is not compatible with the MIPS target."); |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) { |
| 243 | SymbolTable<ELFT> Symtab; |
Rui Ueyama | ff77768 | 2015-10-09 21:12:40 +0000 | [diff] [blame] | 244 | Target.reset(createTarget()); |
| 245 | |
| 246 | if (!Config->Shared) { |
| 247 | // Add entry symbol. |
Rui Ueyama | 0cef689 | 2015-10-12 15:23:54 +0000 | [diff] [blame] | 248 | if (Config->Entry.empty()) |
| 249 | Config->Entry = (Config->EMachine == EM_MIPS) ? "__start" : "_start"; |
Rui Ueyama | 2b67507 | 2015-10-14 22:20:57 +0000 | [diff] [blame] | 250 | |
Rui Ueyama | ff77768 | 2015-10-09 21:12:40 +0000 | [diff] [blame] | 251 | // In the assembly for 32 bit x86 the _GLOBAL_OFFSET_TABLE_ symbol |
| 252 | // is magical and is used to produce a R_386_GOTPC relocation. |
| 253 | // The R_386_GOTPC relocation value doesn't actually depend on the |
| 254 | // symbol value, so it could use an index of STN_UNDEF which, according |
| 255 | // to the spec, means the symbol value is 0. |
| 256 | // Unfortunately both gas and MC keep the _GLOBAL_OFFSET_TABLE_ symbol in |
| 257 | // the object file. |
| 258 | // The situation is even stranger on x86_64 where the assembly doesn't |
| 259 | // need the magical symbol, but gas still puts _GLOBAL_OFFSET_TABLE_ as |
| 260 | // an undefined symbol in the .o files. |
| 261 | // Given that the symbol is effectively unused, we just create a dummy |
| 262 | // hidden one to avoid the undefined symbol error. |
Rui Ueyama | dd7d998 | 2015-12-16 22:31:14 +0000 | [diff] [blame] | 263 | Symtab.addIgnored("_GLOBAL_OFFSET_TABLE_"); |
Rui Ueyama | ff77768 | 2015-10-09 21:12:40 +0000 | [diff] [blame] | 264 | } |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 265 | |
Ed Maste | f2ac688 | 2015-12-11 17:46:46 +0000 | [diff] [blame] | 266 | if (!Config->Entry.empty()) { |
| 267 | // Set either EntryAddr (if S is a number) or EntrySym (otherwise). |
| 268 | StringRef S = Config->Entry; |
| 269 | if (S.getAsInteger(0, Config->EntryAddr)) |
| 270 | Config->EntrySym = Symtab.addUndefined(S); |
| 271 | } |
| 272 | |
Rui Ueyama | 2716130 | 2015-12-16 21:35:39 +0000 | [diff] [blame] | 273 | if (Config->EMachine == EM_MIPS) { |
| 274 | // On MIPS O32 ABI, _gp_disp is a magic symbol designates offset between |
| 275 | // start of function and gp pointer into GOT. |
Rui Ueyama | dd7d998 | 2015-12-16 22:31:14 +0000 | [diff] [blame] | 276 | Config->MipsGpDisp = Symtab.addIgnored("_gp_disp"); |
Rui Ueyama | 2716130 | 2015-12-16 21:35:39 +0000 | [diff] [blame] | 277 | |
| 278 | // Define _gp for MIPS. st_value of _gp symbol will be updated by Writer |
| 279 | // so that it points to an absolute address which is relative to GOT. |
| 280 | // See "Global Data Symbols" in Chapter 6 in the following document: |
| 281 | // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf |
Rafael Espindola | 02ce26a | 2015-12-24 14:22:24 +0000 | [diff] [blame] | 282 | Symtab.addAbsolute("_gp", DefinedRegular<ELFT>::MipsGp); |
Rui Ueyama | 2716130 | 2015-12-16 21:35:39 +0000 | [diff] [blame] | 283 | } |
Igor Kudrin | 15cd9ff | 2015-11-06 07:43:03 +0000 | [diff] [blame] | 284 | |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 285 | for (std::unique_ptr<InputFile> &F : Files) |
| 286 | Symtab.addFile(std::move(F)); |
| 287 | |
Rui Ueyama | f215dac | 2015-10-19 20:55:28 +0000 | [diff] [blame] | 288 | for (StringRef S : Config->Undefined) |
| 289 | Symtab.addUndefinedOpt(S); |
Denis Protivensky | 22220d5 | 2015-10-05 09:43:57 +0000 | [diff] [blame] | 290 | |
Rui Ueyama | ee59282 | 2015-10-07 00:25:09 +0000 | [diff] [blame] | 291 | if (Config->OutputFile.empty()) |
| 292 | Config->OutputFile = "a.out"; |
| 293 | |
Rui Ueyama | 7523039 | 2015-10-07 18:29:51 +0000 | [diff] [blame] | 294 | // Write the result to the file. |
Rui Ueyama | 93bfee5 | 2015-10-13 18:10:33 +0000 | [diff] [blame] | 295 | Symtab.scanShlibUndefined(); |
Rui Ueyama | c4aaed9 | 2015-10-22 18:49:53 +0000 | [diff] [blame] | 296 | if (Config->GcSections) |
| 297 | markLive<ELFT>(&Symtab); |
Rui Ueyama | 3ce825e | 2015-10-09 21:07:25 +0000 | [diff] [blame] | 298 | writeResult<ELFT>(&Symtab); |
Michael J. Spencer | 84487f1 | 2015-07-24 21:03:07 +0000 | [diff] [blame] | 299 | } |