Michael VERGOZ

Aller au contenu | Aller au menu | Aller à la recherche

Portage / Cross dev

Fil des billets

Compiler Apache sans SSP

Un autre petit tip pour compiler Apache 1.3 sans SSP.

$ ./configure --prefix=/je/sais/pas --exec-prefix=/je/sais/pas --enable-module=so
$ make CC="gcc -fno-stack-protector -DEAPI" LD="ld -fno-stack-protector"
$ readelf -a src/httpd | grep stack_chk

Et voila plus de SSP dans Apache :)

Pour Apache > 2.0 et pour APR il ne faut pas utiliser CC et LD mais CFLAGS, et LDFLAGS. En fait à l'époque Apache 1.3 ne gérait pas ces deux dernières variables.

$ make CFLAGS='-fno-stack-protector' LDFLAGS='-fno-stack-protector'

Carton rouge pour Gentoo

Gentoo farci Gentoo farça!

Bon je suis un peut dégouté de Gentoo car au départ, je m'attendais à un système de versionning fiable au niveau du portage et en fait rien, non seulement les références des packages sont perdues mais les sources finissent par disparaitre des mirrors Gentoo. En gros, impossible de faire tourner une vieille gentoo.

Autre chose pas cool, impossible d'emergeR une vieille version d'autoconf genre la 2.53 ou 2.13 nécessaire pour compiler différentes versions d'Apache. Comme dit un pote, comment on peut faire tourner des Gentoo en production ? :(

On est loin des Ports de FreeBSD.

Compiler depuis un x86 vers un x86_64 avec GCC

Au départ je pensais que la compilation d'un fichier ELF x86_64 puis un x86 demandait forcément une cross compilation (CBUILD) d'un toolchain x86_64. Et en fait pas du tout, visiblement GCC intégre par défaut la possibilité de compiler vers un x86_64 depuis un x86 (et inversement) par contre pour changer totalement de processeur, typiquement de l'ARM, il est nécessaire de cross compiler des toolchain et là c'est pas la même histoire...

Un petit test :

root@zef:~# gcc -o test.bin test.c -m64
root@zef:~# file test.bin
test.bin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), for GNU/Linux 2.6.0, dynamically linked (uses shared libs), not stripped
root@zef:~# gcc -o test.bin test.c -m32
root@zef:~# file test.bin
test.bin: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.0, dynamically linked (uses shared libs), not stripped

Il faut savoir un truc c'est que ça ne fonctionne pas toujours. Par exemple si vous voulez compiler Apache 1.3 depuis un x86 vers du x86_64 eh bien cela ne sera pas possible car le Makefile d'Apache peut compiler des fichiers puis les executer pendant la compilation. La solution c'est d'avoir un CHOST x86_64 + support lib32 qui compile pour du x86_64 et x86.

GCC et le SSP

Depuis la version 2.4 de la glibc des symboles de controle ( comme __stack_chk_fail ) sont intégrés par defaut dans tous les binaires compilés. C'est le SSP dans GCC qui est responsable de cette action et il est possible de désactiver ce SSP avec l'option -fno-stack-protector.

Un petit code C comme exemple :

#include <stdio.h>
#include <pthread.h>

int main() {
        pthread_mutex_t fastmutex = PTHREAD_MUTEX_INITIALIZER;
        pthread_mutex_lock(&fastmutex);
        printf("Tst\n");
        pthread_mutex_unlock(&fastmutex);
}

Ensuite on teste :

none@zef:~# gcc -O2 -o test.bin test.c
none@zef:~# readelf -a test.bin | grep _stack_
080496c8  00000507 R_386_JUMP_SLOT   00000000   __stack_chk_fail
     5: 00000000    70 FUNC    GLOBAL DEFAULT  UND __stack_chk_fail@GLIBC_2.4 (3)
    75: 00000000    70 FUNC    GLOBAL DEFAULT  UND __stack_chk_fail@@GLIBC_2
none@zef:~# gcc -O2 -fno-stack-protector -o test.bin test.c
none@zef:~# readelf -a test.bin | grep _stack_
none@zef:~# 

Ca rend de fait portable le binaire pour des glibc > 2.3 :)

none@zef:~# file /lib/libc-2.5.so
/lib/libc-2.5.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.0, stripped
none@zef:~# gcc -O2 -o test.bin test.c
none@zef:~# readelf -a test.bin | grep -i GLIBC_2.4
     5: 00000000    70 FUNC    GLOBAL DEFAULT  UND __stack_chk_fail@GLIBC_2.4 (3)
  004:   2 (GLIBC_2.0)     3 (GLIBC_2.4)     2 (GLIBC_2.0)     1 (*global*)
  0x0010:   Name: GLIBC_2.4  Flags: none  Version: 3
none@zef:~# gcc -O2 -fno-stack-protector -o test.bin test.c
none@zef:~# readelf -a test.bin | grep -i GLIBC_2.4
none@zef:~#