Bug 17556 - crashing when mixing SHF_ALLOC and non SHF_ALLOC sections
Summary: crashing when mixing SHF_ALLOC and non SHF_ALLOC sections
Status: NEW
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Cary Coutant
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-05 13:38 UTC by Rafael Ávila de Espíndola
Modified: 2019-06-24 19:54 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rafael Ávila de Espíndola 2014-11-05 13:38:23 UTC
$ 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
Comment 1 H.J. Lu 2019-06-21 16:43:14 UTC
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)
       {
Comment 2 H.J. Lu 2019-06-21 16:50:14 UTC
gold can't handle input sections with the same name and different
flags.
Comment 3 H.J. Lu 2019-06-21 17:42:18 UTC
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.
Comment 4 H.J. Lu 2019-06-21 17:50:38 UTC
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;
-      }
   }
Comment 5 H.J. Lu 2019-06-24 19:54:30 UTC
A patch is posted at

https://sourceware.org/ml/binutils/2019-06/msg00193.html