链接静态(.a)中库与共享(的.so)库,得到错误"针对局部符号搬迁R_X86_64_32S;重新编译-fPIC"静态、局部、符号、错误

2023-09-08 10:39:19 作者:古川奈奈酱

使用eclipse在redhat使用g ++ 64位编译。

编译错误: ../lib-EL5-64bit/libskd3_clnt_30134500.a(skd_clnt.o):搬迁R_X86_64_32S对创建共享目标时,不能使用'局部符号;重新编译-fPIC

东西我都试过 我加了-fPIC到了C ++编译器标志,以及链接标志。它已经存在于编译器标志,我只是把它移到后直接g ++以及在列表的末尾。

我问过的。一个图书馆的创建者重新编译-fPIC,它仍然给出了同样的错误

有没有什么办法,以确保他们的图书馆与-fPIC编译? 请问错误信息说我需要用-fPIC编译我的。所以,还是某文件需要使用-fPIC编译? 我还能怎么检查?

下面是生成文件(自动Eclipse生成)

请文件:

  ###################################### ##########################################
#自动生成的文件。不要编辑!
################################################## ##############################

-include ../makefile.init

RM:= RM -rf

#所有参与该构建的源极这里定义
-include sources.mk
-include subdir.mk
-include generic_d2s / subdir.mk
-include objects.mk

ifneq($(MAKECMDGOALS),清洁)
ifneq($(带$(C ++ _ DEPS)))
-include $(C ++ _ DEPS)
ENDIF
ifneq($(带$(C_DEPS)))
-include $(C_DEPS)
ENDIF
ifneq($(带$(CC_DEPS)))
-include $(CC_DEPS)
ENDIF
ifneq($(带$(CPP_DEPS)))
-include $(CPP_DEPS)
ENDIF
ifneq($(带$(CXX_DEPS)))
-include $(CXX_DEPS)
ENDIF
ifneq($(带$(C_UPPER_DEPS)))
-include $(C_UPPER_DEPS)
ENDIF
ENDIF

-include ../makefile.defs

#来自这些工具调用添加输入和输出到构建变量

#所有目标
所有:libFUSE.so

#工具调用
libFUSE.so:$(OBJS)$(USER_OBJS)
    @echo建设目标:$ @
    @echo'调用:GCC C ++链接器
    G ++ -fPIC -L ../../ CRYPTOPP / lib目录,EL5-64bit -L ../ LIB-EL5-64bit -Wl,-rpath / lib目录-shared -olibFUSE.so$(OBJS)$( USER_OBJS)$(LIBS)
    @echo已完成建设目标:$ @
    @回声 ' '

#其他目标
清洁:
     -  $(RM)$(OBJS)$(C ++ _ DEPS)$(C_DEPS)$(CC_DEPS)$(库)$(CPP_DEPS)$(CXX_DEPS)$(C_UPPER_DEPS)libFUSE.so
    -@回声 ' '

.PHONY:都是干净的家属
.SECONDARY:

-include ../makefile.targets
 
ubuntu下初试静态库.a 与共享库.so

subdir.mk

  ###################################### ##########################################
#自动生成的文件。不要编辑!
################################################## ##############################

#来自这些工具调用添加输入和输出到构建变量
CPP_SRCS + = \
../CRI.cpp


C_SRCS + = \
../client_rsa.c

OBJS + = \
./CRI.o


C_DEPS + = \
./client_rsa.d

CPP_DEPS + = \
./CRI.d


#每个子目录都必须提供它有助于建设资源规则
%的.o:../%.cpp
    @echo建设文件:$<
    @echo'调用:GCC C ++编译器
    G ++ -D_TM_CDIR =/凸出/ Kronos的/测试/ HHO / testprograms /中继/ testmethods / FUSE'-I ../../ CRYPTOPP /有/ cryptopp -I的/ opt / hp93000 / SOC / PWS / lib目录-I的/ opt / hp93000 / SOC / COM /包括-I /选择/ hp93000 / SOC / prod_com /包括-I /选择/ hp93000 / SOC / prod_com /有/ MAPI -I /选择/ hp93000 / SOC / TestMethod的/有-O0 -g3 -Wall -c -fmessage长度= 0 -fPIC -shared -Wreturn型-Wmissing-括号-Wswitch -Wparentheses -Wunused功能-Wunused标签-Wunused参数-Wunused变量 - Wunused价值-Wunknown-编译指示-Wsign-比较-Wconversion -fPIC -MMD -MP -MF$(@:%O =%D。)-MT$(@:%O =%d) -o$ @$<
    @echo已完成建设:$<
    @回声 ' '

%的.o:../%.c
    @echo建设文件:$<
    @echo'调用:GCC C编译器
    GCC -D_TM_CDIR =/凸出/ Kronos的/测试/ HHO / testprograms /中继/ testmethods / FUSE' - 我的/ opt / hp93000 / SOC / prod_com /包括-I /选择/ hp93000 / SOC / prod_com /有/ MAPI -I / OPT / hp93000 / SOC / TestMethod的/包括-I /选择/ hp93000 / SOC / COM /包括-I /选择/ hp93000 / SOC / PWS / lib目录-O0 -g3 -Wall -c -fmessage长度= 0 -fPIC -Wreturn型-Wmissing-括号-Wswitch -Wparentheses -Wunused功能-Wunused标签-Wunused参数-Wunused变量-Wunused价值-Wunknown-编译指示-Wsign-比较-Wconversion -MMD -MP -MF $(@:%O =%D。)-MT$(@:%O =%d)-o$ @$<
    @echo已完成建设:$<
    @回声 ' '
 

objects.mk

  ###################################### ##########################################
#自动生成的文件。不要编辑!
################################################## ##############################

USER_OBJS:=

LIBS:= -lBB_IO_lib.0.1 -lskd3_clnt_30134500 -lcryptopp
 

sources.mk

  ###################################### ##########################################
#自动生成的文件。不要编辑!
################################################## ##############################

O_SRCS:=
CPP_SRCS:=
C_UPPER_SRCS:=
C_SRCS:=
S_UPPER_SRCS:=
OBJ_SRCS:=
ASM_SRCS:=
CXX_SRCS:=
C ++ _ SRCS:=
CC_SRCS:=
OBJS:=
C ++ _ DEPS:=
C_DEPS:=
CC_DEPS:=
库:=
CPP_DEPS:=
CXX_DEPS:=
C_UPPER_DEPS:=

#与源文件中的每个子目录必须在这里说明
SUBDIRS:= \
。 \
generic_d2s \
 

解决方案

在静态编译,汇编指令将承担大约code,如当地一些事情任何跳跃距离的跳跃/调用指令的4GB。 (假设64B 86)。共享库可以加载渐行渐远超过4GB,让跳跃/调用不会配合。

在编译-fPIC(位置无关code) - 编译器将确保code和本地数据引用是位置indepdent,并安排呼叫/跳转自身之外发生的最坏情况/最大寻址模式(例如全64B)。

当你得到这个错误,因为你有,静态库还不能妄下共享库 - 快捷键上面的拍摄。唯一的办法是用-fPIC重新编译。 (从技术上讲,32位跳可能只有5个字节,但你需要9个字节[1 OP code + 8的地址],所以再多的汇编聪明可以解决这 - 不是没有其他一些卑鄙的操作,喜欢用INT指令提供了手短跳转)。

如今,大多数都可以/应该用-fPIC编译不论被共享 - 除非性能是非常重要的。

Compiling with g++ 64 bit in redhat using eclipse.

Compile Error: ../lib-EL5-64bit/libskd3_clnt_30134500.a(skd_clnt.o): relocation R_X86_64_32S against `a local symbol' can not be used when making a shared object; recompile with -fPIC

Things I have tried I added -fPIC to both the c++ compiler flags, as well as the linker flags. It already existed in the compiler flags, i just moved it to directly after the g++, and at the end of the list.

I've asked the creator of the .a library to recompile with -fPIC and it still gives the same error

Is there any way to make sure that their library was compiled with -fPIC? Does the error message say that I need to compile my .so with -fPIC, or the .a file needs to be compiled with -fPIC? What else can I check?

Here is the make file (auto generated by eclipse)

Make file:

################################################################################
# Automatically-generated file. Do not edit!
################################################################################

-include ../makefile.init

RM := rm -rf

# All of the sources participating in the build are defined here
-include sources.mk
-include subdir.mk
-include generic_d2s/subdir.mk
-include objects.mk

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C++_DEPS)),)
-include $(C++_DEPS)
endif
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
ifneq ($(strip $(CC_DEPS)),)
-include $(CC_DEPS)
endif
ifneq ($(strip $(CPP_DEPS)),)
-include $(CPP_DEPS)
endif
ifneq ($(strip $(CXX_DEPS)),)
-include $(CXX_DEPS)
endif
ifneq ($(strip $(C_UPPER_DEPS)),)
-include $(C_UPPER_DEPS)
endif
endif

-include ../makefile.defs

# Add inputs and outputs from these tool invocations to the build variables 

# All Target
all: libFUSE.so

# Tool invocations
libFUSE.so: $(OBJS) $(USER_OBJS)
    @echo 'Building target: $@'
    @echo 'Invoking: GCC C++ Linker'
    g++ -fPIC -L../../CRYPTOPP/lib-EL5-64bit -L../lib-EL5-64bit -Wl,-rpath /lib -shared -o"libFUSE.so" $(OBJS) $(USER_OBJS) $(LIBS)
    @echo 'Finished building target: $@'
    @echo ' '

# Other Targets
clean:
    -$(RM) $(OBJS)$(C++_DEPS)$(C_DEPS)$(CC_DEPS)$(LIBRARIES)$(CPP_DEPS)$(CXX_DEPS)$(C_UPPER_DEPS) libFUSE.so
    -@echo ' '

.PHONY: all clean dependents
.SECONDARY:

-include ../makefile.targets

subdir.mk

################################################################################
# Automatically-generated file. Do not edit!
################################################################################

# Add inputs and outputs from these tool invocations to the build variables 
CPP_SRCS += \
../CRI.cpp 


C_SRCS += \
../client_rsa.c 

OBJS += \
./CRI.o 


C_DEPS += \
./client_rsa.d 

CPP_DEPS += \
./CRI.d 


# Each subdirectory must supply rules for building sources it contributes
%.o: ../%.cpp
    @echo 'Building file: $<'
    @echo 'Invoking: GCC C++ Compiler'
    g++ -D_TM_CDIR='"/proj/kronos/test/hho/testprograms/trunk/testmethods/FUSE"' -I../../CRYPTOPP/include/cryptopp -I"/opt/hp93000/soc/pws/lib" -I"/opt/hp93000/soc/com/include" -I/opt/hp93000/soc/prod_com/include -I/opt/hp93000/soc/prod_com/include/MAPI -I/opt/hp93000/soc/testmethod/include -O0 -g3 -Wall -c -fmessage-length=0 -shared -fPIC  -Wreturn-type -Wmissing-braces -Wparentheses -Wswitch -Wunused-function -Wunused-label -Wunused-parameter -Wunused-variable -Wunused-value -Wunknown-pragmas -Wsign-compare -Wconversion -fPIC -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
    @echo 'Finished building: $<'
    @echo ' '

%.o: ../%.c
    @echo 'Building file: $<'
    @echo 'Invoking: GCC C Compiler'
    gcc -D_TM_CDIR='"/proj/kronos/test/hho/testprograms/trunk/testmethods/FUSE"' -I/opt/hp93000/soc/prod_com/include -I/opt/hp93000/soc/prod_com/include/MAPI -I/opt/hp93000/soc/testmethod/include -I/opt/hp93000/soc/com/include -I/opt/hp93000/soc/pws/lib -O0 -g3 -Wall -c -fmessage-length=0 -fPIC  -Wreturn-type -Wmissing-braces -Wparentheses -Wswitch -Wunused-function -Wunused-label -Wunused-parameter -Wunused-variable -Wunused-value -Wunknown-pragmas -Wsign-compare -Wconversion -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
    @echo 'Finished building: $<'
    @echo ' '

objects.mk

################################################################################
# Automatically-generated file. Do not edit!
################################################################################

USER_OBJS :=

LIBS := -lBB_IO_lib.0.1 -lskd3_clnt_30134500 -lcryptopp

sources.mk

################################################################################
# Automatically-generated file. Do not edit!
################################################################################

O_SRCS := 
CPP_SRCS := 
C_UPPER_SRCS := 
C_SRCS := 
S_UPPER_SRCS := 
OBJ_SRCS := 
ASM_SRCS := 
CXX_SRCS := 
C++_SRCS := 
CC_SRCS := 
OBJS := 
C++_DEPS := 
C_DEPS := 
CC_DEPS := 
LIBRARIES := 
CPP_DEPS := 
CXX_DEPS := 
C_UPPER_DEPS := 

# Every subdirectory with source files must be described here
SUBDIRS := \
. \
generic_d2s \

解决方案

When you compile statically, the assembler instructions will assume certain things about the locality of code, e.g. any jump is within 4GB of the jumping/calling instruction. (Assuming 64b x86). Shared libraries may be loaded further away than 4GB, so that jump/call wont fit.

When you compile with -fPIC (position independent code) - the compiler will ensure that the code and local data references are position indepdent, and arrange for calls/jumps outside of itself happen with the worst case/maximum addressing mode (eg full 64b).

When you get this error, as you have, the static library cannot jump to the shared library - the shortcuts above were taken. The only solution is a recompile with -fPIC. (Technically, the 32-bit jump may only be 5 bytes but you need 9 bytes [1 opcode + 8 for the addr]; so no amount of assembler cleverness can work around this - not without some other dastardly operation, like using INT instructions to provide a short hand jump).

Nowadays most everything can/should be compiled with -fPIC irrespective of being shared - unless performance is important.

 
精彩推荐
图片推荐