1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-22 10:27:48 +03:00

temporary

This commit is contained in:
Rui Ueyama 2020-12-10 14:32:42 +09:00
parent 8fa6afa223
commit 3e9e13df6b
4 changed files with 14 additions and 15 deletions

View File

@ -54,9 +54,10 @@ static std::vector<std::string_view> tokenize(std::string_view input) {
return vec;
}
static std::span<std::string_view> skip(std::span<std::string_view> tok, std::string_view str) {
static std::span<std::string_view>
skip(std::span<std::string_view> tok, std::string_view str) {
if (tok.empty() || tok[0] != str)
error("expected '" + str + "'");
error("expected '" + std::string(str) + "'");
return tok.subspan(1);
}

View File

@ -82,7 +82,7 @@ InputArgList MyOptTable::parse(int argc, char **argv) {
InputArgList args = this->ParseArgs(vec, missing_index, missing_count);
if (missing_count)
error(Twine(args.getArgString(missing_index)) + ": missing argument");
error(std::string(args.getArgString(missing_index)) + ": missing argument");
for (auto *arg : args.filtered(OPT_UNKNOWN))
error("unknown argument '" + arg->getAsString(args) + "'");
@ -104,7 +104,7 @@ static std::vector<MemoryMappedFile> get_archive_members(MemoryMappedFile mb) {
for (const Archive::Child &c : file->children(err)) {
MemoryBufferRef mb =
CHECK(c.getMemoryBufferRef(),
mb.getBufferIdentifier() +
mb.getBufferIdentifier().str() +
": could not get the buffer for a child of the archive");
MemoryMappedFile file(mb.getBufferIdentifier().str(),
{mb.getBufferStart(), mb.getBufferSize()});
@ -757,7 +757,7 @@ static int get_thread_count(InputArgList &args) {
if (auto *arg = args.getLastArg(OPT_thread_count)) {
int n;
if (!llvm::to_integer(arg->getValue(), n) || n <= 0)
error(arg->getSpelling() + ": expected a positive integer, but got '" +
error(arg->getSpelling().str() + ": expected a positive integer, but got '" +
arg->getValue() + "'");
return n;
}

16
mold.h
View File

@ -6,7 +6,6 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Object/Archive.h"
#include "llvm/Object/ELF.h"
#include "llvm/Object/ELFTypes.h"
@ -51,7 +50,6 @@ using llvm::ArrayRef;
using llvm::ErrorOr;
using llvm::Error;
using llvm::Expected;
using llvm::Twine;
using llvm::object::ELF64LE;
using llvm::object::ELFFile;
@ -67,8 +65,8 @@ class SharedFile;
class Symbol;
struct Config {
std::string_view dynamic_linker = "/lib64/ld-linux-x86-64.so.2";
std::string_view output;
std::string dynamic_linker = "/lib64/ld-linux-x86-64.so.2";
std::string output;
bool as_needed = false;
bool export_dynamic = false;
bool is_static = false;
@ -83,7 +81,7 @@ struct Config {
inline Config config;
[[noreturn]] inline void error(const Twine &msg) {
[[noreturn]] inline void error(std::string msg) {
static std::mutex mu;
std::lock_guard lock(mu);
llvm::errs() << msg << "\n";
@ -116,10 +114,12 @@ T check2(Expected<T> e, llvm::function_ref<std::string()> prefix) {
return std::move(*e);
}
inline std::string toString(std::string s) { return s; }
#define CHECK(E, S) check2((E), [&] { return toString(S); })
#define unreachable() \
error(Twine("internal error at ") + __FILE__ + ":" + Twine(__LINE__))
error("internal error at " + std::string(__FILE__) + ":" + std::to_string(__LINE__))
std::string toString(InputFile *);
@ -859,14 +859,12 @@ inline Symbol *_etext;
inline Symbol *_edata;
}
inline void message(const Twine &msg) {
inline void message(std::string msg) {
static std::mutex mu;
std::lock_guard lock(mu);
llvm::outs() << msg << "\n";
}
inline std::string toString(const Twine &s) { return s.str(); }
inline std::string toString(Symbol sym) {
return std::string(sym.name) + "(" + toString(sym.file) + ")";
}

View File

@ -86,7 +86,7 @@ void ObjectFile::initialize_sections() {
if (shdr.sh_info >= sections.size())
error(toString(this) + ": invalid relocated section index: " +
Twine(shdr.sh_info));
std::to_string((u32)shdr.sh_info));
InputSection *target = sections[shdr.sh_info];
if (target) {