heiher / hev-socks5-tunnel

A high-performance tun2socks for Linux/Android/FreeBSD/macOS/iOS/WSL2 (IPv4/IPv6/TCP/UDP)
MIT License
636 stars 130 forks source link

Compilation issues on Centos9 #118

Closed pronebird closed 2 months ago

pronebird commented 2 months ago

Hi,

Just stumbled upon a mysterious error today when linking the static lib into rust project on Centos9, a lot of errors like this:

/usr/bin/ld: [REDACTED]/third-party/lib/libhev-task-system.a(hev-memory-allocator-slice.o): relocation R_X86_64_32 against `.text' can not be used when making a PIE object; recompile with -fPIE

/usr/bin/ld: [REDACTED]/third-party/lib/libhev-task-system.a(hev-task-aide.o): relocation R_X86_64_32 against `.bss' can not be used when making a PIE object; recompile with -fPIE

Naive approach of simply passing the flag doesn't help either:

diff --git a/Makefile b/Makefile
index d6d87cb..9e1e852 100644
--- a/Makefile
+++ b/Makefile
@@ -35,6 +35,8 @@ THIRDPARTS=$(THIRDPARTDIR)/yaml \
                   $(THIRDPARTDIR)/lwip \
                   $(THIRDPARTDIR)/hev-task-system

+$(STATIC_TARGET) : CCFLAGS+=-fPIC
+
 $(SHARED_TARGET) : CCFLAGS+=-fPIC
 $(SHARED_TARGET) : LDFLAGS+=-shared -pthread

The thing is that the static lib builds fine, but then Rust fails to link the compiled static libraries. Do you happen to know what could be the problem?

pronebird commented 2 months ago

Wanted to share that it seems that adding -fPIC for static target in all makefiles works great, see gist:

https://gist.github.com/pronebird/1b66745ac00773e88b16508522ff8d81

If it makes sense, can we please patch all of the makefiles? It would be difficult to do as a part of single PR as there are submodules across the board.

Its however unusual that the project builds just fine on Ubuntu and Debian but not on Centos.

heiher commented 2 months ago

There is a rust binding for this project: https://github.com/heiher/tun2socks

pronebird commented 2 months ago

I know, but they don't compile on macOS as a dependency to my project.

heiher commented 2 months ago

I know, but they don't compile on macOS as a dependency to my project.

Why link directly to hev-socks5-tunnel instead of tun2socks on macOS?

heiher commented 2 months ago

I think you can append -fPIC to CFLAGS:

make CFLAGS=-fPIC
pronebird commented 2 months ago

Why link directly to hev-socks5-tunnel instead of tun2socks on macOS?

Back then, tun2socks 1.0.2 didn't compile on Mac, so I pulled the C library directly. Then I started working on adding the possibility to start the tunnel using string config instead of file and the project just kept being linked directly ever since.

Today I pulled tun2socks 1.0.4 that you had released yesterday and it seems to compile just fine across the board. So I am switching over to rust crate. Thanks.