x86-64 - Use of <chrono> functions causes linker warnings and program crash

Post Reply

Topic author
dmccorm1
Contributor
Posts: 15
Joined: Fri Apr 14, 2023 4:33 pm
Reputation: 0
Status: Offline

x86-64 - Use of <chrono> functions causes linker warnings and program crash

Post by dmccorm1 » Fri Apr 28, 2023 6:32 pm

I've been testing out the C++17 support in the Clang compiler and I'm really impressed. It's very cool indeed to have modern C++ on VMS. The only wrinkle I've seen so far is with the <chrono> header. Output of a session below. I'm thinking this might be related to the mention in the readme about long double not yet being fully supported?

Also, and apologies if this is VMS noob question, but how does the linker successfully create my sleep.exe program when there are undefined symbols? The linker messages are just warnings rather than errors.

Code: Select all

$ type sleep.cpp
#include <chrono>
using namespace std::chrono_literals;
#include <thread>

int main()
{
    std::this_thread::sleep_for(1s);
    return 0;
}
$ clang -std=c++17 sleep.cpp
$ link sleep
%ILINK-W-NUDFSYMS, 2 undefined symbols:
%ILINK-I-UDFSYM, 	__floatditf 
%ILINK-I-UDFSYM, 	__lttf2 
%ILINK-W-USEUNDEF, undefined symbol __lttf2 referenced
	section: .text._ZNKSt3__16chrono13__duration_ltINS0_8durationIxNS_5ratioILx1ELx1EEEEENS2_IgS4_EEEclERKS5_RKS6_
	offset: %X00000000000000AF
	module: SLEEP 
	file: USERS:[DMCCORM1]SLEEP.OBJ;3 
%ILINK-W-USEUNDEF, undefined symbol __floatditf referenced
	section: .text._ZNKSt3__16chrono15__duration_castINS0_8durationIxNS_5ratioILx1ELx1EEEEENS2_IgS4_EES4_Lb1ELb1EEclERKS5_
	offset: %X000000000000002C
	module: SLEEP 
	file: USERS:[DMCCORM1]SLEEP.OBJ;3 
$ r sleep
%SYSTEM-F-CALLUNDEFSYM, Call using undefined function symbol

  Improperly handled condition, image exit forced by last chance handler.
    Signal arguments:   Number = 0000000000000003
                        Name   = 0000000000003434
                                 0000000080000978
                                 000000000000001B
    Register dump:
    RAX = 0000000000000001  RDI = 0000000000100001  RSI = 0000000000003434
    RDX = 0000000000000001  RCX = 0000000000000001  R8  = 0000000000000003
    R9  = 0000000000000010  RBX = 000000007ACE7F00  RBP = 000000007ACE3390
    R10 = 0000000000000022  R11 = 000000007ACE3180  R12 = 000000007ACE79A8
    R13 = 0000000000000000  R14 = 0000000000000003  R15 = 0000000106084606
    RIP = 0000000080000978  RSP = 000000007ACE3348  SS  = 000000000000001B
$


sms
Master
Posts: 317
Joined: Fri Aug 21, 2020 5:18 pm
Reputation: 0
Status: Offline

Re: x86-64 - Use of <chrono> functions causes linker warnings and program crash

Post by sms » Fri Apr 28, 2023 7:09 pm

Code: Select all

> [...] how does the linker successfully create my sleep.exe program
> when there are undefined symbols? [...]

   It's easy to fill in zeros (or some other invalid value) when you
don't have a real address.  You can expect a run-time failure if the
program tries to call a missing function.

> $ r sleep
> %SYSTEM-F-CALLUNDEFSYM, Call using undefined function symbol

   Like that, for example.  Or, in the old days (VAX, for example):

wisp $ r undef
%SYSTEM-F-ACCVIO, access violation, reason mask=00, virtual address=00000000, PC=00000219, PSL=03C00004
%TRACE-F-TRACEBACK, symbolic stack dump follows
module name     routine name                     line       rel PC    abs PC

UNDEF           main                              918      00000019  00000219

   SYSTEM-F-ACCVIO with "virtual address=00000000" was the telltale
signature before this mollycoddling SYSTEM-F-CALLUNDEFSYM stuff came
along.


Topic author
dmccorm1
Contributor
Posts: 15
Joined: Fri Apr 14, 2023 4:33 pm
Reputation: 0
Status: Offline

Re: x86-64 - Use of <chrono> functions causes linker warnings and program crash

Post by dmccorm1 » Sun Apr 30, 2023 8:30 am

Thanks. Just to clarify, I wasn't literally asking "how" the linker created my program. I appreciate that it can just write invalid addresses for undefined symbols. I guess what I was really questioning is why it bothered to create a program that can't possibly run. If you try the equivalent on Linux, Windows, Mac, etc. you'll get a linker error (example below). I'm just wondering if this is the expected behaviour for the VMS linker or is this a defect?

Code: Select all

[~] $ cat undef.cpp 
#include <cstdio>

int ThisFunctionIsntDefined();

int main()
{
    std::printf("%d\n", ThisFunctionIsntDefined());
    return 0;
}
[~] $ g++ -c undef.cpp
[~] $ g++ -o undef undef.o
/usr/bin/ld: /tmp/cczaJO72.o: in function `main':
undef.cpp:(.text+0x5): undefined reference to `ThisFunctionIsntDefined()'
collect2: error: ld returned 1 exit status
[~] $ ls undef
ls: cannot access 'undef': No such file or directory

User avatar

arne_v
Master
Posts: 308
Joined: Fri Apr 17, 2020 7:31 pm
Reputation: 0
Location: Rhode Island, USA
Status: Offline
Contact:

Re: x86-64 - Use of <chrono> functions causes linker warnings and program crash

Post by arne_v » Sun Apr 30, 2023 8:44 am

The program will run fine if you don't call one of the missing functions.

Regarding bug or feature then I believe it has always worked that way on VMS.
Arne
arne@vajhoej.dk
VMS user since 1986


Topic author
dmccorm1
Contributor
Posts: 15
Joined: Fri Apr 14, 2023 4:33 pm
Reputation: 0
Status: Offline

Re: x86-64 - Use of <chrono> functions causes linker warnings and program crash

Post by dmccorm1 » Sun Apr 30, 2023 4:34 pm

Interesting. Thanks.


jreagan
VSI Expert
Master
Posts: 135
Joined: Tue Dec 01, 2020 8:40 am
Reputation: 0
Status: Offline

Re: x86-64 - Use of <chrono> functions causes linker warnings and program crash

Post by jreagan » Fri May 05, 2023 4:35 pm

Not all of those C++17 packages are built properly. Stick to C++11 and C++14 for now. Those new C++17 packages are on our list.

Post Reply