binutils Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
objcopy

Objcopy: zap ELF visibility when localizing symbols

`objcopy` now clears ELF symbol visibility flags when localizing symbols to avoid violating the ELF specification.

When objcopy localizes symbols (making them only visible within the current object file), it now clears the ELF visibility flags associated with those symbols. The ELF specification forbids local symbols from having non-default visibility (like PROTECTED or HIDDEN). Failing to clear these flags could lead to unexpected behavior or toolchain errors.

In Details

The ELF specification prohibits STB_LOCAL symbols from having non-default visibility settings (STV_PROTECTED, STV_HIDDEN, or STV_INTERNAL). This commit modifies objcopy.c to clear the visibility bits in st_other when localizing symbols via --localize-symbols. This prevents the creation of invalid ELF files. The change affects symbol table processing within objcopy and requires understanding of ELF symbol visibility rules.

For Context

objcopy is a tool for copying and transforming object files. Object files contain compiled code and data, as well as a symbol table that maps names to addresses within the file. Symbols can have different visibility levels; they can be global (visible to other object files), local (only visible within the current file), or have other special visibility attributes. This commit fixes a potential issue where objcopy could create invalid object files when converting global symbols to local symbols. It ensures that local symbols don't retain visibility attributes that are only valid for global symbols, adhering to the ELF standard (the standard format for object files).

Filed Under: objcopyelfsymbol visibility