hmgle / graftcp

A flexible tool for redirecting a given program's TCP traffic to SOCKS5 or HTTP proxy.
GNU General Public License v3.0
2.07k stars 174 forks source link

Fail to compile parallelly #65

Closed unlsycn closed 5 months ago

unlsycn commented 5 months ago

Describe the bug make -j并行编译会导致链接问题

To Reproduce Steps to reproduce the behavior:

  1. checkout to tag v0.7.1
  2. make -j20

Desktop (please complete the following information):

Additional context 给graftcp打包ebuild的时候发现的问题,通过portage调用emake-j8时稳定复现,手动编译-j20时有概率出现。 这两种方式看上去触发的不是同一个问题,但是都应该是make的嵌套调用引起的并行问题。 emake -j8

make -j8
fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
gcc -O2 -pipe -march=native -Wall -O2 -DNDEBUG -DVERSION=\"v0.6\" -c -o main.o main.c
gcc -O2 -pipe -march=native -Wall -O2 -DNDEBUG -DVERSION=\"v0.6\" -c -o graftcp.o graftcp.c
gcc -O2 -pipe -march=native -Wall -O2 -DNDEBUG -DVERSION=\"v0.6\" -c -o util.o util.c
gcc -O2 -pipe -march=native -Wall -O2 -DNDEBUG -DVERSION=\"v0.6\" -c -o cidr-trie.o cidr-trie.c
gcc -O2 -pipe -march=native -Wall -O2 -DNDEBUG -DVERSION=\"v0.6\" -c -o conf.o conf.c
make -C local VERSION=v0.6 CC=gcc CXX=g++ AR=ar
make -C local VERSION=v0.6 CC=gcc CXX=g++ AR=ar
make[1]: Entering directory '/var/tmp/portage/net-proxy/graftcp-0.7.1/work/graftcp-0.7.1/local'
make[1]: Entering directory '/var/tmp/portage/net-proxy/graftcp-0.7.1/work/graftcp-0.7.1/local'
go build -ldflags "-s -w -X main.version=v0.6" ./cmd/graftcp-local
make -C .. libgraftcp.a
go build -ldflags "-s -w -X main.version=v0.6" ./cmd/graftcp-local
make -C .. libgraftcp.a
make[2]: Entering directory '/var/tmp/portage/net-proxy/graftcp-0.7.1/work/graftcp-0.7.1'
make[2]: Entering directory '/var/tmp/portage/net-proxy/graftcp-0.7.1/work/graftcp-0.7.1'
ar rcs libgraftcp.a graftcp.o util.o cidr-trie.o conf.o
ar rcs libgraftcp.a graftcp.o util.o cidr-trie.o conf.o
make[2]: Leaving directory '/var/tmp/portage/net-proxy/graftcp-0.7.1/work/graftcp-0.7.1'
go build -ldflags "-s -w -X main.version=v0.6" ./cmd/mgraftcp
make[2]: Leaving directory '/var/tmp/portage/net-proxy/graftcp-0.7.1/work/graftcp-0.7.1'
go build -ldflags "-s -w -X main.version=v0.6" ./cmd/mgraftcp
gcc main.o graftcp.o util.o cidr-trie.o conf.o -o graftcp
# github.com/hmgle/graftcp/local/cmd/mgraftcp
/usr/lib/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: /var/tmp/portage/net-proxy/graftcp-0.7.1/work/graftcp-0.7.1/libgraftcp.a: error adding symbols: archive has no index; run ranlib to add one
collect2: error: ld returned 1 exit status

make[1]: *** [Makefile:31: mgraftcp] Error 1
make[1]: Leaving directory '/var/tmp/portage/net-proxy/graftcp-0.7.1/work/graftcp-0.7.1/local'
make: *** [Makefile:71: local/graftcp-local] Error 2
make: *** Waiting for unfinished jobs....
# github.com/hmgle/graftcp/local/cmd/mgraftcp
/usr/lib/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: /var/tmp/portage/net-proxy/graftcp-0.7.1/work/graftcp-0.7.1/libgraftcp.a: error adding symbols: archive has no index; run ranlib to add one
collect2: error: ld returned 1 exit status

make[1]: *** [Makefile:31: mgraftcp] Error 1
make[1]: Leaving directory '/var/tmp/portage/net-proxy/graftcp-0.7.1/work/graftcp-0.7.1/local'
make: *** [Makefile:71: local/mgraftcp] Error 2

make -j20

