Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 126520 - atftp uses obsolete CLK_TCK that has been removed from glibc-2.4
Summary: atftp uses obsolete CLK_TCK that has been removed from glibc-2.4
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Robin Johnson
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-17 04:59 UTC by Olliver Schinagl
Modified: 2006-05-26 14:47 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
replace CLK_TCK with CLOCKS_PER_SEC (atftp-0.7-clk_tck_obsolete_marco.patch,647 bytes, patch)
2006-03-17 05:02 UTC, Olliver Schinagl
Details | Diff
Patch that uses sysconf(_SC_CLK_TCK) as a replacement (atftp-0.7-clk_tck.patch,826 bytes, patch)
2006-03-17 06:34 UTC, Sylvain Munaut
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Olliver Schinagl 2006-03-17 04:59:47 UTC
Just doing an emerge -ve world to find out atftp uses an old CLK_TCK macro. Attached find a patch to fix this. It should be backwards compatible, I only compiled it with atftp-0.7 however
Comment 1 Olliver Schinagl 2006-03-17 05:02:27 UTC
Created attachment 82361 [details, diff]
replace CLK_TCK with CLOCKS_PER_SEC

just add this epatch and all should be well again. I think it's backwards compatible with somewhat older glibc's as this has been obsoleted a while ago.
Comment 2 Sylvain Munaut 2006-03-17 06:34:04 UTC
Created attachment 82371 [details, diff]
Patch that uses sysconf(_SC_CLK_TCK) as a replacement
Comment 3 Sylvain Munaut 2006-03-17 06:35:23 UTC
Comment on attachment 82371 [details, diff]
Patch that uses sysconf(_SC_CLK_TCK) as a replacement

CLOCKS_PER_SEC is not the same as CLK_TCK I think.

The man pages recommands using sysconf(_SC_CLK_TCK) instead of CLK_TCK and that's what this patch does
Comment 4 Olliver Schinagl 2006-03-17 06:54:55 UTC
I don't know where that came from.

But from http://www.chemie.fu-berlin.de/chemnet/use/info/libc/libc_17.html
it says:
Macro: int CLK_TCK
    This is an obsolete name for CLOCKS_PER_SEC.
Comment 5 Olliver Schinagl 2006-03-17 06:57:51 UTC
And god forbid:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_clocks_per_sec.2c_.clk_tck.asp

even tells us:
The time in seconds is the value returned by the clock function, divided by CLOCKS_PER_SEC. CLK_TCK is equivalent, but considered obsolete.

And even time.h (the old glibc version one) has CLK_TCK defined as
# if defined __USE_POSIX && !defined __USE_XOPEN2K
#  ifndef CLK_TCK
#   define CLK_TCK      CLOCKS_PER_SEC
#  endif
# endif

So I don't know what the sysconf(_SC_CLK_TCK) does, but I'm fairly confident that it should be CLOCKS_PER_SEC.
Comment 6 Sylvain Munaut 2006-03-17 07:19:17 UTC
Well, that comes from the man pages :

man 2 times tells us :

times() returns the number of clock ticks that have elapsed since an arbitrary point in the past. 
 ...
The number of clock ticks per second can be obtained using sysconf(_SC_CLK_TCK);
In POSIX-1996 the symbol CLK_TCK (defined in <time.h>) is mentioned as obsolescent. It is obsolete now.
 ...
Note that clock(3) returns values of type  clock_t  that  are  not  measured  in  clock  ticks  but  in CLOCKS_PER_SEC.

and a 'man clock' confirms that.

So if the info comes from the function times, use sysconf(...), if the info comes from clock, use CLOCKS_PER_SEC


And theses two values are quite different :

tnt@hitomi ~ $ cat test.c 
#include <stdio.h>
#include <unistd.h>
#include <sys/times.h>
#include <time.h>
int main(int argc, char *argv[]) {
        printf("%d %d\n", sysconf(_SC_CLK_TCK), CLOCKS_PER_SEC);
}                               
tnt@hitomi ~ $ ./test           
100 1000000
Comment 7 Olliver Schinagl 2006-03-17 07:59:11 UTC
Well until someone stops bye that knows this thing exactly:

as I mentioned, the pre 2.4 glibc has:

# if defined __USE_POSIX && !defined __USE_XOPEN2K
#  ifndef CLK_TCK
#   define CLK_TCK      CLOCKS_PER_SEC
#  endif
# endif

so changing CLK_TCK to CLOCKS_PER_SEC you should have a identical binary.

with _CLK_TCK you obvisouly won't.

Again, I don't know what it should be, I haven't studied the code, but this seemed the most sensible to me, as you don't want binary un-identical (is that a word?) code, when only replasing an obsolete macro.
Comment 8 Sylvain Munaut 2006-03-17 08:51:12 UTC
I just tried the following test on a glibc 2.3.5 machine (see below) and
that shows that 
sysconf(_SC_CLK_TCK) = 100
CLOCKS_PER_SEC = 1000000
CLK_TCK = 100

Yes, the binary will be different that's because there is no longer any static/compile time value for CLK_TCK ... now you have to make a function call to get it ...

Try the little apps below by yourself on a pre-2.4 machine ...


tnt@ritsuko ~ $ /lib/libc.so.6 
GNU C Library stable release version 2.3.5, by Roland McGrath et al.
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 3.4.4 (Gentoo 3.4.4-r1, ssp-3.4.4-1.0, pie-8.7.8).
Compiled on a Linux 2.6.11 system on 2005-12-31.
Available extensions:
        GNU libio by Per Bothner
        crypt add-on version 2.1 by Michael Glad and others
        linuxthreads-0.10 by Xavier Leroy
        The C stubs add-on version 2.1.2.
        GNU Libidn by Simon Josefsson
        BIND-8.2.3-T5B
        libthread_db work sponsored by Alpha Processor Inc
        NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
Thread-local storage support included.
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.

tnt@ritsuko ~ $ cat test.c
#include <stdio.h>
#include <unistd.h>
#include <sys/times.h>
#include <time.h>
int main(int argc, char *argv[]) {
                printf("%d %d %d\n", sysconf(_SC_CLK_TCK), CLOCKS_PER_SEC, CLK_TCK);
}
                               
tnt@ritsuko ~ $ ./test 
100 1000000 100

Comment 9 Olliver Schinagl 2006-03-17 08:57:36 UTC
I agree with the results of the test program.

I just wonder why even the MSDN site (which is google's first hit on CLK_TCK) claims to use CLOCKS_PER_SEC.

Even time.h says defines it as so.

Weird. Well as long as it's fixed, it's all good right?

All we need is an updated ebuild to get merged in and we can mark it as closed.
Comment 10 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2006-05-25 14:38:29 UTC
Could you please modify the patch to have only one sysconf call and cache the result - this should be safe, but correct me if I'm wrong.
Comment 11 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2006-05-26 14:47:17 UTC
Ok, I implemented it myself, and stuck it in.