Open tianxiaogu opened 2 years ago
There may be a bug here, but, to be clear, using //go:linkname strhash runtime.strhash
is completely unsupported. If this problem only arises with programs that use go:linkname
then I don't see any real need to fix it.
Still, this program does work with gccgo so it's odd that it fails with GoLLVM.
CC @thanm
The error can be reproduced with the test case and the trunk.
Func_descriptor_expression::do_get_backend
deals with function declaration and definition differently, which can request the backend twice to create global variables representing the function pointer. Unfortunately, the GOLLVM bridge usesmodule_->getGlobalVariable(gname)
(without parameterAllowLocal
) to check existing globals, which cannot findGlobalVariable
with local linkage. To fix this issue, we should setis_hidden = false
inFunc_descriptor_expression::do_get_backend
if theFunction
orFunction_declaration
has a non-emptyasm_name
.Moreover, we need to set
AllowLocal = true
when trying to find globals viamodule_->getGlobalVariable
and resolve linkage/type conflicts if necessary in GOLLVM bridge. Otherwise, the LLVM backend will rename the global by itself, which will lead to undefined reference errors.