mirror of
https://github.com/rui314/mold.git
synced 2024-12-27 10:23:41 +03:00
wip
This commit is contained in:
parent
60d142102a
commit
b003b761db
14
cmdline.cc
14
cmdline.cc
@ -12,26 +12,26 @@ read_response_file(Context<E> &ctx, std::string_view path) {
|
||||
u8 *data = mb->data(ctx);
|
||||
|
||||
auto read_quoted = [&](i64 i, char quote) {
|
||||
std::string *buf = new std::string;
|
||||
std::string buf;
|
||||
while (i < mb->size() && data[i] != quote) {
|
||||
if (data[i] == '\\') {
|
||||
buf->append(1, data[i + 1]);
|
||||
buf.append(1, data[i + 1]);
|
||||
i += 2;
|
||||
} else {
|
||||
buf->append(1, data[i++]);
|
||||
buf.append(1, data[i++]);
|
||||
}
|
||||
}
|
||||
if (i >= mb->size())
|
||||
Fatal(ctx) << path << ": premature end of input";
|
||||
vec.push_back(std::string_view(*buf));
|
||||
vec.push_back(save_string(ctx, buf));
|
||||
return i + 1;
|
||||
};
|
||||
|
||||
auto read_unquoted = [&](i64 i) {
|
||||
std::string *buf = new std::string;
|
||||
std::string buf;
|
||||
while (i < mb->size() && !isspace(data[i]))
|
||||
buf->append(1, data[i++]);
|
||||
vec.push_back(std::string_view(*buf));
|
||||
buf.append(1, data[i++]);
|
||||
vec.push_back(save_string(ctx, buf));
|
||||
return i;
|
||||
};
|
||||
|
||||
|
9
main.cc
9
main.cc
@ -18,7 +18,7 @@ static bool is_text_file(Context<E> &ctx, MemoryMappedFile<E> *mb) {
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
std::string_view save_string(Context<E> &ctx, std::string str) {
|
||||
std::string_view save_string(Context<E> &ctx, const std::string &str) {
|
||||
std::vector<u8> *buf = new std::vector<u8>(str.size());
|
||||
memcpy(buf->data(), str.data(), str.size());
|
||||
ctx.owning_bufs.push_back(std::unique_ptr<std::vector<u8>>(buf));
|
||||
@ -601,4 +601,9 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
template void read_file(Context<X86_64> &ctx, MemoryMappedFile<X86_64> *mb);
|
||||
#define INSTANTIATE(E) \
|
||||
template void read_file(Context<E> &, MemoryMappedFile<E> *); \
|
||||
template std::string_view save_string(Context<E> &, const std::string &)
|
||||
|
||||
INSTANTIATE(X86_64);
|
||||
INSTANTIATE(I386);
|
||||
|
2
mold.h
2
mold.h
@ -1381,7 +1381,7 @@ template <typename E>
|
||||
void read_file(Context<E> &ctx, MemoryMappedFile<E> *mb);
|
||||
|
||||
template <typename E>
|
||||
std::string_view save_string(Context<E> &ctx, std::string str);
|
||||
std::string_view save_string(Context<E> &ctx, const std::string &str);
|
||||
|
||||
//
|
||||
// Symbol
|
||||
|
@ -1081,10 +1081,8 @@ ObjectFile<E>::create_internal_file(Context<E> &ctx) {
|
||||
if (!is_c_identifier(chunk->name))
|
||||
continue;
|
||||
|
||||
auto *start = new std::string("__start_" + std::string(chunk->name));
|
||||
auto *stop = new std::string("__stop_" + std::string(chunk->name));
|
||||
add(*start);
|
||||
add(*stop);
|
||||
add(save_string(ctx, "__start_" + std::string(chunk->name)));
|
||||
add(save_string(ctx, "__stop_" + std::string(chunk->name)));
|
||||
}
|
||||
|
||||
obj->elf_syms = *esyms;
|
||||
|
11
passes.cc
11
passes.cc
@ -913,10 +913,13 @@ void fix_synthetic_symbols(Context<E> &ctx) {
|
||||
// __start_ and __stop_ symbols
|
||||
for (OutputChunk<E> *chunk : ctx.chunks) {
|
||||
if (is_c_identifier(chunk->name)) {
|
||||
std::string *sym1 = new std::string("__start_" + std::string(chunk->name));
|
||||
std::string *sym2 = new std::string("__stop_" + std::string(chunk->name));
|
||||
start(Symbol<E>::intern(ctx, *sym1), chunk);
|
||||
stop(Symbol<E>::intern(ctx, *sym2), chunk);
|
||||
std::string_view sym1 =
|
||||
save_string(ctx, "__start_" + std::string(chunk->name));
|
||||
std::string_view sym2 =
|
||||
save_string(ctx, "__stop_" + std::string(chunk->name));
|
||||
|
||||
start(Symbol<E>::intern(ctx, sym1), chunk);
|
||||
stop(Symbol<E>::intern(ctx, sym2), chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user