<div dir="ltr">Hello.<div><br>I'm working on building a non-gun toolchain with musl, clang, llvm, libunwind, libcxx, libcxxabi and compiler-rt for our project. While static and pie compilation are very useful in our project, C++ programs crash while running with the crtbegin from the compiler-rt in static-pie compilation. <br><br>I tested different combinations on both c program and c++ program: static-pie with/without compiler-rt and pie with/without compiler-rt. While all other tests passed but only C++ program crashed when enabling static-pie and compiler-rt. <br>To figured out why it crashes, I used GDB and it shows that the program crashed because at the _dlstart_c function in musl, rel[0] in line 140 is an address out of address space. </div><div><br>``` <br>136    rel = (void *)(base+dyn[DT_RELA]);<br>137    rel_size = dyn[DT_RELASZ];<br>138    for (; rel_size; rel+=3, rel_size-=3*sizeof(size_t)) {<br>139        if (!IS_RELATIVE(rel[1], 0)) continue;<br>140        size_t *rel_addr = (void *)(base + rel[0]);<br>141        *rel_addr = base + rel[2];<br>142    }<br>```<br><br>Here[1] is my script to build a toolchain based on musl and llvm for ubuntu 16.04(I also attached it below). It will install the toolchain into /usr/local/occlum/.<div>To compiler a c++ program, use : musl-clang hello.cc -I /usr/local/occlum/include/c++/v1/  -static-pie -lc++ -lc++abi -fPIC -o hello --rtlib=compiler-rt<br><br>Is it looks like a bug in llvm or compiler-rt? Or did I make some stupid mistake in my script?<br clear="all"><div>Im really appreciate for any response.</div><div><br></div><div>[1]. <a href="https://gist.github.com/Yourens/0794bfad63bc54e5890d5ee828120ebf">https://gist.github.com/Yourens/0794bfad63bc54e5890d5ee828120ebf</a><br></div>-- <br><div dir="ltr" data-smartmail="gmail_signature"><div dir="ltr">Best Regards.<div>Youren Shen.</div></div></div></div></div></div>