[LLVMdev] [lld] Regression with init_array for clang

Adhemerval Zanella adhemerval.zanella at linaro.org
Tue Jun 23 12:37:36 PDT 2015


Hi,

Checking the llvm test-suite with latest clang/lld I noticed some regressions
on both x86_64 and aarch64.  Tracking down I found it is due 'ldd' not being
handling correct the init_array segments for some cases.  

For instance the code:

global_ctor.cpp:

#include <stdio.h>
//extern int printf(const char *, ...);

int CN = 0;
int DN = 0;

struct foo {
  int Num;
  foo(int num) : Num(num) {
    printf("Foo ctor %d %d\n", Num, CN++);
  }
  ~foo() {
    printf("Foo dtor %d %d\n", Num, DN++);
  }
} Constructor1(7);     // Global with ctor to be called before main
foo Constructor2(12);

struct bar {
  ~bar() {
    printf("bar dtor\n");
  }
} Destructor1;     // Global with dtor

int main() {
  printf("main\n");
  return 0;
}

GCC 4.9 generates:

Section Headers:
[...]
  [15] .init_array       INIT_ARRAY       0000000000000000  000001c0
       0000000000000008  0000000000000000  WA       0     0     8
[...]
Symbol table '.symtab' contains 37 entries:
[...]
    11: 0000000000000000     0 SECTION LOCAL  DEFAULT   15
[...]

While clang (trunk):
[...]
  [18] .init_array       INIT_ARRAY       0000000000000000  00000270
       0000000000000008  0000000000000000  WA       0     0     8
[...]

Main difference is clang is not adding the init_array symbol in .symtab.  This
makes ldd ignore the object section in ELFFile<ELFT>::createSymbolsFromAtomizableSections
and thus not updating the init_array in final executable with object's init_array
(and not triggering the object constructors).

Now, the question is if this is a clang regression (since the test-suite was not
failing two weeks ago), or it is something ldd should handle (since ld/gold handles
it correctly). Also for 'ldd' which would be best strategy to handle such case:
create a empty section atom (createSectionAtom(...)) if some 'runtime' segments
are present (init_array, etc.)?



More information about the llvm-dev mailing list