Skip to content

GOFF global symbols #996

Description

@philipc

The spec says (note that it calls module scope "global"):

Binding Scope	5.4	Bit(4)	Requested binding or resolution-search scope of an external symbol.

B'0000'
    Unspecified
B'0001'
    Section scope ("local")
B'0010'
    Module scope ("global")
B'0011'
    Library scope.
B'0100'
    Import-Export scope

All other values are reserved.

GoffSymbol::is_global() treats module scope as local:
(Note that there's a separate issue where binding_scope() is reading the wrong nibble.)

// If binding scope is section or module symbol is local
let scope = self.behavioral_flags().binding_scope();
if is_section || is_local_name || scope == GOFF_SCOPE_SECTION || scope == GOFF_SCOPE_MODULE
{
return false;
}

write_defined_symbol() uses module scope for SymbolScope::Linkage symbols:
(For ELF, SymbolScope::Linkage means it is global for static linking, but not visible for dynamic linking.)

object/src/write/goff.rs

Lines 716 to 723 in dce50f0

// Determine binding scope based on symbol properties
let scope = if symbol.is_local() {
goff::GOFF_SCOPE_SECTION
} else if symbol.scope == SymbolScope::Dynamic {
goff::GOFF_SCOPE_IMPORT_EXPORT
} else {
goff::GOFF_SCOPE_MODULE
};

LLVM reads module scope as local (does not set SF_GLOBAL):
https://github.com/llvm/llvm-project/blob/3306ae1c98d695d7d111bd8037380c7d09e818b6/llvm/lib/Object/GOFFObjectFile.cpp#L446-L458

LLVM writes library scope or import-export scope for globals, otherwise section scope (never module scope):
https://github.com/llvm/llvm-project/blob/3306ae1c98d695d7d111bd8037380c7d09e818b6/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp#L2910-L2914

@dalvescb Which ones need changing? Based on the LLVM behaviour we probably should switch write_defined_symbol() to library scope instead of module scope, but I'm a bit confused why the spec says module scope is global but LLVM treats it as local.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions