Skip to content
This repository was archived by the owner on Mar 22, 2019. It is now read-only.

Commit d6f824f

Browse files
committed
Merge remote-tracking branch 'github/amd-common' into amd-hcc
2 parents b737b32 + ff82b61 commit d6f824f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1848
-1620
lines changed

COFF/Driver.cpp

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ bool link(ArrayRef<const char *> Args, raw_ostream &Diag) {
5959
(ErrorOS == &llvm::errs() && Process::StandardErrHasColors());
6060
Driver = make<LinkerDriver>();
6161
Driver->link(Args);
62-
return true;
62+
return !ErrorCount;
6363
}
6464

6565
// Drop directory components and replace extension with ".exe" or ".dll".
@@ -121,10 +121,12 @@ void LinkerDriver::addBuffer(std::unique_ptr<MemoryBuffer> MB) {
121121
return Symtab.addFile(make<ArchiveFile>(MBRef));
122122
if (Magic == file_magic::bitcode)
123123
return Symtab.addFile(make<BitcodeFile>(MBRef));
124+
124125
if (Magic == file_magic::coff_cl_gl_object)
125-
fatal(MBRef.getBufferIdentifier() + ": is not a native COFF file. "
126+
error(MBRef.getBufferIdentifier() + ": is not a native COFF file. "
126127
"Recompile without /GL");
127-
Symtab.addFile(make<ObjectFile>(MBRef));
128+
else
129+
Symtab.addFile(make<ObjectFile>(MBRef));
128130
}
129131

130132
void LinkerDriver::enqueuePath(StringRef Path) {
@@ -134,8 +136,9 @@ void LinkerDriver::enqueuePath(StringRef Path) {
134136
enqueueTask([=]() {
135137
auto MBOrErr = Future->get();
136138
if (MBOrErr.second)
137-
fatal(MBOrErr.second, "could not open " + PathStr);
138-
Driver->addBuffer(std::move(MBOrErr.first));
139+
error("could not open " + PathStr + ": " + MBOrErr.second.message());
140+
else
141+
Driver->addBuffer(std::move(MBOrErr.first));
139142
});
140143
}
141144

@@ -148,12 +151,14 @@ void LinkerDriver::addArchiveBuffer(MemoryBufferRef MB, StringRef SymName,
148151
}
149152

150153
InputFile *Obj;
151-
if (Magic == file_magic::coff_object)
154+
if (Magic == file_magic::coff_object) {
152155
Obj = make<ObjectFile>(MB);
153-
else if (Magic == file_magic::bitcode)
156+
} else if (Magic == file_magic::bitcode) {
154157
Obj = make<BitcodeFile>(MB);
155-
else
156-
fatal("unknown file type: " + MB.getBufferIdentifier());
158+
} else {
159+
error("unknown file type: " + MB.getBufferIdentifier());
160+
return;
161+
}
157162

158163
Obj->ParentName = ParentName;
159164
Symtab.addFile(Obj);
@@ -230,7 +235,7 @@ void LinkerDriver::parseDirectives(StringRef S) {
230235
case OPT_throwingnew:
231236
break;
232237
default:
233-
fatal(Arg->getSpelling() + " is not allowed in .drectve");
238+
error(Arg->getSpelling() + " is not allowed in .drectve");
234239
}
235240
}
236241
}
@@ -581,6 +586,15 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
581586
V.push_back(Arg->getValue());
582587
cl::ParseCommandLineOptions(V.size(), V.data());
583588

