Reputation: 1
I am writing a piece of code in kernel, which can get the time stamp of other binaries. By timestamp, I mean the time of compilation of the binary.
Is there some way to get this information?
The time stamp is available in user space when we do ls -l. So ideally it should be embedded some where in the elf file. How can i get this piece of information?
Thanks in advance.
-Gomathi
Upvotes: 0
Views: 1795
Reputation: 1
The compilation time of a binary is not available (unless it is coded in C or C++ and use the __DATE__
and __TIME__
predefined preprocessor macros).
AFAIK, the ELF specification does not store any timestamps by default (and if it did, it could be strip
-ed).
What ls -l
(and also the stat(1) command) gives you is some metadata (kept by the file system) given by the stat(2) syscall; you probably want the st_mtime
(or st_mtim
as a timespec
) field, giving the last modification time of a file. But for instance, a cp
of an ELF file would give the current time as st_mtime
to the new copy.
But the st_mtime
field for an ELF executable is the time the linker (or something else, like cp
) wrote that executable (so it is more related to the link time than to the compile time).
To retrieve it in kernel land, look inside the kernel inode of the executable file (in the VFS probably)
You did not state your real goals, but I guess they can (and should) be done in user-land (look into acct(2) & inotify(7)...). Avoid patching the kernel for such things.
Upvotes: 3