Skip to content

cmd/link: place Darwin bind entries on the __DATA_CONST segment #71416

@qmuntal

Description

@qmuntal

#38830 moved the .rodata, .typelink, .itablink, and .gopclntab sections to the __DATA_CONST segment. Looks like the .got section can also go into that new segment. It is currently passed in the __DATA segment.

You can verify that the macOS clang linker already does what I'm suggesting here by following these steps:

  1. Build a hello world binary with go build -ldflags=linkmode=external -o ext
  2. Get the bind table by running objdump --macho --bind ./ext

The result is something like this:

Bind table:
segment  section            address     type       addend dylib            symbol
__DATA_CONST __got              0x100088000 bind ptr        0 libSystem        ___error
__DATA_CONST __got              0x100088008 bind ptr        0 libSystem        ___stderrp
...

While the same binary built with the Go internal linker has the following bind table:

Bind table:
segment  section            address    type       addend dylib            symbol
__DATA   __nl_symbol_ptr    0x1000EC2B0 pointer         0 libSystem        ___error
__DATA   __nl_symbol_ptr    0x1000EC2B8 pointer         0 libSystem        ___stderrp
...

Also note that clang names the.got section as __got on ARM, while we use __nl_symbol_ptr uncoditionally. Don't know if this makes any real difference, but clang made that change consciously in this commit: https://cgit.geodns-americas.gentoo.org/fork/llvm-project.git/commit/?h=release/3.8.x&id=e8d9df4ea52a5652a13f080614507d70e9f9ad79.

Go version:

go version go1.23.3 darwin/arm64

Clang version:

Apple clang version 16.0.0 (clang-1600.0.26.4)

@golang/compiler @golang/darwin

Metadata

Metadata

Assignees

Labels

FixPendingIssues that have a fix which has not yet been reviewed or submitted.ImplementationIssues describing a semantics-preserving change to the Go implementation.OS-Darwincompiler/runtimeIssues related to the Go compiler and/or runtime.

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions