It's possible that this is due to a behavior change in the Darwin
linker. It is also possible that this has only ever worked by
coincidence on Darwin.
When doing a cgo link, the Go linker will create a C object file
containing all the Go code. It will pass it to the C linker along
with the all the C objects generated from files created by cgo. On
GNU/Linux I see the Go BSS symbols that contain pointer values, then
runtime.ebss, then all the C BSS symbols including the race detector
symbols, then runtime.noptrbss, then all the Go BSS symbols that do
not contain pointer values. So this works fine, as the Go race
detector allocates space for everything between runtime.data and
runtime.enoptrbss, which happens to include all the C symbols. In the
object file passed to the C linker, the Go BSS symbols with pointer
values will be in a section named .bss and the Go BSS symbols without
pointer values will be in a section named .noptrbss. In general the C
BSS symbols will be in a section named .bss. A typical ELF linker
will group all the .bss sections together, and will put the .noptrbss
section after them.
Apparently that is not happening with your link. The Darwin ld man
page hints that it places all sections from each input file in order,
rather than grouping them by name as an ELF linker does. That would
be consistent with what you are seeing.
That is also what I see when I use gomote to build the misc/cgo/test
test with -race. For my test binary, everything works fine.
runtime.enoptrbss is at 0x4d05160. The final symbol in the program,
_issue8811Initialized, is at 0x4d05374. Those are on the same page in
memory, the one from 0x4d05000 to 0x4d06000, so the mmap of the Go
symbols include the C symbols.
Actually, though, the same is true of the values you show above.
runtime.enoptrbss is at 0x4cef0a0, which is a page that extends to
0x4cf0000, which is less than the hola symbol, so I don't know why
your program is failing. Oh, I see, that program is not failing. The
one that is failing is using some patch that must be shifting the
addresses so that the C symbols are on a different page.
Presumably the ideal fix would be for the race detector to somehow
create a shadow map for the C symbols. But I don't know how to do
that. I don't know how the program can discover the end of the BSS
section. The Darwin linker does not seem to create an _end symbol as
ELF linkers do.
Ian