Re: COB_PRE_LOAD

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



James K. Lowden wrote:
> Is there a static alternative to COB_PRE_LOAD?  
>
> I would like to compile my Cobol program, linked to Cobol libraries,
> without relying on any runtime configuration.  
>
> In C, I can set my library search path with -Wl,-rpath, and name the
> library with -l. 
>
> With cobc, if I use -lfoo, the linker looks for libfoo.  (The
> runtime error message says it can't find "-lfoo", with the flag, which
> is IMO misleading.)  The advice in Appendix H of the Programmer's
> Guide seems to be 
>
> 	export COB_LIBRARY_PATH=x
> 	export COB_PRE_LOAD=foo
> 	[run program]
>
> N.B., the 3.0rc1 version of the Guide I'm looking at, from December
> 2019, has errors in the examples of how to use these variables.  
>
> i would like the user to use the program without requiring runtime
> configuration that is simply a by-product of the fact that the program
> was written in Cobol.  
>
> --jkl
>
Yeah, this gets tricky.  GnuCOBOL is somewhat at the mercy of the link
loader in play, which is a complex topic, always changing, either subtle
or not.

To keep up, we need to wrap user entered '-L -l' options in the
--no-as-needed linker flag, for one.  Some distros have ld setup to
eliminate code not mentioned in any objects.  Lookup by string at
run-time does not count, it has to be a symbol lookup by the compile
time toolchain.

I sledge hammer my Ubuntu boxes with an export add to COB_LDFLAGS='-Wl,
--no-as-needed'.  Fedora has not (yet) made as-needed link time
elimination a default. And on and on with the subtleties of compile time
and runtime ld.so.

Often times a -L path -l name will not take in cobc generated code, the
internal rpath does not include the names, eliminated by the linker. 
Ubuntu folk like to say it's programmers with sloppy build systems, but
those young un's that made the change seemed to have missed translated
code with indirect string look up at run time as an existent use case. 
Took many months to figure out where that breakage was coming from, and
many thanks to a stranger on StackOverflow. As stated, we need to wrap
user entered options in some flags when generating commands for the cobc
tool chain to be "less sloppy".

There *is* LD_RUN_PATH at compile time to force set the internal rpath
in ELF binaries. 
https://open-cobol.sourceforge.io/faq/index.html#how-do-i-use-ld-run-path-with-gnucobol
similar to -Wl,rpath (if not identical).

But that then puts binaries at risk of moving files to new path names,
requiring a recompile or hacky symlinks.

Other experiments to try and make things a little more sane, is -A and
-Q to send the C options down the line for -Wl, rpath and other
overrides, until you find a sweet spot.

The POSIX link loader and complications of POSIX link assumptions on top
of say Windows or differences with Apples, makes for a head scratching,
but doable, experience, given enough platform specific knowledge and
binging on google.

50 internet points to the first person to amass enough know how to cover
all the bases needed by cobc on all the platforms and can tweak cobc.c
to suit.  :-)

Have good,
Blue







[Index of Archives]     [Gcc Help]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Info]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux