2016-10-25 1 views
2

Avec la liaison de code assembleur non relocalisable n'a jamais été un problème jusqu'à gcc 6.2.0. Je ne connais pas la version exacte qui fixait, mais avec gcc 5.4.0 (et ci-dessous) cela a fonctionné:gcc 6.2.0 tente de créer un objet partagé alors qu'il ne devrait pas le faire?

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

Cependant, avec 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 

Essayer de forcer statique enchaînement crée un autre problème:

$ 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 

Et les segfaults programme lors de l'utilisation gethostbyname() (mais fonctionne autrement)

Essayez également de mélanger statique et dynamique ne fonctionne pas.

$ 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 

Des idées? Lien vers le projet: https://github.com/niryeffet/ribs2

+2

Je suppose qu'il pourrait vouloir créer un TARTE par défaut? Bien que selon gcc.godbolt.org, ce n'est pas le cas. Quoi qu'il en soit, vous pouvez essayer d'ajouter '-fno-PIE', et aussi peut-être compiler un programme de test différent qui fonctionne et voir si la sortie est PIE ou non. – Jester

+0

Merci, -no-tarte lorsque la liaison l'a fait. – niry

+0

D'où vient ce problème? J'ai eu ce problème en améliorant mon système ... – Saroupille

Répondre

3

Grâce à l'indice de @Jester: l'ajout de -no-pie (pas -fno-PIE) à LDFLAGS a résolu le problème.

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

La modification fonctionne également sur gcc 5.4. Il semble que la valeur par défaut a changé.

MISE À JOUR:

Cela explique. De https://wiki.ubuntu.com/SecurityTeam/PIE

Dans Ubuntu 16.10, comme une mesure supplémentaire de durcissement du compilateur, nous avons permis PIE et la liaison immédiate par défaut sur amd64 et ppc64le. Cela augmente considérablement l'efficacité de ASLR sur ces plates-formes.