[lld] r201900 - [PECOFF] Implement /SAFESEH option.
Rui Ueyama
ruiu at google.com
Fri Feb 21 14:50:28 PST 2014
Author: ruiu
Date: Fri Feb 21 16:50:27 2014
New Revision: 201900
URL: http://llvm.org/viewvc/llvm-project?rev=201900&view=rev
Log:
[PECOFF] Implement /SAFESEH option.
LLD now prints an error message if /SAFESEH option is specified and one or
more input files are not compatible with SEH.
Added:
lld/trunk/test/pecoff/safeseh.test
Modified:
lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp?rev=201900&r1=201899&r2=201900&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp Fri Feb 21 16:50:27 2014
@@ -68,6 +68,7 @@ public:
error_code parse(StringMap &altNames);
StringRef getLinkerDirectives() const { return _directives; }
+ bool isCompatibleWithSEH() const { return _compatibleWithSEH; }
virtual const atom_collection<DefinedAtom> &defined() const {
return _definedAtoms;
@@ -136,6 +137,9 @@ private:
// The contents of .drectve section.
StringRef _directives;
+ // True if the object has "@feat.00" symbol.
+ bool _compatibleWithSEH;
+
// A map from symbol to its name. All symbols should be in this map except
// unnamed ones.
std::map<const coff_symbol *, StringRef> _symbolName;
@@ -317,10 +321,18 @@ error_code FileCOFF::readSymbolTable(vec
"Cannot atomize IMAGE_SYM_DEBUG!");
result.push_back(sym);
- // Cache the name.
StringRef name;
if (error_code ec = _obj->getSymbolName(sym, name))
return ec;
+
+ // Existence of the symbol @feat.00 indicates that object file is compatible
+ // with Safe Exception Handling.
+ if (name == "@feat.00") {
+ _compatibleWithSEH = true;
+ continue;
+ }
+
+ // Cache the name.
_symbolName[sym] = name;
// Symbol may be followed by auxiliary symbol table records. The aux
@@ -778,9 +790,8 @@ error_code FileCOFF::findSection(StringR
return error_code::success();
}
}
- // Section was not found, but it's not an error. This method returns an
- // error
- // only when there's a read error.
+ // Section was not found, but it's not an error. This method returns
+ // an error only when there's a read error.
return error_code::success();
}
@@ -930,6 +941,7 @@ public:
parseFile(std::unique_ptr<MemoryBuffer> &mb, const Registry ®istry,
std::vector<std::unique_ptr<File>> &result) const {
// Parse the memory buffer as PECOFF file.
+ const char *mbName = mb->getBufferIdentifier();
error_code ec;
std::unique_ptr<FileCOFF> file(new FileCOFF(std::move(mb), ec));
if (ec)
@@ -943,6 +955,14 @@ public:
if (error_code ec = file->parse(_context.alternateNames()))
return ec;
+
+ // Check for /SAFESEH.
+ if (_context.requireSEH() && !file->isCompatibleWithSEH()) {
+ llvm::errs() << "/SAFESEH is specified, but " << mbName
+ << " is not compatible with SEH.\n";
+ return llvm::object::object_error::parse_failed;
+ }
+
result.push_back(std::move(file));
return error_code::success();
}
Added: lld/trunk/test/pecoff/safeseh.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/safeseh.test?rev=201900&view=auto
==============================================================================
--- lld/trunk/test/pecoff/safeseh.test (added)
+++ lld/trunk/test/pecoff/safeseh.test Fri Feb 21 16:50:27 2014
@@ -0,0 +1,9 @@
+# "hello.obj" does not have the symbol "@feat.00", so it's not
+# compatible with SEH.
+
+# RUN: yaml2obj %p/Inputs/hello.obj.yaml > %t.obj
+# RUN: not lld -flavor link /safeseh /out:%t.exe /subsystem:console \
+# RUN: -- %t.obj 2> %t.err
+# RUN: FileCheck %s < %t.err
+
+CHECK: /SAFESEH is specified, but {{.*}} is not compatible with SEH.
More information about the llvm-commits
mailing list