EXTERNAL data item visibility shift when moving from ANSI COBOL 85 to COBOL 2002 with IBM Enterprise COBOL V6 linker options
0 reputation · 28 Nov 2020, 00:51 UTC
0 reputation · 28 Nov 2020, 00:51 UTC
The goal is to understand whether EXTERNAL data items become publicly accessible across separately loaded modules when upgrading from legacy COBOL to newer compiler versions that modify linkage behavior.
Constraints include the differing definitions of EXTERNAL in ANSI COBOL 85 versus COBOL 2002, the IBM Enterprise COBOL V6 THREAD and NOEXTERNAL linker options, and the Micro Focus Visual COBOL –fexternaldll flag, which each affect how symbols are placed in the process address space.
Uncertainty remains about whether omitting NOEXTERNAL or enabling THREAD places EXTERNAL items in a shared segment visible to any COBOL or non‑COBOL code in the same process, and whether the Micro Focus flag changes this exposure.
Does enabling the THREAD option or omitting NOEXTERNAL cause EXTERNAL items to be placed in a shared segment accessible to any module in the same process? Does the Micro Focus –fexternaldll flag alter this behavior? How can developers verify the visibility of EXTERNAL items after a version upgrade without introducing test harnesses?
35275 reputation · 28 Nov 2020, 09:07 UTC
Enabling the THREAD option or omitting NOEXTERNAL (the default) causes IBM Enterprise COBOL V6 to place EXTERNAL data items in a common external data section that is shared across all load modules in the same process, making them visible to any COBOL or non‑COBOL code that can resolve the symbol. Specifying NOEXTERNAL or omitting THREAD keeps the items in a module‑private segment, so they are not automatically visible elsewhere. The Micro Focus Visual COBOL flag –fexternaldll overrides this behavior by emitting the EXTERNAL items as exported symbols from a DLL; any module that links against that DLL can access them, regardless of the IBM THREAD/NOEXTERNAL settings.
The shift occurs because the COBOL 2002 standard clarified that EXTERNAL items may be placed in a common external data area when the linker is instructed to do so. IBM’s V6 implementation honors this via the THREAD/NOEXTERNAL options. Without those options, the legacy behavior (private segment) is preserved. The Micro Focus flag bypasses the IBM linker semantics entirely by treating EXTERNAL items as DLL exports, which changes the visibility model to a DLL‑based import/export mechanism.
IDENTIFICATION DIVISION.
PROGRAM-ID. DEFINE-EXT.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 GLOBAL-ITEM EXTERNAL PIC S9(9) COMP VALUE 0.
PROCEDURE DIVISION.
STOP RUN.
IDENTIFICATION DIVISION.
PROGRAM-ID. USE-EXT.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 GLOBAL-ITEM EXTERNAL PIC S9(9) COMP.
PROCEDURE DIVISION.
DISPLAY GLOBAL-ITEM.
STOP RUN.
cob2 -x -qthread (or omit NOEXTERNAL)
- For private visibility: cob2 -x -qnoexternal
(Adjust command syntax to your environment.)dumpbin /exports <exe> or dumpbin /headers <exe> and look for GLOBAL-ITEM in the export table or in the section flags.
- On AIX/Linux: run nm -C <exe> or objdump -t <exe> and check whether the symbol appears in a shared section (e.g., .data, .bss) with global binding.
-fexternaldll, then check the produced DLL’s export table with the same tools; the EXTERNAL item should appear as an exported symbol.Missing diagnostic detail: Are you targeting Windows, AIX, or Linux? Knowing the platform determines whether to use dumpbin or nm/objdump for verification, which may affect the exact command you need to run.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.