fatal: not a git repository (or any of the parent directories): .git
fatal: not a git repository (or any of the parent directories): .git
gcc -Wall -O2 -DNDEBUG -DVERSION=\"v0.6\" -c -o main.o main.c
gcc -Wall -O2 -DNDEBUG -DVERSION=\"v0.6\" -c -o graftcp.o graftcp.c
gcc -Wall -O2 -DNDEBUG -DVERSION=\"v0.6\" -c -o util.o util.c
gcc -Wall -O2 -DNDEBUG -DVERSION=\"v0.6\" -c -o cidr-trie.o cidr-trie.c
gcc -Wall -O2 -DNDEBUG -DVERSION=\"v0.6\" -c -o conf.o conf.c
make -C local VERSION=v0.6 CC=gcc CXX=g++ AR=ar
make -C local VERSION=v0.6 CC=gcc CXX=g++ AR=ar
make[1]: Entering directory '/home/unlsycn/Downloads/graftcp-0.7.1/local'
make[1]: Entering directory '/home/unlsycn/Downloads/graftcp-0.7.1/local'
go build -ldflags "-s -w -X main.version=v0.6" ./cmd/graftcp-local
go build -ldflags "-s -w -X main.version=v0.6" ./cmd/graftcp-local
make -C .. libgraftcp.a
make -C .. libgraftcp.a
make[2]: Entering directory '/home/unlsycn/Downloads/graftcp-0.7.1'
make[2]: Entering directory '/home/unlsycn/Downloads/graftcp-0.7.1'
gcc -Wall -O2 -DNDEBUG -DVERSION=\"v0.6\" -c -o graftcp.o graftcp.c
gcc -Wall -O2 -DNDEBUG -DVERSION=\"v0.6\" -c -o util.o util.c
gcc -Wall -O2 -DNDEBUG -DVERSION=\"v0.6\" -c -o cidr-trie.o cidr-trie.c
gcc -Wall -O2 -DNDEBUG -DVERSION=\"v0.6\" -c -o conf.o conf.c
gcc -Wall -O2 -DNDEBUG -DVERSION=\"v0.6\" -c -o graftcp.o graftcp.c
gcc -Wall -O2 -DNDEBUG -DVERSION=\"v0.6\" -c -o util.o util.c
gcc -Wall -O2 -DNDEBUG -DVERSION=\"v0.6\" -c -o cidr-trie.o cidr-trie.c
gcc -Wall -O2 -DNDEBUG -DVERSION=\"v0.6\" -c -o conf.o conf.c
gcc main.o graftcp.o util.o cidr-trie.o conf.o -o graftcp
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: graftcp.o: in function `client_main':
graftcp.c:(.text+0xb96): undefined reference to `conf_init'
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: graftcp.c:(.text+0xbab): undefined reference to `conf_init'
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: graftcp.c:(.text+0xd2e): undefined reference to `conf_read'
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: graftcp.c:(.text+0xd39): undefined reference to `conf_override'
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: graftcp.c:(.text+0xd46): undefined reference to `conf_override'
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: graftcp.c:(.text+0xec6): undefined reference to `conf_free'
/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: graftcp.c:(.text+0xed0): undefined reference to `conf_free'
collect2: error: ld returned 1 exit status
make: *** [Makefile:62: graftcp] Error 1
make: *** Waiting for unfinished jobs....
ar rcs libgraftcp.a graftcp.o util.o cidr-trie.o conf.o
ar rcs libgraftcp.a graftcp.o util.o cidr-trie.o conf.o
make[2]: Leaving directory '/home/unlsycn/Downloads/graftcp-0.7.1'
go build -ldflags "-s -w -X main.version=v0.6" ./cmd/mgraftcp
make[2]: Leaving directory '/home/unlsycn/Downloads/graftcp-0.7.1'
go build -ldflags "-s -w -X main.version=v0.6" ./cmd/mgraftcp
make[1]: Leaving directory '/home/unlsycn/Downloads/graftcp-0.7.1/local'
make[1]: Leaving directory '/home/unlsycn/Downloads/graftcp-0.7.1/local'
hmgle commented 5 months ago

@unlsycn 已修复,感谢反馈。如有问题欢迎重新打开该 issue。

unlsycn commented 5 months ago

@unlsycn 已修复,感谢反馈。如有问题欢迎重新打开该 issue。

现在没问题了,谢谢!

顺便问一句,go build时添加-s作为ldflag是因为打deb包有什么要求么?因为portage一般希望由用户决定是否保留符号信息,我打包时把它patch掉了,所以我比较好奇当时为什么要加这个flag。

hmgle commented 5 months ago

@unlsycn 已修复,感谢反馈。如有问题欢迎重新打开该 issue。

现在没问题了,谢谢!

顺便问一句,go build时添加-s作为ldflag是因为打deb包有什么要求么?因为portage一般希望由用户决定是否保留符号信息,我打包时把它patch掉了,所以我比较好奇当时为什么要加这个flag。

仅仅是为了减少生成二进制文件的体积,没有考虑各种平台的打包偏好或习惯。 DEB 系的好像对需要保留符号表和调试信息的会有专门的 dbg 包。