-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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/ld: invoke host linker for Windows cgo build #4069
Comments
Issue #3591 has been merged into this issue. |
Issue #4272 has been merged into this issue. |
Issue #1781 has been merged into this issue. |
Issue #3141 has been merged into this issue. |
Issue #3755 has been merged into this issue. |
An update: the beginning of this is implemented for darwin, linux, and *bsd on amd64 and 386. You can play by invoking the go build of a command with -ldflags=-hostobj but if it breaks you get to keep both pieces. Dwarf information is not correct, so you might need -ldflags='-w -hostobj' depending on how paranoid the system linker is. Windows has not been attempted yet. ARM has not been attempted yet. There is a real possibility that ARM and Windows will be skipped for this go-round. |
It's unclear to me how much is left in cmd/5l. The 6l and 8l linkers already had a concept of a relocation and recorded the places that needed to be relocated, as part of the standard linking, so that individual functions could be laid out separately and put together only at the end. Adjusting them to emit the not-applied relocations was fairly straightforward. 5l does not have that flexibility: it lays out the entire code segment at once, because I never changed it like I did 6l and 8l. So the required changes are more spread out than in 6l/8l. Any part of the code layout in asm.c that uses ->pc or ->value is suspect. However, the simplicity of the ARM instruction set might make it easier to find these. At the least, the two 'TODO: Use addrel' comments need to do that, although the one for UNDEF could be changed into two instructions instead (MOVW $0, R0; BL R0). Also any case listed in the table for C_SBRA or C_ADDR arguments, so cases 5, 11, 63, 64, 65, 68, 69, 74, 93, 94. It could be that most of the work is in addpool. It's all very unclear to me. |
Issue #4782 has been merged into this issue. |
What is the plan for the ELF TLS sections? I have a test here that verifies whether __thread variables work in foreign code: https://golang.org/cl/7578043/ It currently crashes, presumably because TLS sections are missing from the -hostobj generated executable. |
Calling __tls_get_addr would be required when compiling in PIC mode for code to go into shared libraries. However, that is not the normal mode and I don't see why we should support it to start. When not compiling PIC and not putting the code into a shared library there is no need to call __tls_get_addr. Instead, 6l would generate a R_X86_64_TPOFF32 reloc on a "mov %fs:0,REG" instruction. 8l would generate a R_386_TLE_LE reloc on a "mov %gs:0,REG" instruction. Not sure about 5l; we may need a __aeabi_read_tp call there for ARMv5. For sufficiently new ARM processors we can use an mrc instruction to get the value and a R_ARM_TLS_LE32 reloc to get the offset. |
Oh man, I messed up that sentence. When host linking, the .debug_gdb_scripts symbol isn't emitted, so the gdb script isn't automatically loaded. Manually loading the script complains about a missing type symbol with the following error: Loading Go Runtime support. Traceback (most recent call last): File "../go/src/pkg/runtime/runtime-gdb.py", line 198, in <module> _rctp_type = gdb.lookup_type("struct runtime.rtype").pointer() gdb.error: No struct type named runtime.rtype. |
Since the debug problem wont be solved before go1.1, I've created issue #5221. |
Issue #5106 has been merged into this issue. |
issue #5590 added host linker support to 5l and added linux/arm to the list of os/arch targets supporting host linking. |
Removes all dynamic_cast, in order to make it work without RTTI. This is due to golang/go#10023 (duplicate of golang/go#4069) and solves go-qml#19.
Make it work without global variable initialization. This is due to golang/go#10023 (duplicate of golang/go#4069) and solves go-qml#142.
ld was only providing 4-byte alignment, which is not enough even on 386 (runtime.test_z64 requires 8-byte alignment and was not met before this change.) Like 640 KB memory, 32-byte alignment should be enough for everybody. misc/cgo/test passed with this change in external linking mode. Update golang/go#4069: this change fixes the issue for 386. Signed-off-by: Shenghou Ma <minux@golang.org>
Just found another benefit of external linking. |
Happy to see this will be fixed in Go1.5, really appreciating. |
@minux Greate, thanks for your work! |
Update #4069: this CL fixes the issue on windows/386. Signed-off-by: Shenghou Ma <minux@golang.org> Change-Id: I2d2ea233f976aab3f356f9b508cdd246d5013e2e Reviewed-on: https://go-review.googlesource.com/7283 Reviewed-by: Ian Lance Taylor <iant@golang.org>
I compared file sizes for misc/cgo/test with -linkmode=internal and -linkmode=external. And the difference (about 1M) seems to be in dwarf sections (all sections starting with .debug). Should we do something about it? Alex |
Ahh, that explains the huge size difference. I will take a look. We should
generate those dwarf sections when doing external linking.
|
Removes all dynamic_cast, in order to make it work without RTTI. This is due to golang/go#10023 (duplicate of golang/go#4069) and solves go-qml#19.
Make it work without global variable initialization. This is due to golang/go#10023 (duplicate of golang/go#4069) and solves go-qml#142.
The text was updated successfully, but these errors were encountered: