Skip to content

Pragma to prevent symbol from being optimized away #879

@firelizzard18

Description

@firelizzard18

I would like to create symbols (variables, constants, functions) that may not be directly referenced, but need to exist in the executable for one reason or another. I'm imagining adding a keep bool field to compiler.globalInfo and case "//go:used" or case "//go:keep" to globalInfo.parsePragmas. Then something would need to be added to keep the symbol, maybe in compiler.getGlobal.

I would be happy to create a PR implementing this, but I can't for the life of me figure out how to mark a global as "this will be used, do not optimize it away". There must be some way to do it, because clang respects __attribute((used)), but googling "clang used attribute" is not effective.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions