GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
pe/coff

PE/COFF: Implement visibility attribute via .drectve

PE/COFF targets now support the visibility attribute by emitting directives to the .drectve section, matching Clang's behavior.

GCC’s PE/COFF targets (MinGW, Cygwin) previously ignored the visibility attribute with a warning. This commit implements support for VISIBILITY_HIDDEN and VISIBILITY_INTERNAL by emitting -exclude-symbols directives into the .drectve section. This behavior aligns with Clang and ensures that hidden symbols are correctly excluded from DLL exports, as the GNU linker respects these directives during auto-export processing.

In Details

This change enables the visibility attribute on PE/COFF targets by leveraging the .drectve section, similar to Clang's approach. For symbols marked VISIBILITY_HIDDEN or VISIBILITY_INTERNAL, the compiler now emits -exclude-symbols directives into .drectve, rather than just issuing a warning. The GNU linker, which processes this section for auto-exporting symbols from DLLs, correctly interprets these directives. This ensures that symbols with restricted visibility are not exported, providing proper control over the DLL interface.

For Context
PE/COFF
Portable Executable/Common Object File Format. The standard file format for executables, object code, and DLLs on 32-bit and 64-bit versions of Windows. MinGW and Cygwin use this format on Linux.
visibility attribute
A C/C++ language extension (supported by GCC and Clang) that allows developers to control the visibility of symbols (functions, variables) in shared libraries. Common levels are default, hidden, internal, and protected.
.drectve
A special section in PE/COFF object files used for directives that are processed by the linker. Common uses include specifying linker options or exclusion directives.
MinGW
Minimalist GNU for Windows. A development environment for creating Windows applications using the GNU Compiler Collection.
Cygwin
A POSIX-compatible environment for Windows that provides a Linux-like interface and tools, including GCC.
auto-export
A feature of some linkers (like the GNU linker on PE/COFF targets) where symbols are automatically exported from a DLL unless explicitly excluded.
VISIBILITY_HIDDEN
A visibility attribute level that makes a symbol not visible outside the shared object where it is defined. It cannot be referenced from other modules.
Filed Under: PE/COFFvisibilitylinkerMinGWCygwin