589+
// Handle /errorlimit early, because error() depends on it.
590+
if (auto *Arg = Args.getLastArg(OPT_errorlimit)) {
591+
int N = 20;
592+
StringRef S = Arg->getValue();
593+
if (S.getAsInteger(10, N))
594+
error(Arg->getSpelling() + " number expected, but got " + S);
595+
Config->ErrorLimit = N;
596+
}
597+
584598
// Handle /help
585599
if (Args.hasArg(OPT_help)) {
586600
printHelp(ArgsArr[0]);
@@ -638,9 +652,10 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
638652

639653
// Handle /noentry
640654
if (Args.hasArg(OPT_noentry)) {
641-
if (!Args.hasArg(OPT_dll))
642-
fatal("/noentry must be specified with /dll");
643-
Config->NoEntry = true;
655+
if (Args.hasArg(OPT_dll))
656+
Config->NoEntry = true;
657+
else
658+
error("/noentry must be specified with /dll");
644659
}
645660

646661
// Handle /dll
@@ -651,10 +666,12 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
651666

652667
// Handle /fixed
653668
if (Args.hasArg(OPT_fixed)) {
654-
if (Args.hasArg(OPT_dynamicbase))
655-
fatal("/fixed must not be specified with /dynamicbase");
656-
Config->Relocatable = false;
657-
Config->DynamicBase = false;
669+
if (Args.hasArg(OPT_dynamicbase)) {
670+
error("/fixed must not be specified with /dynamicbase");
671+
} else {
672+
Config->Relocatable = false;
673+
Config->DynamicBase = false;
674+
}
658675
}
659676

660677
// Handle /machine
@@ -726,24 +743,24 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
726743
StringRef OptLevel = StringRef(S).substr(7);
727744
if (OptLevel.getAsInteger(10, Config->LTOOptLevel) ||
728745
Config->LTOOptLevel > 3)
729-
fatal("/opt:lldlto: invalid optimization level: " + OptLevel);
746+
error("/opt:lldlto: invalid optimization level: " + OptLevel);
730747
continue;
731748
}
732749
if (StringRef(S).startswith("lldltojobs=")) {
733750
StringRef Jobs = StringRef(S).substr(11);
734751
if (Jobs.getAsInteger(10, Config->LTOJobs) || Config->LTOJobs == 0)
735-
fatal("/opt:lldltojobs: invalid job count: " + Jobs);
752+
error("/opt:lldltojobs: invalid job count: " + Jobs);
736753
continue;
737754
}
738755
if (StringRef(S).startswith("lldltopartitions=")) {
739756
StringRef N = StringRef(S).substr(17);
740757
if (N.getAsInteger(10, Config->LTOPartitions) ||
741758
Config->LTOPartitions == 0)
742-
fatal("/opt:lldltopartitions: invalid partition count: " + N);
759+
error("/opt:lldltopartitions: invalid partition count: " + N);
743760
continue;
744761
}
745762
if (S != "ref" && S != "lbr" && S != "nolbr")
746-
fatal("/opt: unknown option: " + S);
763+
error("/opt: unknown option: " + S);
747764
}
748765
}
749766

@@ -801,6 +818,9 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
801818

802819
Config->MapFile = getMapFile(Args);
803820

821+
if (ErrorCount)
822+
return;
823+
804824
// Create a list of input files. Files can be given as arguments
805825
// for /defaultlib option.
806826
std::vector<MemoryBufferRef> MBs;
@@ -959,6 +979,9 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
959979
addUndefined(mangle("_load_config_used"));
960980
} while (run());
961981

982+
if (ErrorCount)
983+
return;
984+
962985
// If /msvclto is given, we use the MSVC linker to link LTO output files.
963986
// This is useful because MSVC link.exe can generate complete PDBs.
964987
if (Args.hasArg(OPT_msvclto)) {
@@ -983,10 +1006,13 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
9831006
}
9841007

9851008
// Handle /safeseh.
986-
if (Args.hasArg(OPT_safeseh))
1009+
if (Args.hasArg(OPT_safeseh)) {
9871010
for (ObjectFile *File : Symtab.ObjectFiles)
9881011
if (!File->SEHCompat)
989-
fatal("/safeseh: " + File->getName() + " is not compatible with SEH");
1012+
error("/safeseh: " + File->getName() + " is not compatible with SEH");
1013+
if (ErrorCount)
1014+
return;
1015+
}
9901016

