1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-11 05:46:58 +03:00

Make it compile with GCC-11

Fixes https://github.com/rui314/mold/issues/37
This commit is contained in:
Rui Ueyama 2021-06-05 19:52:25 +09:00
parent 89ccfa1a00
commit 214bcb2f48
5 changed files with 40 additions and 28 deletions

View File

@ -43,7 +43,8 @@ bool GlobPattern::match(std::string_view str) const {
return str.starts_with(pat);
case SUFFIX:
return str.ends_with(pat);
case GENERIC:
default:
assert(kind == GENERIC);
return generic_match(pat, str);
}
}

View File

@ -54,6 +54,8 @@ public:
return *this;
}
[[noreturn]] ~SyntaxError() = default;
Fatal<E> out;
};

29
mold.h
View File

@ -916,15 +916,15 @@ public:
InputFile(Context<E> &ctx, MemoryMappedFile<E> *mb);
InputFile() : name("<internal>") {}
template<typename T> std::span<T>
inline get_data(Context<E> &ctx, const ElfShdr<E> &shdr);
template<typename T> std::span<T>
inline get_data(Context<E> &ctx, i64 idx);
inline std::string_view get_string(Context<E> &ctx, const ElfShdr<E> &shdr);
inline std::string_view get_string(Context<E> &ctx, i64 idx);
template<typename T> std::span<T>
get_data(Context<E> &ctx, const ElfShdr<E> &shdr);
template<typename T> std::span<T>
get_data(Context<E> &ctx, i64 idx);
ElfShdr<E> *find_section(i64 type);
MemoryMappedFile<E> *mb;
@ -2086,6 +2086,23 @@ inline std::span<FdeRecord<E>> InputSection<E>::get_fdes() const {
return span.subspan(fde_begin, fde_end - fde_begin);
}
template <typename E>
template <typename T>
inline std::span<T> InputFile<E>::get_data(Context<E> &ctx, const ElfShdr<E> &shdr) {
std::string_view view = this->get_string(ctx, shdr);
if (view.size() % sizeof(T))
Fatal(ctx) << *this << ": corrupted section";
return {(T *)view.data(), view.size() / sizeof(T)};
}
template <typename E>
template <typename T>
inline std::span<T> InputFile<E>::get_data(Context<E> &ctx, i64 idx) {
if (elf_sections.size() <= idx)
Fatal(ctx) << *this << ": invalid section index";
return this->template get_data<T>(elf_sections[idx]);
}
template <typename E>
inline std::string_view
InputFile<E>::get_string(Context<E> &ctx, const ElfShdr<E> &shdr) {

View File

@ -101,23 +101,6 @@ InputFile<E>::InputFile(Context<E> &ctx, MemoryMappedFile<E> *mb)
shstrtab = this->get_string(ctx, shstrtab_idx);
}
template <typename E>
template <typename T>
std::span<T> InputFile<E>::get_data(Context<E> &ctx, const ElfShdr<E> &shdr) {
std::string_view view = this->get_string(ctx, shdr);
if (view.size() % sizeof(T))
Fatal(ctx) << *this << ": corrupted section";
return {(T *)view.data(), view.size() / sizeof(T)};
}
template <typename E>
template <typename T>
std::span<T> InputFile<E>::get_data(Context<E> &ctx, i64 idx) {
if (elf_sections.size() <= idx)
Fatal(ctx) << *this << ": invalid section index";
return this->template get_data<T>(elf_sections[idx]);
}
template <typename E>
ElfShdr<E> *InputFile<E>::find_section(i64 type) {
for (ElfShdr<E> &sec : elf_sections)

View File

@ -47,7 +47,12 @@ std::function<void()> fork_child() {
// Child
close(pipefd[0]);
return [=]() { write(pipefd[1], (char []){1}, 1); };
return [=]() {
char buf[] = {1};
int n = write(pipefd[1], buf, 1);
assert(n == 1);
};
}
static std::string base64(u8 *data, u64 size) {
@ -81,7 +86,8 @@ static std::string compute_sha256(std::span<std::string_view> argv) {
for (std::string_view arg : argv) {
if (arg != "-preload" && arg != "--preload") {
SHA256_Update(&sha, arg.data(), arg.size());
SHA256_Update(&sha, (char []){0}, 1);
char buf[] = {0};
SHA256_Update(&sha, buf, 1);
}
}
@ -158,7 +164,9 @@ void try_resume_daemon(Context<E> &ctx) {
send_fd(ctx, conn, STDOUT_FILENO);
send_fd(ctx, conn, STDERR_FILENO);
i64 r = read(conn, (char[1]){}, 1);
char buf[1];
i64 r = read(conn, buf, 1);
close(conn);
if (r == 1)
exit(0);
@ -228,7 +236,8 @@ void daemonize(Context<E> &ctx, std::function<void()> *wait_for_client,
*on_complete = [=]() {
char buf[] = {1};
write(conn, buf, 1);
int n = write(conn, buf, 1);
assert(n == 1);
};
}