Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Fix building Ubuntu shared libraries #4988

Closed
tonerdo opened this issue Nov 22, 2017 · 5 comments · Fixed by #7249
Closed

Fix building Ubuntu shared libraries #4988

tonerdo opened this issue Nov 22, 2017 · 5 comments · Fixed by #7249

Comments

@tonerdo
Copy link
Contributor

tonerdo commented Nov 22, 2017

Currently building shared libraries (.so) on Ubuntu throws the below error:

/usr/bin/ld: obj/Debug/netstandard2.0/native/cslib.o: relocation R_X86_64_PC32 against symbol `__NewArr1___Array<Object>' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value

Parent issue: #1285

@tonerdo
Copy link
Contributor Author

tonerdo commented Apr 15, 2018

Made another attempt, this time using the gold linker and this is what I get:

ld.gold: error: obj/Debug/netstandard2.0/native/cslib.o: requires dynamic R_X86_64_PC32 reloc against '__readonlydata_S_P_TypeLoader_System_Reflection_Runtime_General_QHandle____GetFieldHelper' which may
 overflow at runtime; recompile with -fPIC
ld.gold: error: obj/Debug/netstandard2.0/native/cslib.o: requires dynamic R_X86_64_PC32 reloc against '_ZTV61S_P_CoreLib_System_Resources_MissingManifestResourceException' which may overflow at runtime;
recompile with -fPIC
ld.gold: error: obj/Debug/netstandard2.0/native/cslib.o: requires dynamic R_X86_64_PC32 reloc against 'Internal_CompilerGenerated__Module___InvokeRetOI<System___Canon__Int32>' which may overflow at runti
me; recompile with -fPIC
ld.gold: error: obj/Debug/netstandard2.0/native/cslib.o: requires dynamic R_X86_64_PC32 reloc against 'S_P_TypeLoader_System_Collections_Generic_ArrayBuilder_1<System___Canon>____GetFieldHelper' which ma
y overflow at runtime; recompile with -fPIC
ld.gold: error: obj/Debug/netstandard2.0/native/cslib.o: requires dynamic R_X86_64_PC32 reloc against '_ZTV74Boxed_S_P_Reflection_Metadata_Internal_Metadata_NativeFormat_AssemblyFlags' which may overflow
 at runtime; recompile with -fPIC
ld.gold: error: obj/Debug/netstandard2.0/native/cslib.o: requires dynamic R_X86_64_PC32 reloc against 'S_P_TypeLoader_System_Reflection_Runtime_General_QHandle____GetFieldHelper' which may overflow at ru
ntime; recompile with -fPIC
ld.gold: error: obj/Debug/netstandard2.0/native/cslib.o: requires dynamic R_X86_64_PC32 reloc against '_lsda0S_P_TypeLoader_System_Reflection_Runtime_General_QHandle____GetFieldHelper' which may overflow
 at runtime; recompile with -fPIC
ld.gold: error: /root/Workspace/corert/bin/Linux.x64.Debug/sdk/libRuntime.a(AllocFast.S.o): requires dynamic R_X86_64_PC32 reloc against 'RhExceptionHandling_FailedAllocation' which may overflow at runti
me; recompile with -fPIC
ld.gold: error: /root/Workspace/corert/bin/Linux.x64.Debug/sdk/libRuntime.a(ExceptionHandling.S.o): requires dynamic R_X86_64_PC32 reloc against 'RhThrowHwEx' which may overflow at runtime; recompile wit
h -fPIC
ld.gold: error: /root/Workspace/corert/bin/Linux.x64.Debug/sdk/libRuntime.a(StubDispatch.S.o): requires dynamic R_X86_64_PC32 reloc against 'RhpCidResolve' which may overflow at runtime; recompile with -
fPIC

@tonerdo
Copy link
Contributor Author

tonerdo commented Apr 15, 2018

Full clang command:

clang-3.9 "obj/Debug/netstandard2.0/native/cslib.o" -o "bin/Debug/netstandard2.0/native/cslib.so" -exported_symbols_list "obj/Debug/netstandard2.0/native/cslib.export
s" /root/Workspace/corert/bin/Linux.x64.Debug/sdk/libbootstrapperdll.a /root/Workspace/corert/bin/Linux.x64.Debug/sdk/libRuntime.a /root/Workspace/corert/bin/Linux.x64.Debug/sdk/libSystem.Private.CoreLib
.Native.a /root/Workspace/corert/bin/Linux.x64.Debug/framework/System.Native.a /root/Workspace/corert/bin/Linux.x64.Debug/framework/System.Globalization.Native.a /root/Workspace/corert/bin/Linux.x64.Debu
g/framework/System.IO.Compression.Native.a /root/Workspace/corert/bin/Linux.x64.Debug/framework/System.Net.Http.Native.a /root/Workspace/corert/bin/Linux.x64.Debug/framework/System.Net.Security.Native.a
/root/Workspace/corert/bin/Linux.x64.Debug/framework/System.Security.Cryptography.Native.OpenSsl.a -g -Wl,-rpath,'$ORIGIN' -pthread -lstdc++ -ldl -lm -lcurl -lz -lgssapi_krb5 -lrt -shared

Resulting ld command:

"/usr/bin/ld" -z relro --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -shared -o bin/Debug/netstandard2.0/native/cslib.so /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu/crti.o /usr/
bin/../lib/gcc/x86_64-linux-gnu/5.4.0/crtbeginS.o -L/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0 -L/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib
64 -L/usr/lib/x86_64-linux-gnu -L/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../.. -L/usr/lib/llvm-3.9/bin/../lib -L/lib -L/usr/lib obj/Debug/netstandard2.0/native/cslib.o /root/Workspace/corert/bin/Li
nux.x64.Debug/sdk/libbootstrapperdll.a /root/Workspace/corert/bin/Linux.x64.Debug/sdk/libRuntime.a /root/Workspace/corert/bin/Linux.x64.Debug/sdk/libSystem.Private.CoreLib.Native.a /root/Workspace/corert
/bin/Linux.x64.Debug/framework/System.Native.a /root/Workspace/corert/bin/Linux.x64.Debug/framework/System.Globalization.Native.a /root/Workspace/corert/bin/Linux.x64.Debug/framework/System.IO.Compressio
n.Native.a /root/Workspace/corert/bin/Linux.x64.Debug/framework/System.Net.Http.Native.a /root/Workspace/corert/bin/Linux.x64.Debug/framework/System.Net.Security.Native.a /root/Workspace/corert/bin/Linux
.x64.Debug/framework/System.Security.Cryptography.Native.OpenSsl.a -rpath "\$ORIGIN" -lstdc++ -ldl -lm -lcurl -lz -lgssapi_krb5 -lrt -lgcc --as-needed -lgcc_s --no-as-needed -lpthread -lc -lgcc --as-need
ed -lgcc_s --no-as-needed /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/crtendS.o /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu/crtn.o

@darderik
Copy link
Contributor

darderik commented May 6, 2018

May I ask if there are any updates on this?

@szhaomsft
Copy link

when this is going to be fixed? it is pretty important platform to support

i tried the sample of native library to build as a shared library and hit below errors

clang : warning : argument unused during compilation: '-exported_symbols_list obj/release/netstandard2.0/linux-x64/native/NativeLibrary.exports'

/usr/bin/ld: obj/release/netstandard2.0/linux-x64/native/NativeLibrary.o: relocation R_X86_64_PC32 against symbol `__readonlydata_S_P_TypeLoader_System_Reflection_Runtime_General_QHandle____GetFieldHelper' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value

@MichalStrehovsky
Copy link
Member

There's a work in progress pull request in #6847, but I'll need someone to volunteer to finish it up.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants