Skip to content

gollvm: error: undefined reference to 'runtime.strhash..f.1' #52899

@tianxiaogu

Description

@tianxiaogu
# command-line-arguments
/tmp/go-build3560960528/b001/_pkg_.a(_go_.o):gomodule:type..map_6string_7int: error: undefined reference to 'runtime.strhash..f.1'

The error can be reproduced with the test case and the trunk.

package main

import "unsafe"

var E_hash func(unsafe.Pointer, uintptr) uintptr = strhash

//go:noescape
//go:linkname strhash runtime.strhash
func strhash(unsafe.Pointer, uintptr) uintptr

func pointer(s string) unsafe.Pointer {
	return unsafe.Pointer(&s)
}

func main() {
	var m map[string]int
	m = make(map[string]int)
	m["123"] = 1
	if E_hash == nil {
		panic("Oops")
	}
	if E_hash(pointer("123"), 0) != E_hash(pointer("123"), 0) {
		panic("Oops")
	}
}

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 uses module_->getGlobalVariable(gname) (without parameter AllowLocal) to check existing globals, which cannot find GlobalVariable with local linkage. To fix this issue, we should set is_hidden = false in Func_descriptor_expression::do_get_backend if the Function or Function_declaration has a non-empty asm_name.

Moreover, we need to set AllowLocal = true when trying to find globals via module_->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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions