-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/link: function "decodetypeGcmask" read gcdata from shared object file may not correct when use lld
link in linux/arm64
#69466
Comments
By the way, when I use When I run this command It's probably in an infinite loop. Some backtrace: #0 runtime.growslice (oldPtr=0x406c90c300, newLen=33, oldCap=32, num=1, et=0x6505c0, ~r0=...) at /usr1/go/src/runtime/slice.go:177
#1 0x00000000004743c4 in cmd/go/internal/load.PackageList.func1 (p=0x400036ac08) at /usr1/go/src/cmd/go/internal/load/pkg.go:2684
#2 0x000000000047437c in cmd/go/internal/load.PackageList.func1 (p=0x400007ec08) at /usr1/go/src/cmd/go/internal/load/pkg.go:2682
#3 0x000000000047437c in cmd/go/internal/load.PackageList.func1 (p=0x400007e008) at /usr1/go/src/cmd/go/internal/load/pkg.go:2682
#4 0x000000000047437c in cmd/go/internal/load.PackageList.func1 (p=0x400036b808) at /usr1/go/src/cmd/go/internal/load/pkg.go:2682
#5 0x000000000047437c in cmd/go/internal/load.PackageList.func1 (p=0x4000373808) at /usr1/go/src/cmd/go/internal/load/pkg.go:2682
#6 0x000000000047427c in cmd/go/internal/load.PackageList (roots=..., ~r0=...) at /usr1/go/src/cmd/go/internal/load/pkg.go:2687
#7 0x0000000000476620 in cmd/go/internal/load.setToolFlags (pkgs=...) at /usr1/go/src/cmd/go/internal/load/pkg.go:3118
#8 0x0000000000474b0c in cmd/go/internal/load.LoadPackageWithFlags (path=..., srcDir=..., stk=<optimized out>, importPos=..., mode=<optimized out>, ~r0=<optimized out>)
at /usr1/go/src/cmd/go/internal/load/pkg.go:2748
#9 0x00000000004c59a8 in cmd/go/internal/work.readpkglist (shlibpath=..., pkgs=...) at /usr1/go/src/cmd/go/internal/work/action.go:411
#10 0x00000000004c91a4 in cmd/go/internal/work.(*Builder).linkSharedAction.func1 (~r0=<optimized out>) at /usr1/go/src/cmd/go/internal/work/action.go:895
#11 0x00000000004c5f00 in cmd/go/internal/work.(*Builder).cacheAction (b=0x40001a0360, mode=..., p=0x0, f={void (cmd/go/internal/work.Action *)} 0x403dfb7028, ~r0=<optimized out>)
at /usr1/go/src/cmd/go/internal/work/action.go:424
#12 0x00000000004c8a88 in cmd/go/internal/work.(*Builder).linkSharedAction (b=0x40001a0360, mode=2, depMode=2, shlib=..., a1=<optimized out>, ~r0=<optimized out>)
at /usr1/go/src/cmd/go/internal/work/action.go:891
#13 0x00000000004c80c0 in cmd/go/internal/work.(*Builder).addTransitiveLinkDeps (b=0x40001a0360, a=0x406c8b78c0, a1=0x406c8b7760, shlib=...)
at /usr1/go/src/cmd/go/internal/work/action.go:840
#14 0x00000000004c95b0 in cmd/go/internal/work.(*Builder).linkSharedAction.func1 (~r0=<optimized out>) at /usr1/go/src/cmd/go/internal/work/action.go:966
#15 0x00000000004c5f00 in cmd/go/internal/work.(*Builder).cacheAction (b=0x40001a0360, mode=..., p=0x0, f={void (cmd/go/internal/work.Action *)} 0x403dfb7498, ~r0=<optimized out>)
at /usr1/go/src/cmd/go/internal/work/action.go:424
#16 0x00000000004c8a88 in cmd/go/internal/work.(*Builder).linkSharedAction (b=0x40001a0360, mode=2, depMode=2, shlib=..., a1=<optimized out>, ~r0=<optimized out>)
at /usr1/go/src/cmd/go/internal/work/action.go:891
#17 0x00000000004c80c0 in cmd/go/internal/work.(*Builder).addTransitiveLinkDeps (b=0x40001a0360, a=0x406c8b7080, a1=0x406c8b6f20, shlib=...)
at /usr1/go/src/cmd/go/internal/work/action.go:840
#18 0x00000000004c95b0 in cmd/go/internal/work.(*Builder).linkSharedAction.func1 (~r0=<optimized out>) at /usr1/go/src/cmd/go/internal/work/action.go:966
#19 0x00000000004c5f00 in cmd/go/internal/work.(*Builder).cacheAction (b=0x40001a0360, mode=..., p=0x0, f={void (cmd/go/internal/work.Action *)} 0x403dfb7908, ~r0=<optimized out>)
at /usr1/go/src/cmd/go/internal/work/action.go:424
#20 0x00000000004c8a88 in cmd/go/internal/work.(*Builder).linkSharedAction (b=0x40001a0360, mode=2, depMode=2, shlib=..., a1=<optimized out>, ~r0=<optimized out>)
at /usr1/go/src/cmd/go/internal/work/action.go:891
#21 0x00000000004c80c0 in cmd/go/internal/work.(*Builder).addTransitiveLinkDeps (b=0x40001a0360, a=0x406c7a6dc0, a1=0x406c7a6c60, shlib=...)
at /usr1/go/src/cmd/go/internal/work/action.go:840
#22 0x00000000004c95b0 in cmd/go/internal/work.(*Builder).linkSharedAction.func1 (~r0=<optimized out>) at /usr1/go/src/cmd/go/internal/work/action.go:966
#23 0x00000000004c5f00 in cmd/go/internal/work.(*Builder).cacheAction (b=0x40001a0360, mode=..., p=0x0, f={void (cmd/go/internal/work.Action *)} 0x403dfb7d78, ~r0=<optimized out>)
at /usr1/go/src/cmd/go/internal/work/action.go:424
#24 0x00000000004c8a88 in cmd/go/internal/work.(*Builder).linkSharedAction (b=0x40001a0360, mode=2, depMode=2, shlib=..., a1=<optimized out>, ~r0=<optimized out>)
at /usr1/go/src/cmd/go/internal/work/action.go:891
#25 0x00000000004c80c0 in cmd/go/internal/work.(*Builder).addTransitiveLinkDeps (b=0x40001a0360, a=0x406c7a6580, a1=0x406c7a6420, shlib=...)
at /usr1/go/src/cmd/go/internal/work/action.go:840
|
If I use the CC=$LLVM/bin/clang CXX=$LLVM/bin/clang++ go install -a -ldflags="-extldflags=-fuse-ld=gold" -buildmode=shared runtime sync/atomic
CC=$LLVM/bin/clang CXX=$LLVM/bin/clang++ go build -a -ldflags="-extldflags=-fuse-ld=gold" -linkshared temp.go
GODEBUG=clobberfree=1 ./temp During go/src/cmd/link/internal/ld/decodesym.go Line 220 in a74951c
Check the data of the $ nm $GOROOT/pkg/linux_arm64_dynlink/libruntime,sync-atomic.so | grep "type:error"
00000000003166c0 D type:error
$ objdump -s --start-address=0x3166c0 --stop-address=0x3166f0 $GOROOT/pkg/linux_arm64_dynlink/libruntime,sync-atomic.so
objdump: Warning: Corrupt unit length (0x40000000) found in section .debug_info
/usr1/GoRelease/go1.23.1/pkg/linux_arm64_dynlink/libruntime,sync-atomic.so: file format elf64-littleaarch64
Contents of section .data.rel.ro:
3166c0 10000000 00000000 10000000 00000000 ................
3166d0 35ff0330 07080814 100b3400 00000000 5..0......4.....
3166e0 38862800 00000000 810b0000 206e0100 8.(......... n..
$ objdump -s --start-address=0x288638 --stop-address=0x288648 $GOROOT/pkg/linux_arm64_dynlink/libruntime,sync-atomic.so
Contents of section .rodata:
288638 02000000 00000000 38000000 00000000 ........8.......
$ readelf -r $GOROOT/pkg/linux_arm64_dynlink/libruntime,sync-atomic.so | grep 3166e0
0000003166e0 000000000403 R_AARCH64_RELATIV 288638 The address of the The relocation information (in the |
However, when using the $ nm $GOROOT/pkg/linux_arm64_dynlink/libruntime,sync-atomic.so | grep "type:error"
000000000032aec0 D type:error
$ objdump -s --start-address=0x32aec0 --stop-address=0x32aef0 $GOROOT/pkg/linux_arm64_dynlink/libruntime,sync-atomic.so
Contents of section .data.rel.ro:
32aec0 10000000 00000000 10000000 00000000 ................
32aed0 35ff0330 07080814 00000000 00000000 5..0............
32aee0 08000000 00000000 810b0000 206e0100 ............ n..
$ readelf -r $GOROOT/pkg/linux_arm64_dynlink/libruntime,sync-atomic.so | grep 32aee0
00000032aee0 000000000403 R_AARCH64_RELATIV 1bdf38
$ objdump -s --start-address=0x1bdf38 --stop-address=0x1bdf48 $GOROOT/pkg/linux_arm64_dynlink/libruntime,sync-atomic.so
Contents of section .rodata:
1bdf38 02000000 00000000 38000000 00000000 ........8.......
The address of the The correct address This should be the difference between So I think this may be an undefined behavior, and the go linker may depend on this undefined behavior. So maybe we should modify the code to read the correct address from the relocation information? |
lld
link in linux/arm64lld
link in linux/arm64
Unfortunately I cannot reproduce this. What version of the llvm tools are you using? |
Sorry, in the above test, my lld version number was I do more test: I downloaded The problem can be reproduced in my ARM64 environment with Go1.23.1 and LLVM 16.0.6 . My ARM64 machine is linux kernal 5.10.0 But, when I test, the following warning is reported: /usr1/clang+llvm-16.0.6-aarch64-linux-gnu/bin/clang: /usr/lib64/libtinfo.so.6: no version information available (required by /usr1/clang+llvm-16.0.6-aarch64-linux-gnu/bin/clang) However, it still generates binary. So I ignore such warning. I downloaded The problem can be reproduced in my X86_64 environment with Go1.23.1 and LLVM 15.0.4 . |
In addition, I simply tested the difference between lld and gold by The code is #include<stdio.h>
struct Node {
int data;
struct Node *next;
struct Node *prev;
};
struct Node prev = {0xcc, NULL, NULL};
struct Node next = {0xbb, NULL, NULL};
struct Node head = {0xaa, &next, &prev}; Use gold: $ export PATH="$LLVM/bin:$PATH"
$ clang -fuse-ld=gold -shared -o libexample.so example.c && objdump -s -j.data libexample.so && readelf -r libexample.so
libexample.so: file format elf64-littleaarch64
Contents of section .data:
20010 10000200 00000000 cc000000 00000000 ................
20020 00000000 00000000 00000000 00000000 ................
20030 bb000000 00000000 00000000 00000000 ................
20040 00000000 00000000 aa000000 00000000 ................
20050 30000200 00000000 18000200 00000000 0...............
// ignore some items
000000020058 000800000101 R_AARCH64_ABS64 0000000000020018 prev + 0
000000020050 000a00000101 R_AARCH64_ABS64 0000000000020030 next + 0
You can see data Use lld: $ export PATH="$LLVM/bin:$PATH"
$ clang -fuse-ld=lld -shared -o libexample.so example.c && objdump -s -j.data libexample.so && readelf -r libexample.so
libexample.so: file format elf64-littleaarch64
Contents of section .data:
30890 00000000 00000000 cc000000 00000000 ................
308a0 00000000 00000000 00000000 00000000 ................
308b0 bb000000 00000000 00000000 00000000 ................
308c0 00000000 00000000 aa000000 00000000 ................
308d0 00000000 00000000 00000000 00000000 ................
// ignore some items
0000000308d8 000500000101 R_AARCH64_ABS64 0000000000030898 prev + 0
0000000308d0 000600000101 R_AARCH64_ABS64 00000000000308b0 next + 0
You can see zero data on the address Of course, in this test of the C code, the relocation type here is |
Go version
go version go1.23.1 linux/arm64
Output of
go env
in your module/workspace:What did you do?
temp.go
file:What did you see happen?
or
What did you expect to see?
no crash.
The text was updated successfully, but these errors were encountered: