Bug 28182 - _TIME_BITS=64 in C++ has issues with fcntl, ioctl, prctl
Summary: _TIME_BITS=64 in C++ has issues with fcntl, ioctl, prctl
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: libc (show other bugs)
Version: 2.34
: P2 normal
Target Milestone: 2.35
Assignee: Florian Weimer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-08-03 17:34 UTC by David Korth
Modified: 2021-08-06 14:44 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2021-08-04 00:00:00
fweimer: security-


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Korth 2021-08-03 17:34:52 UTC
Attempting to compile a 32-bit C++ program that uses fcntl.h or sys/ioctl.h if _TIME_BITS=64 results in an error related to exception handling.

Sample code:

#include <fcntl.h>

int main(void)
{
        return 0;
}

Compile with: g++ -m32 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_TIME_BITS=64 -c test.cpp

Results:

In file included from /usr/include/features.h:488,
                 from /usr/include/fcntl.h:25,
                 from test.cpp:1:
/usr/include/fcntl.h:191:41: error: expected initializer before ‘noexcept’
  191 |                        __fcntl_time64)  __THROW;
      |                                         ^~~~~~~
/usr/include/fcntl.h:193:41: error: expected initializer before ‘noexcept’
  193 |                        __fcntl_time64)  __THROW;
      |                                         ^~~~~~~

The same code does compile if built as C code instead of as C++.

Software versions:

OS: Gentoo Linux
Arch: amd64 (Intel Core i7-3520M)
Compiler: gcc-11.1.0
glibc: 2.34
Comment 1 Florian Weimer 2021-08-06 14:44:15 UTC
Fixed for 2.35 via:

commit c87fcacc50505d550f1bb038382bcc7ea73a5926
Author: Florian Weimer <fweimer@redhat.com>
Date:   Fri Aug 6 09:51:38 2021 +0200

    Linux: Fix fcntl, ioctl, prctl redirects for _TIME_BITS=64 (bug 28182)
    
    __REDIRECT and __THROW are not compatible with C++ due to the ordering of the
    __asm__ alias and the throw specifier. __REDIRECT_NTH has to be used
    instead.
    
    Fixes commit 8a40aff86ba5f64a3a84883e539cb67b ("io: Add time64 alias
    for fcntl"), commit 82c395d91ea4f69120d453aeec398e30 ("misc: Add
    time64 alias for ioctl"), commit b39ffab860cd743a82c91946619f1b8158
    ("Linux: Add time64 alias for prctl").
    
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>