Skip to content

Commit 253e5cc

Browse files
committed
Merge remote-tracking branch 'upstream/gnucobol-3.x' into gitside-gnucobol-3.x
2 parents 3457bd5 + 50b58f6 commit 253e5cc

File tree

12 files changed

+445
-29
lines changed

12 files changed

+445
-29
lines changed

NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ NEWS - user visible changes -*- outline -*-
133133
$b for executable basename, $d for date in YYYYMMDD format, $t for time
134134
in HHMMSS format (before, only $$ was available for pid)
135135

136+
** Introduction of the COB_LOAD_GLOBAL boolean flag, which determines whether
137+
the symbols of dynamically loaded shared libraries are made available
138+
globally to other shared objects or remain confined locally. Previously,
139+
this behavior depended on the underlying platform, where the default was
140+
often "global." The default behavior is now explicitly set to "local".
141+
136142
* New build features
137143

138144
** configure now uses pkg-config/ncurses-config to search for ncurses and

cobc/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11

2+
2025-12-29 Roger Bowler <rbowler@snipix.net>
3+
4+
* tree.c (finalize_file): if file is EXTFH enabled then don't warn for
5+
ORGANIZATION INDEXED, even when compiler is configured --without-db
6+
27
2025-12-04 Roger Bowler <rbowler@snipix.net>
38

49
* parser.y (entry): check that ENTRY statement begins in area B not area A