9911017
// Windows specific -- when we are creating a .dll file, we also
9921018
// need to create a .lib file.

COFF/Error.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void error(const Twine &Msg) {
7777
} else if (ErrorCount == Config->ErrorLimit) {
7878
print("error: ", raw_ostream::RED);
7979
*ErrorOS << "too many errors emitted, stopping now"
80-
<< " (use -error-limit=0 to see all errors)\n";
80+
<< " (use /ERRORLIMIT:0 to see all errors)\n";
8181
exitLld(1);
8282
}
8383

COFF/Options.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def base : P<"base", "Base address of the program">;
2121
def defaultlib : P<"defaultlib", "Add the library to the list of input files">;
2222
def delayload : P<"delayload", "Delay loaded DLL name">;
2323
def entry : P<"entry", "Name of entry point symbol">;
24+
def errorlimit : P<"errorlimit",
25+
"Maximum number of errors to emit before stopping (0 = no limit)">;
2426
def export : P<"export", "Export a function">;
2527
// No help text because /failifmismatch is not intended to be used by the user.
2628
def failifmismatch : P<"failifmismatch", "">;

COFF/PDB.cpp

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,33 +83,22 @@ static ArrayRef<uint8_t> getDebugSection(ObjectFile *File, StringRef SecName) {
8383
}
8484

8585
static void addTypeInfo(pdb::TpiStreamBuilder &TpiBuilder,
86-
codeview::TypeTableBuilder &TypeTable,
87-
std::vector<uint8_t> &Data) {
86+
codeview::TypeTableBuilder &TypeTable) {
8887
// Start the TPI or IPI stream header.
8988
TpiBuilder.setVersionHeader(pdb::PdbTpiV80);
9089

9190
// Flatten the in memory type table.
92-
// FIXME: Avoid this copy.
9391
TypeTable.ForEachRecord([&](TypeIndex TI, ArrayRef<uint8_t> Rec) {
94-
Data.insert(Data.end(), Rec.begin(), Rec.end());
92+
// FIXME: Hash types.
93+
TpiBuilder.addTypeRecord(Rec, None);
9594
});
96-
97-
BinaryByteStream Stream(Data, support::little);
98-
codeview::CVTypeArray Records;
99-
BinaryStreamReader Reader(Stream);
100-
if (auto EC = Reader.readArray(Records, Reader.getLength()))
101-
fatal(EC, "Reader.readArray failed");
102-
for (const codeview::CVType &Rec : Records)
103-
TpiBuilder.addTypeRecord(Rec);
10495
}
10596

