golang/go
View on GitHubcmd/objdump: doesn't disassemble the last function in a macho file
Open
#78811 opened on Apr 16, 2026
BugReportNeedsFixOS-Darwincompiler/runtimehelp wanted
Description
On darwin, do:
main.c:
void f();
void g();
int main() {
f();
g();
return 0;
}
main.s:
.globl _f
_f:
add x0, x0, x0
add x1, x1, x1
ret
.globl _g
_g:
add x2, x2, x2
add x3, x3, x3
ret
gcc -O3 main.c main.s
go tool objdump a.out
This will print the body of main and f, but does not print the body of g. We get only the TEXT line:
TEXT _main(SB)
:0 0x100000328 a9bf7bfd STP.W (R29, R30), -16(RSP)
:0 0x10000032c 910003fd MOVD RSP, R29
:0 0x100000330 94000005 CALL _f(SB)
:0 0x100000334 94000007 CALL 7(PC)
:0 0x100000338 52800000 MOVW $0, R0
:0 0x10000033c a8c17bfd LDP.P 16(RSP), (R29, R30)
:0 0x100000340 d65f03c0 RET
TEXT _f(SB)
:0 0x100000344 8b000000 ADD R0, R0, R0
:0 0x100000348 8b010021 ADD R1, R1, R1
:0 0x10000034c d65f03c0 RET
TEXT _g(SB)
Looks like the size of the g symbol is set to 0. The code that does this, in cmd/internal/objfile/macho.go:symbols(), sets the size of a symbol by looking at the address of the next higher symbol and subtracting. For the last symbol in the file, this doesn't work. We should probably use the end of the containing section or something.
The "CALL 7(PC)" instead of "CALL _g(SB)" might be related.