一半君的总结纸

听话只听一半君

CentOS 7下交叉编译tomato 1.2.8 v131路由器(磊科Q3)可以使用的shadowsocks 2.3.1 – 正/逆翻墙用

对于出国在外,国内家里还有亲人的同学可能有用,网上的教程一般都是在路由器上编译安装,对于离家很远的童鞋们来说,如果远程操作,可能有把路由器搞挂的可能,那就得不偿失了,不折腾的话至少还能vpn连回国内,所以这里lz来测试一下在电脑上交叉编译shadowsocks(所谓cross compiling的意思就是在一个系统上编译另一种系统用的软件,比如linux下编译windows软件)

update: 本文有更新版在这里
update: crosstool-ng 1.2.2 cross compile shadowsocks-libev 2.4.1 for 磊科q3 asus rt-n66u rt-n16

如果不想伤眼看这一大段垃圾(这可真可以算是人肉jenkins/travis ci了),请直接拉到最底部,有本文编译好的shadowsocks-libev_2.3.1的文件下载

lz国内家里用的是垃圾磊科Q3路由器(无usb接口),京东60多块,这里lz想试试看能不能编译个静态的shadowsocks的server放在上面,然后从国外翻回国内(为了使用虾米看国内视频等目的…),机(2)智(B)的lz当年买的时候买了两个,正好可以在真机上随意测试,弄好了再去远程操作家里的路由器

当年lz设置家里路由器的时候图简单,刷了8MB的shibby版本的tomato,但是后来觉得连vpn不方便,比如虾米,连了vpn虽然能用了,但是下歌速度很慢,如果过了验证页面关掉vpn,这样下歌听歌都很快,但只要一切换播放列表就又不行了,去年虾米还是只在首页验证一下的,所以开虾米之前开vpn,进入apps之后关掉vpn就好,可以正常随便用, 可是现在变成很多页面都要验你在不在国内了,所以用vpn就不太方便了

吃灰中的备用磊科q3放了好久忘记ip了,只好reset,方法是不插网线,按着reset插电源线,然后保持reset按着过一会再放…

