Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.

Fixing the gcc linker order #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fixing the gcc linker order #2

wants to merge 1 commit into from

Conversation

jpereira
Copy link
Contributor

Hi,

I got the below errors during the build.

# make
(cd src; make all)
make[1]: Entering directory '/home/jpereira/Devel/github-jpereira/lua-ffi-yara.git/src'
gcc -shared -o libyawrap.so yawrap.o -Wl,-Bstatic -lyara -Wl,-Bdynamic -lpthread -lcrypto
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libyara.a(object.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
Makefile:19: recipe for target 'libyawrap' failed
make[1]: *** [libyawrap] Error 1
make[1]: Leaving directory '/home/jpereira/Devel/github-jpereira/lua-ffi-yara.git/src'
Makefile:2: recipe for target 'all' failed
make: *** [all] Error 2
#

My setup is:

# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.10
Release:	16.10
Codename:	yakkety
# dpkg -s gcc | grep Version
Version: 4:6.1.1-1ubuntu2
#

you can see the fix into this PR.

@robert-zenedge
Copy link
Contributor

robert-zenedge commented Feb 14, 2017

Looks like your libyara needs to be rebuilt with --with-pic, based on the output of ld:

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libyara.a(object.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC

@jpereira
Copy link
Contributor Author

But, if the problem is the -fPIC, the linker order shouldn't work. do you agree?

@robert-zenedge
Copy link
Contributor

robert-zenedge commented Feb 14, 2017

I'm not exactly sure how changing the linker order here affects things, but there are a few effects that seem undesirable. As a test, I installed the system libyara-dev package and built with your diff. The resulting ldd:

[poprocks@soter]─[~/code/C/yara] $ ldd ./libyawrap.so 
	linux-vdso.so.1 =>  (0x00007fff92faf000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe09a248000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fe09a831000)

So we're not linked to pthread or crypto libs, yet those libs are not statically compiled in, so we would run into runtime issues here. Also, older versions of yara had struct element name changes, so yara lib version 3.5 is a requirement. I'll add that note to the Readme as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants