diff --git a/mold.h b/mold.h index 31924022..96447642 100644 --- a/mold.h +++ b/mold.h @@ -147,7 +147,7 @@ class Symbol { public: Symbol(StringRef name, ObjectFile *file = nullptr) : name(name), file(file), needs_got(false), needs_gotplt(false), - needs_gottp(false), needs_plt(false), is_weak(false), + needs_gottp(false), needs_plt(false), is_dso(false), is_weak(false), is_undef_weak(false) {} Symbol(const Symbol &other) : Symbol(other.name, other.file) {} @@ -175,6 +175,7 @@ public: u8 needs_gotplt : 1; u8 needs_gottp : 1; u8 needs_plt : 1; + u8 is_dso : 1; u8 is_weak : 1; u8 is_undef_weak : 1; diff --git a/object_file.cc b/object_file.cc index 036e76e2..c179c130 100644 --- a/object_file.cc +++ b/object_file.cc @@ -197,7 +197,11 @@ void ObjectFile::parse() { } - initialize_sections(); + if (is_dso) + sections.resize(elf_sections.size()); + else + initialize_sections(); + if (symtab_sec) initialize_symbols(); } @@ -231,6 +235,7 @@ void ObjectFile::register_defined_symbols() { sym.type = esym.getType(); sym.visibility = esym.getVisibility(); sym.is_weak = is_weak; + sym.is_dso = is_dso; } } } diff --git a/test/hello-static.s b/test/hello-static.s index 222512a2..5f8d0b06 100644 --- a/test/hello-static.s +++ b/test/hello-static.s @@ -1,5 +1,5 @@ // RUN: cc -o %t.o -c %s -// RUN: mold -o %t.exe /usr/lib/x86_64-linux-gnu/crt1.o \ +// RUN: mold -static -o %t.exe /usr/lib/x86_64-linux-gnu/crt1.o \ // RUN: /usr/lib/x86_64-linux-gnu/crti.o \ // RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbeginT.o \ // RUN: %t.o \