cobc/tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5033,7 +5033,7 @@ finalize_file (struct cb_file *f, struct cb_field *records)
50335033
#if !defined (WITH_INDEX_EXTFH) && \
50345034
!defined (WITH_DB) && \
50355035
!defined (WITH_CISAM) && !defined(WITH_DISAM) && !defined(WITH_VBISAM)
5036-
if (f->organization == COB_ORG_INDEXED) {
5036+
if (f->organization == COB_ORG_INDEXED && !f->extfh) {
50375037
char msg[80];
50385038
snprintf (msg, sizeof (msg), "ORGANIZATION INDEXED; FD %s", f->name);
50395039
cb_warning_x (cb_warn_unsupported, f->description_entry,

config/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
* gcos-strict.conf: set init-justify to no after testing on GCOS
1515

16+
2024-12-16 Simon Sobisch <simonsobisch@gnu.org>
17+
18+
* config/runtime.cfg: add COB_LOAD_GLOBAL
19+
1620
2024-08-17 Ammar Almoris <ammaralmorsi@gmail.com>
1721

1822
FR #474: add runtime configuration to hide cursor for extended screenio

config/runtime.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,19 @@
323323
# Default: false
324324
# Example: PHYSICAL_CANCEL TRUE
325325

326+
# Environment name: COB_LOAD_GLOBAL
327+
# Parameter name: load_global
328+
# Purpose: tell the system loader to provide symbols in CALLed
329+
# programs globally, allowing symbols to be found for linked
330+
# libraries later
331+
# Type: boolean
332+
# Note: COBOL CALLs will always find symbols in already CALLed or
333+
# pre-loaded modules; this setting is mostly an advise to the
334+
# system, not all systems are capable of loading libraries
335+
# global/local
336+
# Default: false
337+
# Example: load_global true
338+
326339
#
327340
## File I/O
328341
#

libcob/ChangeLog

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,18 @@
206206
* common.h, common.c: handle [__xlc__] identical to [__IBMC__]
207207
* common.c [!SIGPIPE]: fix warning about unused jump
208208

209+
2025-01-08 Florian Schmidt <florian.schmidt.1994@icloud.com>
210+
Simon Sobisch <simonsobisch@gnu.org>
211+
212+
* call.c (cob_dlopen): new function used instead of partially re-defining
213+
lt_dlopen; changed default to not load symbols to the global namespace
214+
any more but locally (was always the case for _WIN32)
215+
* common.c, coblocal.h (cob_settings): added boolean COB_LOAD_GLOBAL
216+
to toggle into which namespace the symbols of CALLed programs should be
217+
made available
218+
* call.c (cob_dlopen, add_to_preload, cache_preload, cob_exit_call):
219+
handle COB_LOAD_GLOBAL (load_global)
220+
209221
2024-12-31 Simon Sobisch <simonsobisch@gnu.org>
210222

211223
* common.c [WITH_EXTENDED_SCREENIO]: adjusted curses includes/defines

libcob/call.c

Lines changed: 84 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,6 @@ FILE *fmemopen (void *buf, size_t size, const char *mode);
6666
#include <windows.h>
6767
#include <io.h> /* for access */
6868

69-
static HMODULE
70-
lt_dlopen (const char *x)
71-
{
72-
if (x == NULL) {
73-
return GetModuleHandle (NULL);
74-
}
75-
return LoadLibrary(x);
76-
}
77-
7869
static void *
7970
lt_dlsym (HMODULE hmod, const char *p)
8071
{
@@ -106,7 +97,6 @@ lt_dlerror (void)
10697
/* note: only defined in configure when HAVE_DLFCN_H is true and dlopen can be linked */
10798
#include <dlfcn.h>
10899

109-
#define lt_dlopen(x) dlopen(x, RTLD_LAZY | RTLD_GLOBAL)
110100
#define lt_dlsym(x,y) dlsym(x, y)
111101
#define lt_dlclose(x) dlclose(x)
112102
#define lt_dlerror() dlerror()
@@ -171,6 +161,10 @@ static char *call_filename_buff;
171161
static lt_dlhandle mainhandle;
172162
#endif
173163

164+
#if !defined(_WIN32) && !defined(USE_LIBDL)
165+
static lt_dladvise advise = NULL;
166+
#endif
167+
174168
static size_t call_lastsize;
175169
static size_t resolve_size = 0;
176170
static unsigned int cob_jmp_primed;
@@ -279,7 +273,8 @@ set_resolve_error (int module_type)
279273
}
280274
}
281275

282-
static int last_entry_is_working_directory (const char *buff, const char *pstr)
276+
static int
277+
last_entry_is_working_directory (const char *buff, const char *pstr)
283278
{
284279
const size_t pos = pstr - buff; /* always > 2 */
285280
if (buff[pos - 1] == '.'
@@ -289,6 +284,44 @@ static int last_entry_is_working_directory (const char *buff, const char *pstr)
289284
return 0;
290285
}
291286

287+
static void*
288+
cob_dlopen (const char* filename)
289+
{
290+
#if defined (_WIN32)
291+
if (filename == NULL) {
292+
return GetModuleHandle (NULL);
293+
}
294+
return LoadLibrary (filename);
295+
#elif defined(USE_LIBDL)
296+
const int flags = cobsetptr->cob_load_global
297+
? RTLD_LAZY | RTLD_GLOBAL
298+
: RTLD_LAZY | RTLD_LOCAL;
299+
300+
return dlopen (filename, flags);
301+
#else
302+
if (advise != NULL) {
303+
static int last_cob_load_global = -1;
304+
305+
if (cobsetptr->cob_load_global != last_cob_load_global) {
306+
int error;
307+
last_cob_load_global = cobsetptr->cob_load_global
308+
309+
if (cobsetptr->cob_load_global) {
310+
error = lt_dladvise_global (&advise);
311+
} else {
312+
error = lt_dladvise_local (&advise);
313+
}
314+
315+
if (error) {
316+
cob_runtime_warning ("set link loader hint failed; %s", lt_dlerror());
317+
}
318+
}
319+
}
320+
321+
return lt_dlopenadvise (filename, advise);
322+
#endif
323+
}
324+
292325
/* resolves the actual library path used from
293326
* COB_LIBRARY_PATH runtime setting
294327
* "." as current working direktory [if not included already: prefixed]
@@ -555,9 +588,20 @@ add_to_preload (const char *path, lt_dlhandle libhandle, struct struct_handle *l
555588
base_preload_ptr = preptr;
556589
}
557590
#else
558-
COB_UNUSED (last_elem);
559-
preptr->next = base_preload_ptr;
560-
base_preload_ptr = preptr;
591+
/* Use the same logic as above in case the cob_load_global is set to local */
592+
if (!cobsetptr->cob_load_global) {
593+
if (last_elem) {
594+
last_elem->next = preptr;
595+
} else {
596+
preptr->next = NULL;
597+
base_preload_ptr = preptr;
598+
}
599+
} else {
600+
COB_UNUSED (last_elem);
601+
preptr->next = base_preload_ptr;
602+
base_preload_ptr = preptr;
603+
}
604+
561605
#endif
562606

563607
if (!cobsetptr->cob_preload_str) {
@@ -595,6 +639,9 @@ cache_preload (const char *path)
595639
/* Save last element of preload list */
596640
if (!preptr->next) last_elem = preptr;
597641
#endif
642+
if (!cobsetptr->cob_load_global) {
643+
if (!preptr->next) last_elem = preptr;
644+
}
598645
}
599646

600647
/* Check for duplicate in already loaded programs;
@@ -624,7 +671,7 @@ cache_preload (const char *path)
624671
return 0;
625672
}
626673

627-
libhandle = lt_dlopen (path);
674+
libhandle = cob_dlopen (path);
628675
if (!libhandle) {
629676
cob_runtime_warning (
630677
_("preloading from existing path '%s' failed; %s"), path, lt_dlerror());
@@ -854,7 +901,7 @@ cob_resolve_internal (const char *name, const char *dirent,
854901
}
855902

856903
#if 0 /* RXWRXW RTLD */
857-
#if defined(USE_LIBDL) && defined (RTLD_DEFAULT)
904+
#if defined(USE_LIBDL) && defined(RTLD_DEFAULT)
858905
func = lt_dlsym (RTLD_DEFAULT, call_entry_buff);
859906
if (func != NULL) {
860907
insert (name, func, NULL, NULL, NULL, 1);
@@ -870,7 +917,7 @@ cob_resolve_internal (const char *name, const char *dirent,
870917
for (p = call_filename_buff; *p; ++p) {
871918
*p = (cob_u8_t)toupper(*p);
872919
}
873-
handle = lt_dlopen (call_filename_buff);
920+
handle = cob_dlopen (call_filename_buff);
874921
if (handle != NULL) {
875922
/* Candidate for future calls */
876923
cache_dynload (call_filename_buff, handle);
@@ -913,7 +960,7 @@ cob_resolve_internal (const char *name, const char *dirent,
913960
return NULL;
914961
}
915962
lt_dlerror (); /* clear last error conditions */
916-
handle = lt_dlopen (call_filename_buff);
963+
handle = cob_dlopen (call_filename_buff);
917964
if (handle != NULL) {
918965
/* Candidate for future calls */
919966
cache_dynload (call_filename_buff, handle);
@@ -946,7 +993,7 @@ cob_resolve_internal (const char *name, const char *dirent,
946993
call_filename_buff[COB_NORMAL_MAX] = 0;
947994
if (access (call_filename_buff, R_OK) == 0) {
948995
lt_dlerror (); /* clear last error conditions */
949-
handle = lt_dlopen (call_filename_buff);
996+
handle = cob_dlopen (call_filename_buff);
950997
if (handle != NULL) {
951998
/* Candidate for future calls */
952999
cache_dynload (call_filename_buff, handle);
@@ -1706,6 +1753,15 @@ cob_exit_call (void)
17061753
#endif
17071754
#endif
17081755

1756+
#if !defined(_WIN32) && !defined(USE_LIBDL)
1757+
if (advise != NULL) {
1758+
if (lt_dladvise_destroy (&advise)) {
1759+
/* not translated as highly unlikely */
1760+
cob_runtime_warning (
1761+
"destroying link loader advise failed; %s", lt_dlerror ());
1762+
}
1763+
}
1764+
#endif
17091765
}
17101766

17111767
/* try to load specified module from all entries in COB_LIBRARY_PATH
@@ -1793,12 +1849,20 @@ cob_init_call (cob_global *lptr, cob_settings* sptr, const int check_mainhandle)
17931849

17941850
lt_dlinit ();
17951851

1852+
#if !defined(_WIN32) && !defined(USE_LIBDL)
1853+
if (lt_dladvise_init (&advise) != 0) {
1854+
/* not translated as highly unlikely */
1855+
cob_runtime_warning (
1856+
"init link loader advise failed; %s", lt_dlerror ());
1857+
}
1858+
#endif
1859+
17961860
#ifndef COB_BORKED_DLOPEN
17971861
/* only set main handle if not started by cobcrun as this
17981862
saves a check for exported functions in every CALL
17991863
*/
18001864
if (check_mainhandle) {
1801-
mainhandle = lt_dlopen (NULL);
1865+
mainhandle = cob_dlopen (NULL);
18021866
} else {
18031867
mainhandle = NULL;
18041868
}

libcob/coblocal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ typedef struct __cob_settings {
306306

307307
/* call.c */
308308
int cob_physical_cancel; /* 0 "= "logical only" (default), 1 "also unload", -1 "never unload" */
309+
unsigned int cob_load_global; /* hint for dynamic linker to make symbols available 0=global, 1=local */
309310
unsigned int name_convert;
310311
char *cob_preload_str;
311312
char *cob_library_path;

libcob/common.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,9 @@ static struct config_tbl gc_conf[] = {
549549
{"LOGICAL_CANCELS", "logical_cancels", NULL, NULL, GRP_HIDE, ENV_BOOL | ENV_NOT, SETPOS (cob_physical_cancel)},
550550
{"COB_LIBRARY_PATH", "library_path", NULL, NULL, GRP_CALL, ENV_PATH, SETPOS (cob_library_path)}, /* default value set in cob_init_call() */
551551
{"COB_PRE_LOAD", "pre_load", NULL, NULL, GRP_CALL, ENV_STR, SETPOS (cob_preload_str)},
552+
#ifndef _WIN32
553+
{"COB_LOAD_GLOBAL", "load_global", "0", NULL, GRP_CALL, ENV_BOOL, SETPOS(cob_load_global)},
554+
#endif
552555
{"COB_BELL", "bell", "0", beepopts, GRP_SCREEN, ENV_UINT | ENV_ENUMVAL, SETPOS (cob_beep_value)},
553556
{"COB_DEBUG_LOG", "debug_log", NULL, NULL, GRP_HIDE, ENV_FILE, SETPOS (cob_debug_log)},
554557
{"COB_DISABLE_WARNINGS", "disable_warnings", "0", NULL, GRP_MISC, ENV_BOOL | ENV_NOT, SETPOS (cob_display_warn)},

0 commit comments

Comments
 (0)