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