$ cat test.s .section .foo,"" $ cat test2.s .section .foo,"a" bar: $ gcc -c test.s $ gcc -c test2.s $ ld -shared -o test.so test.o test2.o ld: internal error in add_output_section_to_load, at ../../binutils/gold/output.cc:4093
This avoids crash: diff --git a/gold/object.cc b/gold/object.cc index 689448f50c..9051438e73 100644 --- a/gold/object.cc +++ b/gold/object.cc @@ -1644,6 +1644,13 @@ Sized_relobj_file<size, big_endian>::do_layout(Symbol_table* symtab, omit[i] = true; } + // Skip empty sections without flags. + if (!(shdr.get_sh_flags() & ~elfcpp::SHF_GROUP) + && !shdr.get_sh_size()) + { + omit[i] = true; + } + bool discard = omit[i]; if (!discard) {
gold can't handle input sections with the same name and different flags.
Layout::get_output_section has // This is the first time we've seen this name/type/flags // combination. For compatibility with the GNU linker, we // combine sections with contents and zero flags with sections // with non-zero flags. This is a workaround for cases where // assembler code forgets to set section flags. FIXME: Perhaps // there should be an option to control this. This is broken.
This works: diff --git a/gold/layout.cc b/gold/layout.cc index b83e8e6e2d..a8f6525cb0 100644 --- a/gold/layout.cc +++ b/gold/layout.cc @@ -868,16 +868,6 @@ Layout::get_output_section(const char* name, Stringpool::Key name_key, && (same_name->flags() & elfcpp::SHF_TLS) == 0) os = same_name; } - else if ((flags & elfcpp::SHF_TLS) == 0) - { - elfcpp::Elf_Xword zero_flags = 0; - const Key zero_key(name_key, std::make_pair(lookup_type, - zero_flags)); - Section_name_map::iterator p = - this->section_name_map_.find(zero_key); - if (p != this->section_name_map_.end()) - os = p->second; - } }
A patch is posted at https://sourceware.org/ml/binutils/2019-06/msg00193.html