mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 02:52:53 +02:00
[dlltool] Make memory buffer ownership less weird.
There's no reason to destroy them in a global destructor. llvm-svn: 311287
This commit is contained in:
parent
bf0706a056
commit
e0313d3bd2
@ -56,21 +56,16 @@ public:
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
std::vector<std::unique_ptr<MemoryBuffer>> OwningMBs;
|
|
||||||
|
|
||||||
// Opens a file. Path has to be resolved already.
|
// Opens a file. Path has to be resolved already.
|
||||||
// Newly created memory buffers are owned by this driver.
|
static std::unique_ptr<MemoryBuffer> openFile(const Twine &Path) {
|
||||||
Optional<MemoryBufferRef> openFile(StringRef Path) {
|
|
||||||
ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> MB = MemoryBuffer::getFile(Path);
|
ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> MB = MemoryBuffer::getFile(Path);
|
||||||
|
|
||||||
if (std::error_code EC = MB.getError()) {
|
if (std::error_code EC = MB.getError()) {
|
||||||
llvm::errs() << "cannot open file " << Path << ": " << EC.message() << "\n";
|
llvm::errs() << "cannot open file " << Path << ": " << EC.message() << "\n";
|
||||||
return None;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryBufferRef MBRef = MB.get()->getMemBufferRef();
|
return std::move(*MB);
|
||||||
OwningMBs.push_back(std::move(MB.get())); // take ownership
|
|
||||||
return MBRef;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static MachineTypes getEmulation(StringRef S) {
|
static MachineTypes getEmulation(StringRef S) {
|
||||||
@ -82,7 +77,7 @@ static MachineTypes getEmulation(StringRef S) {
|
|||||||
.Default(IMAGE_FILE_MACHINE_UNKNOWN);
|
.Default(IMAGE_FILE_MACHINE_UNKNOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string getImplibPath(std::string Path) {
|
static std::string getImplibPath(StringRef Path) {
|
||||||
SmallString<128> Out = StringRef("lib");
|
SmallString<128> Out = StringRef("lib");
|
||||||
Out.append(Path);
|
Out.append(Path);
|
||||||
sys::path::replace_extension(Out, ".a");
|
sys::path::replace_extension(Out, ".a");
|
||||||
@ -122,7 +117,8 @@ int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<MemoryBufferRef> MB = openFile(Args.getLastArg(OPT_d)->getValue());
|
std::unique_ptr<MemoryBuffer> MB =
|
||||||
|
openFile(Args.getLastArg(OPT_d)->getValue());
|
||||||
if (!MB)
|
if (!MB)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user