Tcl Source Code

View Ticket
Login
Ticket UUID: 02b58d5d040821baebe7eccd70aee11afa1bacae
Title: Direct access of *64 functions by Tcl code (code cleanup)
Type: Bug Version: 8.6.8
Submitter: bll Created on: 2018-05-09 15:08:47
Subsystem: 53. Configuration and Build Tools Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2023-07-21 15:12:41
Resolution: Wont Fix Closed By: chrstphrchvz
    Closed on: 2023-07-21 15:12:41
Description:
I noticed this in ticket:
   https://core.tcl.tk/tcl/info/92564326a98b5510

No code should ever be accessing the *64 functions directly.

The configuration process should be using the output
of `getconf LFS_CFLAGS` (and LFS_LDFLAGS and LFS_LIBS) as appropriate.
User Comments: chrstphrchvz added on 2023-07-21 15:12:41: (text/x-fossil-wiki)
I apologize for any confusion, but my comment about the order of tests does not apply to <tt>_LARGEFILE64_SOURCE</tt>, so I don’t think [d6640b90305e] makes any difference. Although that macro is also considered obsolete, it is in the sense that the family of function declarations and structure definitions it enables, e.g. <tt>stat64()</tt> and <tt>struct stat64</tt>, are obsolete in favor defining <tt>_FILE_OFFSET_BITS=64</tt> to enable 64-bit <tt>stat()</tt> and <tt>struct stat</tt> and using those instead.  Not defining <tt>_LARGEFILE64_SOURCE</tt> leaves <tt>stat64()</tt> and <tt>struct stat64</tt> disabled, regardless of whether <tt>_FILE_OFFSET_BITS=64</tt> is defined.

Also be aware that, depending on whether <tt>_FILE_OFFSET_BITS=64</tt> or <tt>_TIME_BITS=64</tt> are defined, <tt>sizeof(struct stat64)</tt> and the implementation (i.e. symbol name) of <tt>stat64()</tt> can change on 32-bit systems.

P.S.: [https://gcc.godbolt.org] is a neat tool for exploring this stuff.

jan.nijtmans added on 2023-07-21 07:22:41: (text/x-fossil-wiki)
Thanks, I see your point: [d6640b90305e1e21]

Closing this ticket, since [d40b9c8503eb] already handles the necessary steps for old systems. I see no reason to rewrite the whole stuff, since all is obsolete in the 64-bit world anyway.

chrstphrchvz added on 2023-07-20 20:16:35: (text/x-fossil-wiki)
<a href="https://man7.org/linux/man-pages/man7/feature_test_macros.7.html"><tt>man feature_test_macros</tt></a> from the Linux man-pages project says that the <tt>_LARGEFILE_SOURCE</tt> macro is obsolete, and that <tt>_FILE_OFFSET_BITS=64</tt> is now enough to enable 64-bit declarations of <tt>fseeko()</tt> and <tt>ftello()</tt>. I am not aware exactly how long this has been the case. But there is seemingly no harm in leaving a configuration test in Tcl for defining <tt>_LARGEFILE_SOURCE</tt> in case it is needed; it should now just go after the one for <tt>_FILE_OFFSET_BITS=64</tt> (recently added for [d40b9c8503eb]).

jan.nijtmans added on 2020-08-21 12:25:47: (text/x-fossil-wiki)
A start implementing this, can be found in the "bug-02b58d5d04" branch. Basically, remove the use of the various "64"-related macro's.

bll added on 2018-05-15 00:08:38:
Right.  If this had been done correctly (i.e. implicit) in the first
place, the referenced ticket would never have had a bug.

I cannot think of a reason to ever use explicit access.  Perhaps in the
early days of 32/64 conversion when a 32-bit API might need to be accessed.

I agree, there's no need to rush this into place, but I think it greatly
reduces the chances of bugs and should simplify the code.

"(implicit) 3. The size of filesize related data types is increased to 64 bits. eg off_t, blkcnt_t, etc are now 64 bits in size"

Since explicit was used, the size of off_t may be different on 32-bit systems.

bll-tecra:bll$ egrep -l off_t */*.c */*.h
generic/tclIOUtil.c
macosx/tclMacOSXFCmd.c  # 64-bit, no issue here.
unix/tclUnixChan.c
generic/regex.h
unix/tclUnixPort.h
bll-tecra:bll$ egrep -l blkcnt_t */*.c */*.h
generic/tclIOUtil.c

jan.nijtmans added on 2018-05-14 19:34:39: (text/x-fossil-wiki)
All of this is described in: [https://people.redhat.com/berrange/notes/largefile.html]

As I understand it, both 'implicit' and 'explicit' LSF is allowed.  Care should be taken to the STAT functions as well, so it's not trivial to make this change. It gives more readable code, so I'll have a look. (I won't be angry if someone provides patches .....)

Anyway, such a change should be tested very well on various platforms. So I think it's wise to to that for Tcl 9, not 8.x, because it might easily break some platform if not done well.