gcc-fPIC-fPIE:gcc-4和gcc-6之间的差异
序言:这个问题与Oracle无关,相反,我想了解gcc-4和gcc-6在处理位置无关代码方面的根本区别 因此,我决定尝试在Debian上安装Oracle12c 在与gcc-6的链接阶段,会发出如下错误消息:gcc-fPIC-fPIE:gcc-4和gcc-6之间的差异,gcc,gcc4,gcc6,Gcc,Gcc4,Gcc6,序言:这个问题与Oracle无关,相反,我想了解gcc-4和gcc-6在处理位置无关代码方面的根本区别 因此,我决定尝试在Debian上安装Oracle12c 在与gcc-6的链接阶段,会发出如下错误消息: /usr/bin/ld: /opt/oracle/product/12.2.0/lib/libpls12.a(pci.o): relocation R_X86_64_32S against `.rodata.str1.4' can not be used when making a sh
/usr/bin/ld: /opt/oracle/product/12.2.0/lib/libpls12.a(pci.o):
relocation R_X86_64_32S against `.rodata.str1.4' can not be used when making a shared object;
recompile with -fPIC.
但是,如果我将编译器切换为使用gcc-4.9,则所有链接都会顺利完成
因此,我有两个问题:
- gcc版本4和6之间-fPIC和-fPIE的默认值是否有变化?很可能是的,版本6默认使用这两个选项
- 对我来说更重要的是:gcc版本6是否有使用版本4行为生成位置无关代码的选项?(或者我迟早会因为gcc-4不再可用而无法链接到旧库吗?)
UNIX # gcc-6 -g -Wall -fno-pic -c helloworld.c -o helloworld.o
UNIX # gcc-6 -g -Wall helloworld.o -o helloworld
/usr/bin/ld: helloworld.o: relocation R_X86_64_32 against `.rodata' 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
UNIX # gcc-6 -g -Wall -no-pie helloworld.o -o helloworld
事实上,在Oracle使用的gcc选项中添加了-no-pie之后,链接就可以正常工作了。来自broeni的解决方案可以正常工作。我还采取了一些额外的措施使其发挥作用: 在安装过程中,我修改了oracle的默认链接器工具,编辑了文件
/opt/oracle/product/12.2.0/db1/bin/orald
在第一行中,我强制使用GCC链接器,并添加了-no pie选项:
#if [ -z "$BASH_VERSION" -o -n "$ORALD_USE_GCC" ] ; then
exec gcc -no-pie "$@"
exit 1
#fi
标签:oracle 12c debian stretch