Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for weak or lazy symbols #1324

Open
jmalak opened this issue Aug 15, 2024 Discussed in #1323 · 1 comment
Open

Support for weak or lazy symbols #1324

jmalak opened this issue Aug 15, 2024 Discussed in #1323 · 1 comment

Comments

@jmalak
Copy link
Member

jmalak commented Aug 15, 2024

Discussed in #1323

Originally posted by ghaerr August 14, 2024
Hello @jmalak,

I have a need to mark a symbol such that, when linking, other libraries will not normally be searched to find and pull in the referenced symbol unless the symbol has already been defined in object files already committed to being linked. In GCC, this is known as weak symbols, and can be specified using the GCC __attribute__((__weak__)) extension.

Can the OpenWatcom linker support weak symbols? I can't seem to find any direct documentation on it, although by looking at the OW source, I see that OBJ EXTRN comment records are apparently used (for import) to specify weak and lazy symbol attributes. (See

#define WEAK_EXTRN_COMMENT CMT_NP( WKEXT )
as well as IS_SYM_LINK_WEAK in wl/c/objpass1.c, and WEAK in many more places).

There is also some documentation identified on google but which I cannot find the full manual for, saying "Open Watcom Linker User's Guide ... The "EXPORT" directive is used to tell the Open Watcom Linker which symbols are available for import ... A lazy external reference is one which has two" but when I folllow the link I can't find the referenced text. So possibly there is a way to use the EXPORT or IMPORT directives to specify a weak symbol, rather than C source.

My requirement to use weak symbols is for optionally including various routines only when needed in the ELKS C Library, e.g. for including another function printf might call to perform float-to-string display only when floats are used, etc.

Can you point me into the right direction for how to take advantage of this possible internal capability in OpenWatcom?

Thank you!

@jmalak
Copy link
Member Author

jmalak commented Aug 15, 2024

It is not supported by OW compilers for user code.
It is used internally by code generator for common block (fortran) or for C++ code I think. May be other reason.
The linker is fully capable to process it, but you cannot define it in linker. It must be defined in generated code (in modules) for real code.
But use of it can be danger and it is not required for current user code.
We can do it as extension but it needs review of OW code.
Probably we could extend #pragma aux for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant