Fix user symbol prefix handling for directives in mingw PE targets
Correctly handle user symbol prefixes for directives like `asm` labels and `-export:` in GCC's mingw PE backend.
This commit addresses an issue in GCC’s mingw PE (Portable Executable) backend where user symbol prefix handling was incorrect for certain directives. Previously, the compiler might incorrectly strip leading underscores from function or variable names when they lacked an asm label. Conversely, when an asm label was used, the compiler needed to correctly incorporate the user label prefix into the directive, which was not happening. The fix modifies i386_pe_drectve_name and related functions to properly handle these scenarios, ensuring correct symbol visibility and directive processing, and adds new test cases.
In Details
The i386_pe_assemble_visibility function in GCC's mingw backend had issues correctly applying user label prefixes (e.g., leading underscores) to symbols, particularly when using asm labels or the -export: directive. The i386_pe_drectve_name function was modified to accept a string and selectively apply prefix logic based on whether the name originated from an asm label. This corrects cases where user prefixes were stripped incorrectly or where asm labels themselves needed to be prefixed correctly before being passed to the PE object file directives. New test cases target `dllexpor…
- PE
- Portable Executable; the file format used for executables, object code, DLLs, and other files used in 32-bit and 64-bit versions of Windows operating systems.
- user symbol prefix
- A prefix, typically an underscore, that GCC adds to symbols in assembly output for certain targets, distinguishing them from user-defined symbols.
- asm label
- A label explicitly provided in C/C++ code using the
asmkeyword, used to control the symbol name generated in assembly output. - -export:
- A GCC driver option for PE targets used to explicitly export symbols from a DLL.
- visibility
- A symbol attribute that controls the linkage and visibility of symbols, affecting how they are exported from or imported into shared libraries.