gcc 6.2.0是否尝试创建共享对象? [英] gcc 6.2.0 is attempting to create shared object when it shouldn't?

查看:96
本文介绍了gcc 6.2.0是否尝试创建共享对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用不可重定位的汇编代码,直到gcc 6.2.0为止,链接从未成为问题.我不知道确切的版本,但在gcc 5.4.0(及更低版本)下可以正常工作:

With non relocatable assembler code linking was never a problem up until gcc 6.2.0. I don't know the exact version that stared this, but with gcc 5.4.0 (and below) this worked:

$ gcc -o httpget ../obj/httpget.o ../../../lib/libribs2_ssl.a -lssl -lcrypto

但是,对于gcc 6.2.0:

However, with 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

尝试强制进行静态链接会产生另一个问题:

Trying to force static linking creates another problem:

$ 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()时程序会出现段错误(但可以正常工作)

And the program segfaults when using gethostbyname() (but works otherwise)

尝试将静态和动态混合使用也不可行.

Also trying to mix static and dynamic doesn't work.

$ 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

有什么想法吗?链接到项目: https://github.com/niryeffet/ribs2

Any ideas? Link to the project: https://github.com/niryeffet/ribs2

推荐答案

感谢@Jester的提示:在LDFLAGS中添加-no-pie(不是-fno-PIE)可以解决此问题.

Thanks to the hint from @Jester: adding -no-pie (not -fno-PIE) to LDFLAGS solved the problem.

gcc -no-pie -o httpget ../obj/httpget.o ../../../lib/libribs2_ssl.a -lssl -lcrypto

更改也适用于gcc 5.4.默认值似乎已更改.

The change also works on gcc 5.4. It seems as the default has changed.

更新:

这可以解释.来自 https://wiki.ubuntu.com/SecurityTeam/PIE

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

In Ubuntu 16.10, as an additional compiler hardening measure, we've enabled PIE and immediate binding by default on amd64 and ppc64le. This greatly increases the effectiveness of ASLR on those platforms.

这篇关于gcc 6.2.0是否尝试创建共享对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