10697
// Merge .debug$T sections into IpiData and TpiData.
10798
static void mergeDebugT(SymbolTable *Symtab, pdb::PDBFileBuilder &Builder,
108-
std::vector<uint8_t> &TpiData,
109-
std::vector<uint8_t> &IpiData) {
99+
codeview::TypeTableBuilder &TypeTable,
100+
codeview::TypeTableBuilder &IDTable) {
110101
// Visit all .debug$T sections to add them to Builder.
111-
codeview::TypeTableBuilder IDTable(BAlloc);
112-
codeview::TypeTableBuilder TypeTable(BAlloc);
113102
for (ObjectFile *File : Symtab->ObjectFiles) {
114103
ArrayRef<uint8_t> Data = getDebugSection(File, ".debug$T");
115104
if (Data.empty())
@@ -132,10 +121,10 @@ static void mergeDebugT(SymbolTable *Symtab, pdb::PDBFileBuilder &Builder,
132121
}
133122

134123
// Construct TPI stream contents.
135-
addTypeInfo(Builder.getTpiBuilder(), TypeTable, TpiData);
124+
addTypeInfo(Builder.getTpiBuilder(), TypeTable);
136125

137126
// Construct IPI stream contents.
138-
addTypeInfo(Builder.getIpiBuilder(), IDTable, IpiData);
127+
addTypeInfo(Builder.getIpiBuilder(), IDTable);
139128
}
140129

141130
static void dumpDebugT(ScopedPrinter &W, ObjectFile *File) {
@@ -213,9 +202,9 @@ void coff::createPDB(StringRef Path, SymbolTable *Symtab,
213202
auto &DbiBuilder = Builder.getDbiBuilder();
214203
DbiBuilder.setVersionHeader(pdb::PdbDbiV110);
215204

216-
std::vector<uint8_t> TpiData;
217-
std::vector<uint8_t> IpiData;
218-
mergeDebugT(Symtab, Builder, TpiData, IpiData);
205+
codeview::TypeTableBuilder TypeTable(BAlloc);
206+
codeview::TypeTableBuilder IDTable(BAlloc);
207+
mergeDebugT(Symtab, Builder, TypeTable, IDTable);
219208

220209
// Add Section Contributions.
221210
std::vector<pdb::SectionContrib> Contribs =

COFF/SymbolTable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ void SymbolTable::addLazy(ArchiveFile *F, const Archive::Symbol Sym) {
190190
}
191191

192192
void SymbolTable::reportDuplicate(Symbol *Existing, InputFile *NewFile) {
193-
fatal("duplicate symbol: " + toString(*Existing->body()) + " in " +
193+
error("duplicate symbol: " + toString(*Existing->body()) + " in " +
194194
toString(Existing->body()->getFile()) + " and in " +
195195
(NewFile ? toString(NewFile) : "(internal)"));
196196
}

ELF/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ add_lld_library(lldELF
2424
OutputSections.cpp
2525
Relocations.cpp
2626
ScriptLexer.cpp
27+
ScriptParser.cpp
2728
Strings.cpp
2829
SymbolTable.cpp
2930
Symbols.cpp

ELF/Driver.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "LinkerScript.h"
3434
#include "Memory.h"
3535
#include "OutputSections.h"
36+
#include "ScriptParser.h"
3637
#include "Strings.h"
3738
#include "SymbolTable.h"
3839
#include "Target.h"
@@ -860,10 +861,12 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
860861
if (Config->OutputFile.empty())
861862
Config->OutputFile = "a.out";
862863

863-
// Fail early if the output file is not writable. If a user has a long link,
864-
// e.g. due to a large LTO link, they do not wish to run it and find that it
865-
// failed because there was a mistake in their command-line.
866-
if (!isFileWritable(Config->OutputFile))
864+
// Fail early if the output file or map file is not writable. If a user has a
865+
// long link, e.g. due to a large LTO link, they do not wish to run it and
866+
// find that it failed because there was a mistake in their command-line.
867+
if (!isFileWritable(Config->OutputFile, "output file"))
868+
return;
869+
if (!isFileWritable(Config->MapFile, "map file"))
867870
return;
868871

869872
// Use default entry point name if no name was given via the command

ELF/Filesystem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ void elf::unlinkAsync(StringRef Path) {
7070
// FileOutputBuffer doesn't touch a desitnation file until commit()
7171
// is called. We use that class without calling commit() to predict
7272
// if the given file is writable.
73-
bool elf::isFileWritable(StringRef Path) {
73+
bool elf::isFileWritable(StringRef Path, StringRef Desc) {
7474
if (auto EC = FileOutputBuffer::create(Path, 1).getError()) {
75-
error("cannot open output file " + Path + ": " + EC.message());
75+
error("cannot open " + Desc + " " + Path + ": " + EC.message());
7676
return false;
7777
}
7878
return true;

ELF/Filesystem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
namespace lld {
1616
namespace elf {
1717
void unlinkAsync(StringRef Path);
18-
bool isFileWritable(StringRef Path);
18+
bool isFileWritable(StringRef Path, StringRef FileDescription);
1919
}
2020
}
2121

0 commit comments

Comments
 (0)