mirror of
https://github.com/rui314/mold.git
synced 2024-12-28 02:44:48 +03:00
temporary
This commit is contained in:
parent
6511d0965f
commit
d6f47b2de4
@ -1,5 +1,13 @@
|
||||
#include "mold.h"
|
||||
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace llvm::sys;
|
||||
|
||||
static thread_local StringRef script_path;
|
||||
static thread_local StringRef script_dir;
|
||||
|
||||
static std::vector<StringRef> tokenize(StringRef input) {
|
||||
std::vector<StringRef> vec;
|
||||
while (!input.empty()) {
|
||||
@ -52,6 +60,21 @@ static ArrayRef<StringRef> read_output_format(ArrayRef<StringRef> tok) {
|
||||
return tok.slice(1);
|
||||
}
|
||||
|
||||
static std::string resolve_path(StringRef str) {
|
||||
if (str.startswith("/"))
|
||||
return str.str();
|
||||
if (str.startswith("-l"))
|
||||
return find_library(str.substr(2));
|
||||
if (std::string path = (script_dir + "/" + str).str(); fs::exists(path))
|
||||
return path;
|
||||
if (fs::exists(str))
|
||||
return str.str();
|
||||
for (StringRef dir : config.library_paths)
|
||||
if (std::string path = (dir + "/" + str).str(); fs::exists(path))
|
||||
return path;
|
||||
error("library not found: " + str);
|
||||
}
|
||||
|
||||
static ArrayRef<StringRef> read_group(ArrayRef<StringRef> tok) {
|
||||
tok = skip(tok, "(");
|
||||
|
||||
@ -61,7 +84,7 @@ static ArrayRef<StringRef> read_group(ArrayRef<StringRef> tok) {
|
||||
continue;
|
||||
}
|
||||
|
||||
read_file(tok[0]);
|
||||
read_file(resolve_path(tok[0]));
|
||||
tok = tok.slice(1);
|
||||
}
|
||||
|
||||
@ -70,7 +93,10 @@ static ArrayRef<StringRef> read_group(ArrayRef<StringRef> tok) {
|
||||
return tok.slice(1);
|
||||
}
|
||||
|
||||
void parse_linker_script(StringRef input) {
|
||||
void parse_linker_script(StringRef path, StringRef input) {
|
||||
script_path = path;
|
||||
script_dir = path.substr(0, path.find_last_of('/'));
|
||||
|
||||
std::vector<StringRef> vec = tokenize(input);
|
||||
ArrayRef<StringRef> tok = vec;
|
||||
|
||||
|
4
main.cc
4
main.cc
@ -141,7 +141,7 @@ void read_file(StringRef path) {
|
||||
out::files.push_back(new ObjectFile(mb, ""));
|
||||
break;
|
||||
case file_magic::unknown:
|
||||
parse_linker_script(mb.getBuffer());
|
||||
parse_linker_script(mb.getBufferIdentifier(), mb.getBuffer());
|
||||
break;
|
||||
default:
|
||||
error(path + ": unknown file type");
|
||||
@ -589,7 +589,7 @@ static int parse_filler(opt::InputArgList &args) {
|
||||
return (u8)ret;
|
||||
}
|
||||
|
||||
static std::string find_library(StringRef name) {
|
||||
std::string find_library(StringRef name) {
|
||||
for (StringRef dir : config.library_paths) {
|
||||
if (std::string path = (dir + "/lib" + name + ".a").str(); fs::exists(path))
|
||||
return path;
|
||||
|
4
mold.h
4
mold.h
@ -804,7 +804,7 @@ inline std::vector<T> flatten(std::vector<std::vector<T>> &vec) {
|
||||
// linker_script.cc
|
||||
//
|
||||
|
||||
void parse_linker_script(StringRef input);
|
||||
void parse_linker_script(StringRef path, StringRef input);
|
||||
|
||||
//
|
||||
// perf.cc
|
||||
@ -847,4 +847,6 @@ void print_map(ArrayRef<ObjectFile *> files, ArrayRef<OutputChunk *> output_sect
|
||||
//
|
||||
// main.cc
|
||||
//
|
||||
|
||||
std::string find_library(StringRef name);
|
||||
void read_file(StringRef path);
|
||||
|
@ -267,7 +267,6 @@ static std::vector<u64> create_dynamic_section() {
|
||||
if (!file->soname.empty()) {
|
||||
define(DT_NEEDED, i);
|
||||
i += file->soname.size() + 1;
|
||||
llvm::outs() << "file=" << file->name << " soname=" << file->soname << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user