We should error out when building a shared library / dynamic executable if incompatible relocations are present in the input files for the current linking model.
Reproducer:
#!/usr/bin/env bash
cat >1.c <<\EOF
#include <stdio.h>
int u ;
int main() {
u = 11;
printf("u: %d\n", u);
return 0;
}
EOF
cat >u.c <<\EOF
int u = 11;
int foo() { return u; }
EOF
musl-clang -o u.o u.c -c -ffunction-sections -fno-pic
LD=eld musl-clang -o libu.eld.so u.o -shared
The link works fine but it should fail with the error: invalid relocation 'R_X86_64_32S' against symbol u.