go-libtor icon indicating copy to clipboard operation
go-libtor copied to clipboard

mips/mipsel support

Open hook-s3c opened this issue 5 years ago • 4 comments

Hi,

Just been playing around trying to get a mips build to work from a cross-compiled from x86 vua a musl buildchain tooling - arm/armel static builds work great this way.

I'm using the tools found on http://musl.cc/

  • mipsel-linux-musl-cross.tgz
  • mips-linux-musl-cross.tgz

I seem to be getting some errors thrown from libevent and wondered if there was a way to quick-hack this?

So I try;

CC=mips-linux-musl-gcc CXX=mips-linux-musl-g++ CGO_ENABLED=1 GOOS=linux GOARCH=mips go build -a -ldflags '-w -extldflags "-static"' -v

and this fails;

In file included from libtor/../libevent/include/event2/event.h:202,
                 from libtor/../libevent/compat/../buffer.c:85,
                 from libtor/libevent_buffer.go:8:
libtor/../libevent/include/event2/util.h:129:2: error: #error "No way to define ev_uint64_t"
 #error "No way to define ev_uint64_t"
  ^~~~~
libtor/../libevent/include/event2/util.h:148:2: error: #error "No way to define ev_uint32_t"
 #error "No way to define ev_uint32_t"
  ^~~~~
libtor/../libevent/include/event2/util.h:167:2: error: #error "No way to define ev_uint16_t"
 #error "No way to define ev_uint16_t"
  ^~~~~
libtor/../libevent/include/event2/util.h:283:2: error: #error "No way to define SIZE_MAX"

Any ideas? C is not my forte, but it looks like a default catch-all on an elseif.

I've had help building tor for mips before, so I know it's possible - would just be cool to get this CGO version working!

hook-s3c avatar Mar 28 '19 07:03 hook-s3c

Hi,

So I went through and found libevent_config/event2/event-config.h

I dropped this at the bottom;

#define EVENT__HAVE_UINT64_T 0
#define EVENT__HAVE_UINT32_T 1
#define EVENT__HAVE_UINT16_T 1
#define EVENT__SIZEOF_SIZE_T 4
#define EVENT__SIZEOF_LONG 8
#define EVENT__SIZEOF_LONG_LONG 1

Seemed to get past the above errors, although I'm not really sure if the size values are correct.

Then I ran in to this;

# github.com/ipsn/go-libtor/libtor
In file included from libtor/openssl_crypto_bio_bss_dgram.go:10:
libtor/../openssl/include/../crypto/bio/bss_dgram.c:17:12: fatal error: netinet/sctp.h: No such file or directory
 #  include <netinet/sctp.h>
            ^~~~~~~~~~~~~~~~
compilation terminated.

hook-s3c avatar Mar 28 '19 07:03 hook-s3c

So I searched my system for sctp.h and found it on /usr/include/netinet/sctp.h

-# include <netinet/sctp.h> +# include </usr/include/netinet/sctp.h>

in openssl/crypto/bio/bss_dgram.c

I'm not proud, but it got me a little further...

# github.com/ipsn/go-libtor/libtor
In file included from libtor/openssl_crypto_bn_bn_dh.go:10:
libtor/../openssl/include/../crypto/bn/bn_dh.c:479:4: error: #error "unsupported BN_BITS2"
 #  error "unsupported BN_BITS2"
    ^~~~~

https://github.com/ipsn/go-libtor/blob/7eb60e4a5fc96ce50b3d0250bde2b75865e24a0e/openssl/crypto/bn/bn_dh.c#L479

hook-s3c avatar Mar 28 '19 08:03 hook-s3c

I tried to hack some C, but it's not going to work out - maybe you have a better idea of what's needed. I can help with testing, just let me know!

hook-s3c avatar Mar 28 '19 09:03 hook-s3c

Just saw this issue. So, the way I've been generating the correct constants is to manually build all the dependencies on the target hardware and then see what values the local make process generates. Then incorporate those into the pre-configured templates.

karalabe avatar May 26 '19 10:05 karalabe