前期准备工作

  • 首先第一步,看看路由器上jffs空间还有多少? lz的q3背后的贴纸写着v1.0, 当前的tomato版本是121系列的
    q3_before_20150903

    lz原来当年刷的是6.7mb左右的max版本,而q3的flash只有8mb,虽然可以刷4mb多的,lz没去比较少哪些功能,如果还剩的1.3mb能放下也行啊,如果实在放不下server版,lz就放个静态链接的client进去,放回家里只用于正向翻墙好了

    刚刚去看了下现在的最新版本是多少
    q3_tomato_versions_131

    lz决定先升到最新版再说

  • 升级之前的121系列rom jffs还有1.6mb空间
    jffs_121

    可是升级到131系列之后就只有1.4mb了,orz 先乱搞试试不行再说(刷4mb多的 shibby tomato)
    jffs_131

  • 看一下q3的cpu
    $less /proc/cpuinfo
    system type             : Broadcom BCM53572 chip rev 1 pkg 8
    processor               : 0
    cpu model               : MIPS 74K V4.9
    BogoMIPS                : 149.50
    cpu MHz                 : 300
    wait instruction        : no
    microsecond timers      : yes
    tlb_entries             : 32
    extra interrupt vector  : no
    hardware watchpoint     : yes
    ASEs implemented        : mips16 dsp
    shadow register sets    : 1
    VCED exceptions         : not available
    VCEI exceptions         : not available
    
    unaligned_instructions  : 0
    

    从q3上拷个.so文件来看看系统配置

    [oglop@localhost tmp]$ scp root@192.168.2.22:/lib/libc.so.0 .
    
    [oglop@localhost tmp]$ readelf -h libc.so.0 
    ELF Header:
      Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
      Class:                             ELF32
      Data:                              2's complement, little endian
      Version:                           1 (current)
      OS/ABI:                            UNIX - System V
      ABI Version:                       0
      Type:                              DYN (Shared object file)
      Machine:                           MIPS R3000
      Version:                           0x1
      Entry point address:               0x6d50
      Start of program headers:          52 (bytes into file)
      Start of section headers:          260672 (bytes into file)
      Flags:                             0x50001007, noreorder, pic, cpic, o32, mips32
      Size of this header:               52 (bytes)
      Size of program headers:           32 (bytes)
      Number of program headers:         5
      Size of section headers:           40 (bytes)
      Number of section headers:         18
      Section header string table index: 17
    
  • 试试看tomato自带的toolchain能不能用
    mkdir -p ~/tomato && cd ~/tomato
    git clone https://github.com/tomatofirmware/tomato.git
    git branch -r
    git fetch
    git checkout tomato-shibby-RT-N
    
    # 准备工作 lz的tomato的根目录在~/tomato/tomato
    sudo ln -s ~/tomato/tomato/tools/brcm /opt/brcm
    
    
    # 如果有很多垃圾文件,想全删了可以用
    git reset --hard
    git clean -fdx
    
    # 如果只想恢复某个目录
    git checkout -- FolderToClean/*
    

    如果你看到错误

    /home/oglop/tomato/tomato/toolchain/build_dir/toolchain-mipsel_gcc4.2.4/gcc-4.2.4/gcc/doc/cppopts.texi:726: @itemx must follow @item
    make[5]: *** [doc/cpp.info] Error 1
    

    这是因为你的texinfo太新,降级到4.13a可以解决

    $ makeinfo --version
    makeinfo (GNU texinfo) 5.1
    4.13a http://ftp.gnu.org/gnu/texinfo/
    

    试过下面的方法,不行,也试过把MAKEINFO=missing加到makefile里也不行

    vim /home/oglop/tomato/tomato/toolchain/build_dir/toolchain-mipsel_gcc4.2.4/gcc-4.2.4/gcc/doc/cppopts.texi
    :%s/@itemx/@item
    # Added MAKEINFO=missing to avoid dealing with the texinfo >=5 strictness bugs
    #	Throws a @itemx must follow @item errors if the docs are built.
    

    所以只好乖乖去降级了

    export PATH=/usr/local/bin:$PATH
    cd tomato/toolchain
    # 工具链本身就带了,不用编译,lz只是想试试
    ./build26.sh
    
    # toolchain编译在t410上大约用时18min,完成后
    export PATH=/opt/brcm/hndtools-mipsel-linux/bin:/opt/brcm/hndtools-mipsel-uclibc/bin:$PATH
    
    # 测试一下好不好用
    $ cat > test.c
    #include <stdio.h>
    int main() { printf("Hello, world!\n"); return 0; }
    ^D
    $ mipsel-linux-uclibc-gcc -o test test.c
    $ scp test root@192.168.2.22:/home/root/
    $ ssh root@192.168.2.22
    
    root@unknown:/tmp/home/root# ./test
    Hello, world!
    
  • 编译openssl

    git clone https://github.com/openssl/openssl.git
    git checkout tags/OpenSSL_1_0_2d
    CC=mipsel-linux-uclibc-gcc CXX=mipsel-linux-uclibc-g++ AR=mipsel-linux-uclibc-ar RANLIB=mipsel-linux-uclibc-ranlib ./Configure no-asm shared --prefix=/home/oglop/tomato/openssl-install linux-mips32
    make && make install
    
  • 编译shadowsocks-libev

    git clone https://github.com/shadowsocks/shadowsocks-libev.git
    CC=mipsel-linux-uclibc-gcc CXX=mipsel-linux-uclibc-g++ AR=mipsel-linux-uclibc-ar RANLIB=mipsel-linux-uclibc-ranlib ./configure --prefix=/home/oglop/tomato/ss-install  --with-openssl=/home/oglop/tomato/openssl-install --host=mips-uclibc-linux
    make V=99 && make install
    

    结果出错

    ../libcork/.libs/libcork.a(libcork_la-error.o): In function `cork_error_get':
    /home/oglop/tomato/shadowsocks-libev/libcork/core/error.c:92: undefined reference to `__sync_val_compare_and_swap_4'
    

    解决不了,搜到说是用>4.4.x的gcc可以解决,所以折返去用crosstools-ng

  • 使用crosstools-ng编译工具链
    sudo yum install -y gperf texinfo glib* libstdc++*
    git clone https://github.com/crosstool-ng/crosstool-ng.git
    cd crosstool-ng
    git checkout tags/crosstool-ng-1.21.0
    ./bootstrap 
    ./configure
    make
    make install
    export PATH=$PATH:/opt/cross/bin
    LD_LIBRARY_PATH=
    

    我猜应该用uclibc-0.9.30.1(从tomato目录里看到此字样),可是crosstool-ng mips sample目录下没给这个版本的.config文件,所以去找了buildroot,然后用make uclibc-menuconfig,先load了crosstool-ng sample目录下的mip-unknown-linux-uclibc下的uClibc-0.9.33.2.config,然后改了改(little endian等等,linux选成2.6的,gcc选了个低版本的4.2.4不死心想试试,因为tomato用的是4.2.4),然后另存出来,最后再ct-ng menuconfig里uclibc的配置文件那里指定用这个自己存的,看到一些错误提示

    [INFO ]  =================================================================
    [INFO ]  Installing C library headers
    [EXTRA]    Copying sources to build dir
    [EXTRA]    Applying configuration
    [ERROR]    gcc: error: unrecognized argument in option '-mabi=32'
    [ERROR]    gcc: error: unrecognized argument in option '-mabi=32'
    [ERROR]    gcc: error: unrecognized command line option '-mips32'
    [ERROR]    gcc: error: unrecognized command line option '-mips32'
    ...
    

    不过似乎不会终止,能继续下去,会在后面一点的地方失败

    [INFO ]  =================================================================
    [INFO ]  Installing C library
    [EXTRA]    Copying sources to build dir
    [EXTRA]    Applying configuration
    [EXTRA]    Building C library
    [ERROR]    gmake[1]: *** [lib/crtn.o] Error 1
    [ERROR]   
    [ERROR]  >>
    [ERROR]  >>  Build failed in step 'Installing C library'
    [ERROR]  >>        called in step '(top-level)'
    [ERROR]  >>
    [ERROR]  >>  Error happened in: CT_DoExecLog[scripts/functions@257]
    [ERROR]  >>        called from: do_libc[scripts/build/libc/uClibc.sh@200]
    [ERROR]  >>        called from: main[scripts/crosstool-NG.sh@638]
    [ERROR]  >>
    [ERROR]  >>  For more info on this error, look at the file: 'build.log'
    [ERROR]  >>  There is a list of known issues, some with workarounds, in:
    [ERROR]  >>      '/opt/cross/share/doc/crosstool-ng/ct-ng.1.21.0/B - Known issues.txt'
    
    # build.log里的内容是
    [ALL  ]    {standard input}: Assembler messages:
    [ALL  ]    {standard input}: Error: .size expression for _init does not evaluate to a constant
    [ALL  ]    {standard input}: Error: .size expression for _fini does not evaluate to a constant
    [ALL  ]      CC libm/acoshf.os
    [ERROR]    gmake[1]: *** [lib/crtn.o] Error 1
    

    网上搜到说(2011年左右)是只要去 uClibc-0.9.31/libc/sysdeps/linux/arm/crtn.S里把下面两行删掉就行

    .size _init, .-_init
    .size _fini, .-_fini 
    

    可是我去.build/src/uClibc-0.9.30.1/libc/sysdeps/linux/mips/crtn.S里看过,没有这两行,而且2011年的时候这个就已经被加到patch里过了,试过2.21.53还是这样的错误,所以后来觉得可以试试老版本的binutils(<2.21),

    uClibc 0.9.31 and Binutils 2.21 are incompatible for x86 builds
    [patch] remove .size directives from libc/sysdeps/linux/powerpc/crtn.S
    uClibc build problems: crtn.S and DOMULTI
    Building a cross compiler for AVR32

  • 试了下gcc 4.4.7,binutils 2.20.1a结果出现

    [INFO ]  =================================================================
    [INFO ]  Installing pass-1 core C gcc compiler
    [EXTRA]    Configuring core C gcc compiler
    [EXTRA]    Building gcc
    [ERROR]    collect2: error: ld returned 1 exit status
    [ERROR]    gmake[2]: *** [cc1-dummy] Error 1
    [ERROR]    gmake[1]: *** [all-gcc] Error 2
    [ERROR]   
    [ERROR]  >>
    [ERROR]  >>  Build failed in step 'Installing pass-1 core C gcc compiler'
    [ERROR]  >>        called in step '(top-level)'
    [ERROR]  >>
    [ERROR]  >>  Error happened in: CT_DoExecLog[scripts/functions@257]
    [ERROR]  >>        called from: do_gcc_core_backend[scripts/build/cc/100-gcc.sh@478]
    [ERROR]  >>        called from: do_gcc_core_pass_1[scripts/build/cc/100-gcc.sh@107]
    [ERROR]  >>        called from: do_cc_core_pass_1[scripts/build/cc.sh@35]
    [ERROR]  >>        called from: main[scripts/crosstool-NG.sh@638]
    
    # log里显示有几百行
    [ALL  ]    /home/oglop/tomato/ct-ng-tmp/.build/src/cloog-ppl-0.15.11/source/ppl/domain.c:1789: undefined reference to `ppl_delete_Polyhedron'
    [ALL  ]    /home/oglop/tomato/ct-ng-tmp/.build/mipsel-unknown-linux-uclibc/buildtools/lib/libcloog.a(domain.o): In function `cloog_domain_extend':
    [ALL  ]    /home/oglop/tomato/ct-ng-tmp/.build/src/cloog-ppl-0.15.11/source/ppl/domain.c:1842: undefined reference to `ppl_Polyhedron_add_space_dimensions_and_embed'
    [ALL  ]    /home/oglop/tomato/ct-ng-tmp/.build/src/cloog-ppl-0.15.11/source/ppl/domain.c:1843: undefined reference to `ppl_Polyhedron_map_space_dimensions'
    [ALL  ]    /home/oglop/tomato/ct-ng-tmp/.build/src/cloog-ppl-0.15.11/source/ppl/domain.c:1845: undefined reference to `ppl_delete_Polyhedron'
    [ALL  ]    /home/oglop/tomato/ct-ng-tmp/.build/mipsel-unknown-linux-uclibc/buildtools/lib/libcloog.a(domain.o): In function `cloog_domain_difference':
    [ALL  ]    /home/oglop/tomato/ct-ng-tmp/.build/src/cloog-ppl-0.15.11/source/ppl/domain.c:1207: undefined reference to `ppl_Polyhedron_add_constraint'
    [ALL  ]    /home/oglop/tomato/ct-ng-tmp/.build/src/cloog-ppl-0.15.11/source/ppl/domain.c:1208: undefined reference to `ppl_delete_Constraint'
    [ALL  ]    /home/oglop/tomato/ct-ng-tmp/.build/src/cloog-ppl-0.15.11/source/ppl/domain.c:1210: undefined reference to `ppl_delete_Polyhedron'
    [ALL  ]    /home/oglop/tomato/ct-ng-tmp/.build/src/cloog-ppl-0.15.11/source/ppl/domain.c:1217: undefined reference to `ppl_Polyhedron_add_constraint'
    [ALL  ]    /home/oglop/tomato/ct-ng-tmp/.build/src/cloog-ppl-0.15.11/source/ppl/domain.c:1218: undefined reference to `ppl_delete_Constraint'
    [ALL  ]    /home/oglop/tomato/ct-ng-tmp/.build/src/cloog-ppl-0.15.11/source/ppl/domain.c:1220: undefined reference to `ppl_delete_Polyhedron'
    
    

    据说选成CLooG 0.15.9 就行,可是我菜单里只有一项CLooG 0.15.11,跑去ct-ngscript里下载文件的cloog的ftp网址看,也没有0.15.9了,这大概是有原因的吧,我还是不要乱搞的好(改config/companion_libs/cloog.in自己加个0.15.9或者自己网上下个0.15.9解开放到src下面去

    此外,如果binutils选2.19.1a,则出现如下错误

    [INFO ]  =================================================================
    [INFO ]  Installing C library
    [EXTRA]    Copying sources to build dir
    [EXTRA]    Applying configuration
    [EXTRA]    Building C library
    [ERROR]    /home/oglop/x-tools/mipsel-unknown-linux-uclibc-tmp2/mipsel-unknown-linux-uclibc/sysroot/usr/include/linux/sysinfo.h:8: error: expected specifier-qualifier-list before '__kernel_long_t'
    [ERROR]    /home/oglop/x-tools/mipsel-unknown-linux-uclibc-tmp2/mipsel-unknown-linux-uclibc/sysroot/usr/include/linux/if_link.h:387: error: expected specifier-qualifier-list before '__be16'
    [ERROR]    gmake[1]: *** [libc/inet/if_index.os] Error 1
    [ERROR]    /home/oglop/x-tools/mipsel-unknown-linux-uclibc-tmp2/mipsel-unknown-linux-uclibc/sysroot/usr/include/linux/sysinfo.h:8: error: expected specifier-qualifier-list before '__kernel_long_t'
    [ERROR]    /home/oglop/x-tools/mipsel-unknown-linux-uclibc-tmp2/mipsel-unknown-linux-uclibc/sysroot/usr/include/linux/if_link.h:387: error: expected specifier-qualifier-list before '__be16'
    [ERROR]    gmake[1]: *** [libc/inet/ifaddrs.os] Error 1
    [ERROR]   
    [ERROR]  >>
    [ERROR]  >>  Build failed in step 'Installing C library'
    [ERROR]  >>        called in step '(top-level)'
    [ERROR]  >>
    [ERROR]  >>  Error happened in: CT_DoExecLog[scripts/functions@257]
    [ERROR]  >>        called from: do_libc[scripts/build/libc/uClibc.sh@200]
    [ERROR]  >>        called from: main[scripts/crosstool-NG.sh@638]
    

    Building uclibc linux 3.10-2 (Debian jessie x86_64) fails due to missing types

    如果binutils选2.18a

    [INFO ]  =================================================================
    [INFO ]  Installing binutils for host
    [EXTRA]    Configuring binutils
    [EXTRA]    Building binutils
    [ERROR]    eelf32ltsmip.c:1:1: error: expected identifier or '(' before string constant
    [ERROR]    eelf32ltsmip.c:189:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32ltsmip.c:377:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32ltsmip.c:618:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32ltsmip.c:861:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32ltsmip.c:1111:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32ltsmip.c:1359:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32ltsmip.c:1602:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32ltsmip.c:1842:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32ltsmip.c:2080:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32ltsmip.c:2313:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32ltsmip.c:2562:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32ltsmip.c:2810:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32ltsmip.c:3053:3: error: expected identifier or '(' before '}' token
    [ERROR]    gmake[5]: *** [eelf32ltsmip.o] Error 1
    [ERROR]    eelf32btsmip.c:1:1: error: expected identifier or '(' before string constant
    [ERROR]    eelf32btsmip.c:189:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32btsmip.c:377:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32btsmip.c:618:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32btsmip.c:861:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32btsmip.c:1111:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32btsmip.c:1359:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32btsmip.c:1602:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32btsmip.c:1842:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32btsmip.c:2080:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32btsmip.c:2313:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32btsmip.c:2562:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32btsmip.c:2810:5: error: expected identifier or '(' before 'else'
    [ERROR]    eelf32btsmip.c:3053:3: error: expected identifier or '(' before '}' token
    [ERROR]    gmake[5]: *** [eelf32btsmip.o] Error 1
    [ERROR]    gmake[4]: *** [all-recursive] Error 1
    [ERROR]    gmake[3]: *** [all] Error 2
    [ERROR]    gmake[2]: *** [all-ld] Error 2
    [ERROR]    gmake[1]: *** [all] Error 2
    

    如果binutils选2.21.53

    
    
  • 错误

    mbrtowc.c:125: error: 'MB_CUR_MAX' undeclared
    </li>
    CT_LIBC_UCLIBC_CONFIG_FILE="/home/oglop/tomato/tomato/toolchain/toolchain/uClibc/config/0.9.30.1/mipsel"
    

    搜到据说是c library没选add support for WCHAR,选上后就过了

    错误

    [INFO ]  =================================================================
    [INFO ]  Installing strace
    [EXTRA]    Configuring strace
    [EXTRA]    Building strace
    [ERROR]    /home/oglop/tomato/ct-ng-tmp/.build/src/strace-4.10/dirent.c:146: error: invalid use of undefined type 'struct dirent64'
    [ERROR]    /home/oglop/tomato/ct-ng-tmp/.build/src/strace-4.10/dirent.c:188: error: dereferencing pointer to incomplete type
    

    dirent64在uclibc的include文件夹里有,不知为何这里他不知道,既然如此,我就给他

    export C_INCLUDE_PATH=/home/oglop/tomato/ct-ng-tmp/.build/src/uClibc-0.9.30.1/include
    
    # 然后从断掉的地方继续开始
    ct-ng build RESTART=debug
    

    整蛊了半天还是不行,最后直接去把build strace的选项关了 … orz
    最后成功编译,不过编译openssl的时候看到错误

    /home/oglop/x-tools/mipsel-unknown-linux-uclibc/mipsel-unknown-linux-uclibc/sysroot/usr/include/features.h:383:4: error: #error It appears you have defined _FILE_OFFSET_BITS=64. Unfortunately, uClibc was built without large file support enabled.
    In file included from /home/oglop/x-tools/mipsel-unknown-linux-uclibc/mipsel-unknown-linux-uclibc/sysroot/usr/include/stdio.h:72,
                     from bss_file.c:86:
    /home/oglop/x-tools/mipsel-unknown-linux-uclibc/mipsel-unknown-linux-uclibc/sysroot/usr/include/bits/uClibc_stdio.h:72:2: error: #error Sorry... uClibc was built without large file support!
    

    只好再来一遍,去buildroot里改也行,但运气不好的lz可能又会掉到别的坑里,所以lz直接用了tomato自己带的uclibc config,/home/oglop/tomato/tomato/toolchain/toolchain/uClibc/config/0.9.30.1/mips

    lz使用的crosstools-ng的配置文件在这里,uclibc 0.9.30.1的配置文件在这里

    最后的最后,大概因为同样是gcc 4.2.4,lz悲剧的掉到了同一个坑里,还是一样的错误

      CC     ss_local-local.o
      CCLD   ss-local
    ss_local-udprelay.o: In function `create_remote_socket':
    /home/oglop/tomato/shadowsocks-libev/src/udprelay.c:344: undefined reference to `in6addr_any'
    ../libcork/.libs/libcork.a(libcork_la-error.o): In function `cork_error__get':
    /home/oglop/tomato/shadowsocks-libev/libcork/core/error.c:79: undefined reference to `__sync_val_compare_and_swap_4'
    /home/oglop/tomato/shadowsocks-libev/libcork/core/error.c:79: undefined reference to `__sync_val_compare_and_swap_4'
    ../libcork/.libs/libcork.a(libcork_la-error.o): In function `cork_error_get':
    /home/oglop/tomato/shadowsocks-libev/libcork/core/error.c:92: undefined reference to `__sync_val_compare_and_swap_4'
    /home/oglop/tomato/shadowsocks-libev/libcork/core/error.c:88: undefined reference to `__sync_val_compare_and_swap_4'
    /home/oglop/tomato/shadowsocks-libev/libcork/core/error.c:88: undefined reference to `__sync_val_compare_and_swap_4'
    collect2: ld returned 1 exit status
    make[2]: *** [ss-local] Error 1
    make[2]: Leaving directory `/home/oglop/tomato/shadowsocks-libev/src'
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory `/home/oglop/tomato/shadowsocks-libev'
    make: *** [all] Error 2
    

    看来只好如网上所说,升级到gcc4.4.x试试

  • 选了gcc 4.4.7,不过gmp mpfr ppl cloog这几样东西默认的组合是过不了的,错误百出,经lz无脑测试,下面的组合可以通过,后来发现Architecture Level不写的话就是默认mips1,可以试试mips32

    GCC Binutils GMP MPFR PPL CLooG
    4.4.0 2.19.1a 4.3.2 3.1.3 0.10.2 0.15.11
    4.4.7 2.19.1a 4.3.2 3.1.3 0.10.2 0.15.11
    4.4.7 2.20.1a 4.3.2 3.1.3 0.10.2 0.15.11
    试试gcc 4.8.5

    看到如下错误

    [ERROR]    configure: error: Unable to find a usable ISL.  See config.log for details.
    [ERROR]  
    [ERROR]  >>
    [ERROR]  >>  Build failed in step 'Installing pass-1 core C gcc compiler'
    [ERROR]  >>        called in step '(top-level)'
    [ERROR]  >>
    [ERROR]  >>  Error happened in: CT_DoExecLog[scripts/functions@257]
    [ERROR]  >>        called from: do_gcc_core_backend[scripts/build/cc/100-gcc.sh@382]
    [ERROR]  >>        called from: do_gcc_core_pass_1[scripts/build/cc/100-gcc.sh@107]
    [ERROR]  >>        called from: do_cc_core_pass_1[scripts/build/cc.sh@35]
    [ERROR]  >>        called from: main[scripts/crosstool-NG.sh@638]
    

    下面的组合可以通过

    GCC Binutils GMP MPFR ISL CLooG MPC
    4.8.5 2.20.1a 4.3.2 3.1.3 0.14 0.18.4 1.0.3
    选gcc 4.9.3试试

    要关闭use synci
    下面的组合可以通过

    GCC Binutils GMP MPFR ISL CLooG MPC
    4.9.3 2.20.1a 4.3.2 3.1.3 0.14 0.18.4 1.0.3
    如果选高版本的gcc 5.2.0
    [INFO ]  Installing final gcc compiler
    [EXTRA]    Configuring final gcc compiler
    [EXTRA]    Building final gcc compiler
    [ERROR]    /home/oglop/tomato/ct-ng-tmp/.build/src/gcc-5.2.0/libatomic/gcas.c:1:0: error: the 'mips1' architecture does not support the synci instruction [-Werror]
    [ERROR]    /home/oglop/tomato/ct-ng-tmp/.build/src/gcc-5.2.0/libatomic/gload.c:1:0: error: the 'mips1' architecture does not support the synci instruction [-Werror]
    [ERROR]    /home/oglop/tomato/ct-ng-tmp/.build/src/gcc-5.2.0/libatomic/gstore.c:1:0: error: the 'mips1' architecture does not support the synci instruction [-Werror]
    [ERROR]    /home/oglop/tomato/ct-ng-tmp/.build/src/gcc-5.2.0/libatomic/gexch.c:1:0: error: the 'mips1' architecture does not support the synci instruction [-Werror]
    [ERROR]    gmake[5]: *** [gcas.lo] Error 1
    [ERROR]    gmake[5]: *** [gstore.lo] Error 1
    [ERROR]    checking stdalign.h usability... gmake[5]: *** [gload.lo] Error 1
    [ERROR]    gmake[5]: *** [gexch.lo] Error 1
    [ERROR]    gmake[4]: *** [all-recursive] Error 1
    [ERROR]    gmake[3]: *** [all] Error 2
    [ERROR]    gmake[2]: *** [all-target-libatomic] Error 2
    [ERROR]    gmake[1]: *** [all] Error 2
    [ERROR]   
    [ERROR]  >>
    [ERROR]  >>  Build failed in step 'Installing final gcc compiler'
    [ERROR]  >>        called in step '(top-level)'
    [ERROR]  >>
    [ERROR]  >>  Error happened in: CT_DoExecLog[scripts/functions@257]
    [ERROR]  >>        called from: do_gcc_backend[scripts/build/cc/100-gcc.sh@871]
    [ERROR]  >>        called from: do_gcc_for_host[scripts/build/cc/100-gcc.sh@592]
    [ERROR]  >>        called from: do_cc_for_host[scripts/build/cc.sh@56]
    [ERROR]  >>        called from: main[scripts/crosstool-NG.sh@638]
    
    

    所以去把他关掉 ,去menuconfig里把use synci关掉(可是之前gcc 4.x的时候开着的没有错误)
    下面的组合可以通过

    GCC Binutils GMP MPFR ISL MPC
    5.2.0 2.19.1a 4.3.2 3.1.3 0.12.2 1.0.3
    5.2.0 2.20.1a 5.0.1 3.1.3 0.12.2 1.0.3
    5.2.0 2.20.1a 6.0.0a 3.1.3 0.12.2 1.0.3

    Build failed in step ‘Installing pass-1 core C compiler’

  • 同样编译openssl和shadowsocks-libev
    git clone https://github.com/openssl/openssl.git
    git checkout tags/OpenSSL_1_0_2d
    export PATH=/home/oglop/x-tools/mipsel-unknown-linux-uclibc/bin:$PATH
    CC=mipsel-unknown-linux-uclibc-gcc CXX=mipsel-unknown-linux-uclibc-g++ AR=mipsel-unknown-linux-uclibc-ar RANLIB=mipsel-unknown-linux-uclibc-ranlib ./Configure no-asm shared --prefix=/home/oglop/tomato/openssl-install linux-mips32
    make && make install
    

    编译shadowsocks-libev

    git clone https://github.com/shadowsocks/shadowsocks-libev.git
    CC=mipsel-unknown-linux-uclibc-gcc CXX=mipsel-unknown-linux-uclibc-g++ AR=mipsel-unknown-linux-uclibc-ar RANLIB=mipsel-unknown-linux-uclibc-ranlib ./configure --prefix=/home/oglop/tomato/ss-install  --with-openssl=/home/oglop/tomato/openssl-install --host=mipsel-uclibc-linux
    make V=99 && make install
    

    似乎出来的文件很大

    [oglop@localhost tmp]$ ll ~/tomato/ss-install/bin/
    total 3828
    -rwxr-xr-x. 1 oglop oglop  874277 Sep  9 11:07 ss-local
    -rwxr-xr-x. 1 oglop oglop  487344 Sep  9 11:07 ss-manager
    -rwxr-xr-x. 1 oglop oglop  772211 Sep  9 11:07 ss-redir
    -rwxr-xr-x. 1 oglop oglop 1005399 Sep  9 11:07 ss-server
    -rwxr-xr-x. 1 oglop oglop  771035 Sep  9 11:07 ss-tunnel
    
    # 我们把他弄小一点
    [oglop@localhost shadowsocks-libev]$ mipsel-unknown-linux-uclibc-strip ~/tomato/ss-install/bin/*
    [oglop@localhost shadowsocks-libev]$ ll ~/tomato/ss-install/bin/
    total 996
    -rwxr-xr-x. 1 oglop oglop 224536 Sep  9 11:57 ss-local
    -rwxr-xr-x. 1 oglop oglop 110720 Sep  9 11:57 ss-manager
    -rwxr-xr-x. 1 oglop oglop 204900 Sep  9 11:57 ss-redir
    -rwxr-xr-x. 1 oglop oglop 260184 Sep  9 11:57 ss-server
    -rwxr-xr-x. 1 oglop oglop 204884 Sep  9 11:57 ss-tunnel
    

    成功!的确小了很多,上面这个是dynamic的,lz把ss-server拷到q3上试试

    $ ssh root@my-router-ip
    root@unknown:/tmp/home/root# ldd ./ss-server 
            libcrypto.so.1.0.0 => /usr/lib/libcrypto.so.1.0.0 (0x2aabf000)
            libm.so.0 => /lib/libm.so.0 (0x2ac23000)
            libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x2ac37000)
            libpthread.so.0 => /lib/libpthread.so.0 (0x2ac56000)
            libc.so.0 => /lib/libc.so.0 (0x2ac78000)
            libdl.so.0 => /lib/libdl.so.0 (0x2accb000)
            ld-uClibc.so.0 => /lib/ld-uClibc.so.0 (0x2aaa8000)
    

    似乎他想要用到的library都有了已经,运气不错,省空间了,如果你想要编译static的ss,那你得

    # static的openssl
    LDFLAGS="-static" CC=mipsel-unknown-linux-uclibc-gcc CXX=mipsel-unknown-linux-uclibc-g++ AR=mipsel-unknown-linux-uclibc-ar RANLIB=mipsel-unknown-linux-uclibc-ranlib ./Configure no-asm  --prefix=/home/oglop/tomato/openssl-install-static linux-mips32
    
    # static的ss
    LIBS="-ldl" LDFLAGS="-static" CC=mipsel-unknown-linux-uclibc-gcc CXX=mipsel-unknown-linux-uclibc-g++ AR=mipsel-unknown-linux-uclibc-ar RANLIB=mipsel-unknown-linux-uclibc-ranlib ./configure --prefix=/home/oglop/tomato/ss-install-static   --host=mips-uclibc-linux --with-openssl=/home/oglop/tomato/openssl-install-static
    

    不知为何如果不加LIBS=”-ldl”,configure ss的时候会提示

    checking for EVP_EncryptInit_ex in -lcrypto... no
    configure: error: OpenSSL libraries not found.
    

    Ubuntu 上交叉编译静态版本的 Shadowsocks ARM

    貌似体积巨大

    
    [oglop@localhost shadowsocks-libev]$ ll /home/oglop/tomato/ss-install-static/bin/
    total 10024
    -rwxr-xr-x. 1 oglop oglop 2460484 Sep  9 17:23 ss-local
    -rwxr-xr-x. 1 oglop oglop  487356 Sep  9 17:23 ss-manager
    -rwxr-xr-x. 1 oglop oglop 2359341 Sep  9 17:23 ss-redir
    -rwxr-xr-x. 1 oglop oglop 2590061 Sep  9 17:23 ss-server
    -rwxr-xr-x. 1 oglop oglop 2358333 Sep  9 17:23 ss-tunnel
    
    # 瘦身之后似乎也没小多少,不过我用不着静态版本,我希望用的q3上已经有需要的openssl的so文件了
    [oglop@localhost shadowsocks-libev]$ mipsel-unknown-linux-uclibc-strip ~/tomato/ss-install-static/bin/*
    [oglop@localhost shadowsocks-libev]$ ll /home/oglop/tomato/ss-install-static/bin/
    total 6440
    -rwxr-xr-x. 1 oglop oglop 1618912 Sep  9 17:25 ss-local
    -rwxr-xr-x. 1 oglop oglop  110616 Sep  9 17:25 ss-manager
    -rwxr-xr-x. 1 oglop oglop 1599276 Sep  9 17:25 ss-redir
    -rwxr-xr-x. 1 oglop oglop 1654544 Sep  9 17:25 ss-server
    -rwxr-xr-x. 1 oglop oglop 1599260 Sep  9 17:25 ss-tunnel
    

    继续乱搞,试试看用UPX能不能把他们再整小一点

    [oglop@localhost upx-3.91-amd64_linux]$ ./upx ~/tomato/ss-install-static/bin/ss-server 
                           Ultimate Packer for eXecutables
                              Copyright (C) 1996 - 2013
    UPX 3.91        Markus Oberhumer, Laszlo Molnar & John Reiser   Sep 30th 2013
    
            File size         Ratio      Format      Name
       --------------------   ------   -----------   -----------
       1654544 ->    648140   39.17%  linux/mipsel   ss-server                     
    
    Packed 1 file.
    

    似乎能小不少

  • 最终产物
    dynamic版

    [oglop@localhost upx-3.91-amd64_linux]$ ./upx ~/tomato/ss-install/bin/*
                           Ultimate Packer for eXecutables
                              Copyright (C) 1996 - 2013
    UPX 3.91        Markus Oberhumer, Laszlo Molnar & John Reiser   Sep 30th 2013
    
            File size         Ratio      Format      Name
       --------------------   ------   -----------   -----------
        212080 ->     93744   44.20%  linux/mipsel   ss-local                      
        110616 ->     47080   42.56%  linux/mipsel   ss-manager                    
        192444 ->     86564   44.98%  linux/mipsel   ss-redir                      
        247728 ->    107352   43.33%  linux/mipsel   ss-server                     
        192428 ->     86052   44.72%  linux/mipsel   ss-tunnel                     
       --------------------   ------   -----------   -----------
        955296 ->    420792   44.05%                 [ 5 files ]
    
    Packed 5 files.
    

    static版

    [oglop@localhost upx-3.91-amd64_linux]$ ./upx ~/tomato/ss-install-static/bin/*
                           Ultimate Packer for eXecutables
                              Copyright (C) 1996 - 2013
    UPX 3.91        Markus Oberhumer, Laszlo Molnar & John Reiser   Sep 30th 2013
    
            File size         Ratio      Format      Name
       --------------------   ------   -----------   -----------
       1618912 ->    634888   39.22%  linux/mipsel   ss-local                      
        110616 ->     47076   42.56%  linux/mipsel   ss-manager                    
       1599276 ->    627896   39.26%  linux/mipsel   ss-redir                      
       1654544 ->    648140   39.17%  linux/mipsel   ss-server                     
       1599260 ->    627484   39.24%  linux/mipsel   ss-tunnel                     
       --------------------   ------   -----------   -----------
       6582608 ->   2585484   39.28%                 [ 5 files ]
    
    Packed 5 files.
    
    

    总之还是小了一些的,上面的可执行文件均是先被strip过,然后被upx过的
    static版600k左右,dynamic版100k左右

本文的乱搞成果文件下载:(不幸的是这些文件本身在墙外)
shadowsocks-libev_2.3.1_mipsel_OpenSSL_static.tar.gz
shadowsocks-libev_2.3.1_mipsel_OpenSSL_dynamic.tar.gz
openssl-1.0.2d_dynamic.tar.gz

perp-2.07.tar.gz

lz使用的是用crosstools-ng 1.21.0 编译出来的 gcc 5.2.0的toolchain,在这里mipsel-unknown-linux-uclibc.tar.gz

GCC Binutils GMP MPFR ISL MPC
5.2.0 2.20.1a 6.0.0a 3.1.3 0.12.2 1.0.3

Architecture level mips32
C-library 是uClibc 0.9.30.1 config文件自备(用tomato里带的或者自己用buildroot出一个)
C compiler -> Use synci 关闭

参考:
Shadowsocks 1.4.1 OpenSSL PolarSSL 动态/静态编译全版 备份
为ASUS-AC68U-Merlin固件交叉编译shadowsocks-libev
How to build, and rebuild Tomato, FOR TOTAL NOOBS
How to build a cross compiler for your Raspberry Pi
Using Crosstool-ng | nairobi-embedded
toolchain build fails due to texinfo strictness
使用shadowsocks轻松搭建FQ环境教程
Configuration via Config File
Centos7安装Shadowsocks实现多用户科学上网
Shadowsocks for Merlin固件,交叉编译教程
The why and how of RPATH
CentOS下shadowsocks-libev一键安装脚本
Compilation and Installation – OpenSSL
What gcc versions support the __int128 intrinsic type?
shadowsocks-libev – FISHERMAN’S BLOG
Shadowsocks + GfwList 实现 OpenWRT 路由器自动翻墙

Advertisements

13 responses to “CentOS 7下交叉编译tomato 1.2.8 v131路由器(磊科Q3)可以使用的shadowsocks 2.3.1 – 正/逆翻墙用

  1. houzi123 九月 15, 2015 @ 1:46 上午

    不知道博主有没有编译过chinadns,能编译出来但是不能运行!是arm平台的!MIPS没有任何问题!

    • 一半君 九月 28, 2015 @ 8:49 上午

      没试过… 我没arm的路由器… 我在墙外不好测试…

      • HOUZI (@wojiaolinmu008) 十一月 24, 2015 @ 8:26 下午

        使用博主提供的编译工具链出现该情况,Pthread 库文件丢失!不知道您有没有遇到过!
        checking for the pthreads library -lpthreads… no
        checking whether pthreads work without any flags… no
        checking whether pthreads work with -Kthread… no
        checking whether pthreads work with -kthread… no
        checking for the pthreads library -llthread… no
        checking whether pthreads work with -pthread… no
        checking whether pthreads work with -pthreads… no
        checking whether pthreads work with -mthreads… no
        checking for the pthreads library -lpthread… no
        checking whether pthreads work with –thread-safe… no
        checking whether pthreads work with -mt… no
        checking for pthread-config… no
        configure: error: Missing Pthread Library

      • 一半君 十一月 24, 2015 @ 11:19 下午

        我现在没电脑 过几天我试试

      • HOUZI (@wojiaolinmu008) 十一月 27, 2015 @ 2:40 下午

        编译2.4.1的时候会出现该问题,用到了该函数库。希望博主有时间编译看看!

  2. xixixihaha 一月 19, 2016 @ 11:42 上午

    能分享下你编译出来的crosstool吗? 谢谢

  3. jack 一月 27, 2016 @ 12:02 下午

    不知道博主在国外看国内优酷视频是否卡,国内的宽带限制了上行,512K 或者1M的上行真的是小水管啊。

  4. windy 三月 10, 2016 @ 7:10 上午

    用了楼主的 crosstool, 编译 ss 的时候遇到这个错:

    ../lib/gcc/mipsel-unknown-linux-uclibc/5.2.0/../../../../mipsel-unknown-linux-uclibc/bin/ld: cannot find -lssp_nonshared

    请问应该怎么解决? 谢谢!

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: