[cfe-dev] Why clang creates ELF section group with only one section in it?

Dmitri Shubin sbn at tbricks.com
Thu May 10 09:34:48 PDT 2012


Hello!

I have the following linking problem with clang on Solaris 10:

$ cat -n a.cpp
      1  #include "a.h"
      2
      3  void baz()
      4  {
      5      bar(10);
      6  }
$ cat -n b.cpp
      1  #include "a.h"
      2
      3  void foo()
      4  {
      5      bar(12);
      6  }
$ cat -n a.h
      1  struct S
      2  {
      3      ~S();
      4  };
      5
      6  template<typename T>
      7  int bar(T t)
      8  {
      9      S s;
     10      return t*3;
     11  }
$ /opt/clang/bin/clang++ a.cpp b.cpp
ld: fatal: relocation error: file: /tmp/b-.qa4V1.o section: 
.rel.eh_frame symbol: : symbol has been discarded with discarded 
section: .text._Z3barIiEiT_
clang: error: linker command failed with exit code 1 (use -v to see 
invocation)

This happens only on releases < U10, so I suspect that this is due to 
some Solaris linker bug/restriction which was fixed/relaxed in U10.

But, I found that I can workaround this error by avoiding creating 
.group section in object files:

$ elfdump -g a.o

Group Section:  .group
      index    flags / section         signature symbol
        [0]   [ COMDAT ]               _Z3barIiEiT_
        [1]   .text._Z3barIiEiT_ [6]

This group contains only one section, is it really needed?

GCC (4.5.1, 4.7.0) doesn't create one.
Sun C++ 5.11 creates group with 2 sections: bar<int>() text and relocs.



More information about the cfe-dev mailing list