[Info-vax] OpenVMS Alpha C++ Compiler Bug
RobertsonEricW
robertsonericw at netzero.net
Wed Sep 10 13:24:10 EDT 2014
While porting the cmake project to OpenVMS (the first Open Source C++ project that I have had to deal with porting thus far), I came across what appears to be an odd bug in the OpenVMS Alpha C++ V7.3-009 compiler (which as far as I am aware is the latest version available from HP). This bug is apparently specific to the OpenVMS Alpha C++ compiler as compiling using the OpenVMS IA64 C++ V 7.4-005 compiler does not produce the manifestation of the bug. This bug cropped up incidentally to the porting effort because I was porting over the vms_crtl_init.c module used in Bash so that it could be consumed by the OpenVMS C++ compiler to achieve the same logical end as in Bash; namely, to invoke an application specific CRTL initialization function prior to the invocation of the "main" function using the OpenVMS mechanism exposed through LIB$INITIALIZE. Sadly, because of earlier statements from HP with respect to the Alpha compilers in particular, this bug is unlikely to be fixed and so it will remain for the forseeable future.
So, all you retro OpenVMS Alpha C++ users might want to mark this information down for future reference in case you should come across it. The bug appears to be related to simultaneous use of the #pragma extern_model statement in the source and the use of the /DEBUG qualifier within the CXX compiler command line. Specifically the following sequence of source code reveals the bug:
static void sfunc ( void )
{
return;
}
#pragma nostandard
#pragma extern_model save
#ifdef __VAX
#pragma extern_model strict_refdef "LIB$INITIALIZE" nowrt, long, nopic
#else
#pragma extern_model strict_refdef "LIB$INITIALIZE" nowrt, long
# if __INITIAL_POINTER_SIZE
# pragma __pointer_size __save
# pragma __pointer_size 32
# else
# pragma __required_pointer_size __save
# pragma __required_pointer_size 32
# endif
#endif
/* Set our contribution to the LIB$INITIALIZE array */
static void (* const iniarray[])(void) = {sfunc, } ;
#ifndef __VAX
# if __INITIAL_POINTER_SIZE
# pragma __pointer_size __restore
# else
# pragma __required_pointer_size __restore
# endif
#endif
/*
** Force a reference to LIB$INITIALIZE to ensure it
** exists in the image.
*/
#ifdef __cplusplus
extern "C"
{
#endif
int LIB$INITIALIZE(void);
#if defined(__DECC) || defined (__DECCXX)
#pragma extern_model strict_refdef
#endif
int lib_init_ref = (int) LIB$INITIALIZE;
#if defined(__DECC) || defined(__DECCXX)
#pragma extern_model restore
#pragma standard
#endif
#ifdef __cplusplus
}
#endif
int main(int argc, char *argv[])
{
return 1;
}
When placing the above code into the file cxx_lib$initialize.cxx the following unexpected result is produced.
$ cxx/version
HP C++ V7.3-009 for OpenVMS Alpha V8.3
$ cxx/NOOPT cxx_lib$initialize.cxx
$ cxxlink/debug cxx_lib$initialize
$ cxx/NOOPT/DEBUG cxx_lib$initialize.cxx
$ cxxlink/debug cxx_lib$initialize
%LINK-W-NUDFSYMS, 1 undefined symbol:
%LINK-I-UDFSYM, sfunc__xv
%LINK-W-USEUNDEF, undefined symbol sfunc__xv referenced
in psect $LINK$ offset %X00000000
in module cxx_lib$initialize file DISK_USERS:[usr.robertson.OpenSourceProjects.Test]cxx_lib$initialize.OBJ;2
The use of the /DEBUG qualifier (which is the only difference between the above pairings of compile and link command sequences) should not logically alter the necessity of any symbols defined within the application itself. Hence their should not be any application defined symbols that are unresolved when using the /DEBUG qualifier that are not also unresolved without it. Use of the /NOOPT in both cases would imply that this confusion is likely not contributed though code optimization of any kind. Unfortunately, the only resolution I could come to was to remove the "static" specifier for sfunc. This is not the best of workarounds because removing the "static" specifier changes the linkage of the sfunc symbol from internal to globally external. Which for the particular purpose of defining the initialization function to be invoked through LIB$INITIALIZE, is not generally desirable.
More information about the Info-vax
mailing list