[c] "main.o: relocation R_X86_64_32 against `.data' can not be used when making a PIE object; recompile with -fPIC" 해결 방법.

2022. 5. 26. 13:46Language/c

728x90
728x90

Makefile으로컴파일수행간, 하단과같은에러발생.

$ make
cc -o vmdecrypt main.o -ldl ~/libvmdecrypt.so -L~/lib64 -lssl -lcrypto
/usr/bin/ld: main.o: relocation R_X86_64_32 against `.data' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
Makefile:58: recipe for target 'vmdecrypt' failed
make: *** [vmdecrypt] Error 1

에러 발생하는 원인.


"/usr/bin/ld: main.o: relocation R_X86_64_32 against `.data' can not be used when making a PIE object; recompile with -fPIC" 해결 방법.

컴파일 명령어 라인에 "-no-pie" 옵션 추가.


Makefile 수정.


Makefile "-no-pie" 옵션 추가 컴파일 동작을 확인.

$ make
cc -o vmdecrypt main.o -ldl ~/libvmdecrypt.so -L~/lib64 -lssl -lcrypto -no-pie
[Make Build Mode => Release]

cc 매뉴얼 참고.

1.pie

  • Produce a position independent executable on targets that support it.  For predictable results, you must also specify the same set of options used for compilation (-fpie, -fPIE, or model suboptions) when you specify this linker option.

2.no-pie

  • Don't produce a position independent executable.
728x90
728x90