bazel-contrib / bazel-contrib/rules_go

is it possible to statically override malloc for cgo?

Open
#4,549 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.5k
Forks
760
Avg merge
1d 11h
Merged PRs (30d)
12

Description

I can't find anything online about doing this (bazel or not), but it would be nice if go_binary could expose malloc attribute (like cc_binary, maybe named cgo_malloc in this case) and/or support --custom_malloc. I could not find an existing way to make this work.

Use case: some go programs might be primarily cgo calls around larger C++ libraries (like for ml) and it would be nice to be able to use mimalloc or tcmalloc there. Presumably this can work with LD_PRELOAD but I was hoping for a static solution.

Contributor guide

Open the contributing guide

Research direction

Start by comparing the go_binary and cc_binary rule interfaces and trace how cgo linking is configured in Bazel. Investigate whether a cgo_malloc or --custom_malloc option can provide static allocator selection; done means establishing a supported configuration or documenting why only an approach such as LD_PRELOAD works.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, go
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.