cobol: Repair COBOL EXTERNAL data definition.
Fixes COBOL EXTERNAL data definitions by aligning them with Fortran COMMON, resolving linking issues with C modules.
This commit corrects how COBOL’s EXTERNAL data definitions are handled, bringing them in line with Fortran’s COMMON data behavior. Previously, these were mistakenly treated as C global variables, causing linking problems. The fix now uses DECL_WEAK references for metadata and DECL_COMMON for data areas, enabling correct interoperability with C modules and proper runtime behavior for EXTERNAL data.
In Details
The COBOL frontend previously mishandled EXTERNAL data items, treating them as C global variables (implicitly with external linkage) rather than the intended equivalent of Fortran's COMMON. This commit rectifies this by marking the runtime metadata variable with DECL_WEAK and the data area itself with DECL_COMMON. This ensures that EXTERNAL data can be shared across compilation units correctly, mirroring Fortran COMMON semantics and improving C interoperability by allowing external C declarations to refer to the same memory region.
- EXTERNAL clause
- A COBOL clause that defines data items shared between compilation units, similar in concept to Fortran's COMMON statement.
- Fortran COMMON
- A Fortran construct that allows named blocks of memory to be shared between different program units (subroutines, functions, main program), acting as a form of global data.
- DECL_WEAK
- An internal GCC attribute marking a symbol as weak, meaning it can be overridden by a non-weak symbol of the same name during linking. Used here for runtime metadata.
- DECL_COMMON
- An internal GCC attribute applied to data symbols that are in the common symbol table. Multiple definitions of common symbols result in a single definition at link time, with the largest size taking precedence. Used here for the data area of EXTERNAL variables.
- vs_global
- An internal enum value within the GCC COBOL frontend representing a global variable scope.
- vs_external
- An internal enum value within the GCC COBOL frontend representing an external variable scope, previously misused for EXTERNAL data.