gcc 6.2.0试图创建共享对象,但它不应';T

gcc 6.2.0试图创建共享对象,但它不应';T,gcc,assembly,dynamic,static,gcc6,Gcc,Assembly,Dynamic,Static,Gcc6,在gcc 6.2.0之前,使用不可重定位的汇编代码链接从来都不是问题。我不知道具体的版本是什么,但在gcc 5.4.0(及以下版本)中,这是有效的: $ gcc -o httpget ../obj/httpget.o ../../../lib/libribs2_ssl.a -lssl -lcrypto 但是,对于gcc 6.2.0: $ gcc -o httpget ../obj/httpget.o ../../../lib/libribs2_ssl.a -lssl -lcrypto /usr

在gcc 6.2.0之前,使用不可重定位的汇编代码链接从来都不是问题。我不知道具体的版本是什么,但在gcc 5.4.0(及以下版本)中,这是有效的:

$ gcc -o httpget ../obj/httpget.o ../../../lib/libribs2_ssl.a -lssl -lcrypto
但是,对于gcc 6.2.0:

$ gcc -o httpget ../obj/httpget.o ../../../lib/libribs2_ssl.a -lssl -lcrypto
/usr/bin/ld: ../../../lib/libribs2_ssl.a(context_asm.o): relocation R_X86_64_32S against symbol `current_ctx' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
尝试强制静态链接会产生另一个问题:

$ gcc -static -o httpget ../obj/httpget.o ../../../lib/libribs2_ssl.a -lssl -lcrypto -ldl
/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
(.text+0x11): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
../obj/httpget.o: In function `main':
/home/nir/ribs2/examples/httpget/src/httpget.c:194: warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
使用gethostbyname()时,程序会出现故障(但在其他情况下有效)

同时,试图将静态和动态混合在一起也行不通

$ gcc -o httpget -Wl,-Bstatic ../obj/httpget.o ../../../lib/libribs2_ssl.a -Wl,-Bdynamic -lssl -lcrypto
/usr/bin/ld: ../../../lib/libribs2_ssl.a(context_asm.o): relocation R_X86_64_32S against symbol `current_ctx' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status

有什么想法吗?项目链接:

感谢@Jester的提示:将-no-pie(not-fno-pie)添加到LDFLAGS解决了问题

gcc -no-pie -o httpget ../obj/httpget.o ../../../lib/libribs2_ssl.a -lssl -lcrypto
此更改也适用于gcc 5.4。似乎默认设置已更改

更新:

这就是原因。从

在Ubuntu 16.10中,作为额外的编译器强化措施,我们 默认情况下,在amd64和ppc64le上启用饼图和即时绑定。 这大大提高了ASLR在这些平台上的有效性


我猜它可能想在默认情况下创建一个饼?尽管根据gcc.godbolt.org,情况并非如此。无论如何,您可能希望尝试添加
-fno PIE
,也可能编译另一个运行的测试程序,看看输出是否为PIE。谢谢,-链接时没有PIE。这个问题来自哪里?我升级系统时遇到了这个问题…@Saroupille,请参阅下面的更新。我猜其他发行版也在这样做。