From bbfb69ed8d4f7adb7b37dad752c58edba5e62c36 Mon Sep 17 00:00:00 2001 From: Till Straumann Date: Thu, 18 Sep 2014 12:19:47 -0700 Subject: [PATCH] - implemented suggestion by Michael Davidsaver: when reading ELF files check modifification time against program start time and warn if the file was modified more recently since it could be out of date. --- src/libCom/osi/os/posix/osdElfFindAddr.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/libCom/osi/os/posix/osdElfFindAddr.cpp b/src/libCom/osi/os/posix/osdElfFindAddr.cpp index 518b55a51..4f7d38f0d 100644 --- a/src/libCom/osi/os/posix/osdElfFindAddr.cpp +++ b/src/libCom/osi/os/posix/osdElfFindAddr.cpp @@ -24,6 +24,9 @@ #include #include #include +#include +#include +#include #ifdef _POSIX_MAPPED_FILES #include @@ -112,6 +115,18 @@ static ESyms elfs = 0; static epicsMutexId listMtx; static epicsThreadOnceId listMtxInitId = EPICS_THREAD_ONCE_INIT; +static time_t getStartTime() +{ +struct timespec ts; + + if ( clock_gettime(CLOCK_REALTIME, &ts) ) + return (time_t)0; + + return ts.tv_sec; +} + +static time_t prog_start_time = getStartTime(); + static void listMtxInit(void *unused) { listMtx = epicsMutexMustCreate(); @@ -350,6 +365,12 @@ struct stat stat_b; } n -= EI_NIDENT; + if ( 0 == fstat(es->fd, &stat_b) ) { + if ( stat_b.st_mtime > prog_start_time ) { + errlogPrintf("elfRead() -- WARNING: '%s' was modified after program start -- symbol information may be inaccurate or invalid\n", fname); + } + } + /* read rest */ if ( n != do_read(es->fd, ehdr.e32.e_ident + EI_NIDENT, n) ) { errlogPrintf("elfRead() -- unable to read ELF ehdr: %s\n", strerror(errno));