Replies: 6 comments 16 replies
-
It is not supported by OW compilers for user code. |
Beta Was this translation helpful? Give feedback.
-
OW support only alias for regular symbol. It is not same , but it could help you in some situation. |
Beta Was this translation helpful? Give feedback.
-
I just found a very small OBJ post-processing utility: In our case, it would seem to be quite simple to enhance it to take a symbol name and add a WKEXT record in the same way, thus defining the passed symbol as weak, run as a compiler post-processing tool: Of course, this would be a bit of a kluge but might be quite a bit simpler than introducing a compiler change, and could be done first for testing. What do you think? |
Beta Was this translation helpful? Give feedback.
-
Although having a |
Beta Was this translation helpful? Give feedback.
-
More information about weak symbol support in current Open Watcom linker and C compiler: I went ahead and modified fcenable's (far call optimizer) OBJ manipulation routines to emit a WKREF weak symbol reference for a specified symbol, which now works. This allowed further testing to see how wlink handles weak symbols, both when resolved and left unresolved. For small code models, the result works as expected: the symbol (in the tested case, an external function's address) is indeed set to 0. For large code models, there are some potential problems. Since the C compiler didn't know about the weak symbol, the code generation was identical, but I'm pretty sure the code generated would have to be the same. Before calling a weak function symbol, it must be tested to determine if the function is in fact linked in or not. In large model, the code generated for testing the address of a weak function symbol is:
What happens in the linker is that the value of This can be kind of fixed by just testing the low 16 bits of the function address; but in large model it is possible that if the weak symbol happens to be linked into the first (zero) offset of a new segment, its strong reference offset would also be zero. With the ELKS C library, the first code segment offset zero won't be used, so this would work for programs < 64k code. I am guessing that even with pragma aux weak the C compiler would have to generate a segment reference, as the compiler doesn't know whether the reference will ultimately be resolved weak or strongly by the linker. This means that even with pragma aux weak, the linker probably needs modification to set the segment value of an unresolved weak symbol to zero in order for things to function properly. [EDIT: it is possible the linker is already doing this and there is a non-cancelled FIXUP relocation entry that is causing the segment value to be set from non-zero. I will have to check more carefully to see if that is the reason for this problem.] Another possible fix would be to somehow tell the linker to not place any functions at address zero in any code segment. I haven't found a way to specify or guarantee that with existing commands/options. |
Beta Was this translation helpful? Give feedback.
-
No, it need to use also code generator support to implement it by some #pragma for weak symbols. I looked on IBM compilers |
Beta Was this translation helpful? Give feedback.
-
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
open-watcom-v2/bld/cg/intel/h/x86objd.h
Line 87 in 8eb58ce
IS_SYM_LINK_WEAK
in wl/c/objpass1.c, andWEAK
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!
Beta Was this translation helpful? Give feedback.
All reactions