Skip to content

Commit 2b9228a

Browse files
committedJul 29, 2024
8318696: Do not use LFS64 symbols on Linux
Reviewed-by: andrew Backport-of: 2697a9d1c288daaddae751a7e8a2d2239c5d884c
1 parent 77cb961 commit 2b9228a

File tree

5 files changed

+31
-26
lines changed

5 files changed

+31
-26
lines changed
 

‎make/autoconf/flags-cflags.m4

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER],
419419
[
420420
#### OS DEFINES, these should be independent on toolchain
421421
if test "x$OPENJDK_TARGET_OS" = xlinux; then
422-
CFLAGS_OS_DEF_JVM="-DLINUX"
422+
CFLAGS_OS_DEF_JVM="-DLINUX -D_FILE_OFFSET_BITS=64"
423423
CFLAGS_OS_DEF_JDK="-D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE"
424424
elif test "x$OPENJDK_TARGET_OS" = xmacosx; then
425425
CFLAGS_OS_DEF_JVM="-D_ALLBSD_SOURCE -D_DARWIN_C_SOURCE -D_XOPEN_SOURCE"

‎src/hotspot/os/linux/attachListener_linux.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -182,6 +182,8 @@ int LinuxAttachListener::init() {
182182
char initial_path[UNIX_PATH_MAX]; // socket file during setup
183183
int listener; // listener socket (file descriptor)
184184

185+
static_assert(sizeof(off_t) == 8, "Expected Large File Support in this file");
186+
185187
// register function to cleanup
186188
if (!_atexit_registered) {
187189
_atexit_registered = true;
@@ -444,14 +446,14 @@ AttachOperation* AttachListener::dequeue() {
444446

445447
void AttachListener::vm_start() {
446448
char fn[UNIX_PATH_MAX];
447-
struct stat64 st;
449+
struct stat st;
448450
int ret;
449451

450452
int n = snprintf(fn, UNIX_PATH_MAX, "%s/.java_pid%d",
451453
os::get_temp_directory(), os::current_process_id());
452454
assert(n < (int)UNIX_PATH_MAX, "java_pid file name buffer overflow");
453455

454-
RESTARTABLE(::stat64(fn, &st), ret);
456+
RESTARTABLE(::stat(fn, &st), ret);
455457
if (ret == 0) {
456458
ret = ::unlink(fn);
457459
if (ret == -1) {
@@ -471,8 +473,8 @@ int AttachListener::pd_init() {
471473

472474
bool AttachListener::check_socket_file() {
473475
int ret;
474-
struct stat64 st;
475-
ret = stat64(LinuxAttachListener::path(), &st);
476+
struct stat st;
477+
ret = stat(LinuxAttachListener::path(), &st);
476478
if (ret == -1) { // need to restart attach listener.
477479
log_debug(attach)("Socket file %s does not exist - Restart Attach Listener",
478480
LinuxAttachListener::path());
@@ -511,14 +513,14 @@ bool AttachListener::is_init_trigger() {
511513
}
512514
char fn[PATH_MAX + 1];
513515
int ret;
514-
struct stat64 st;
516+
struct stat st;
515517
os::snprintf_checked(fn, sizeof(fn), ".attach_pid%d", os::current_process_id());
516-
RESTARTABLE(::stat64(fn, &st), ret);
518+
RESTARTABLE(::stat(fn, &st), ret);
517519
if (ret == -1) {
518520
log_trace(attach)("Failed to find attach file: %s, trying alternate", fn);
519521
snprintf(fn, sizeof(fn), "%s/.attach_pid%d",
520522
os::get_temp_directory(), os::current_process_id());
521-
RESTARTABLE(::stat64(fn, &st), ret);
523+
RESTARTABLE(::stat(fn, &st), ret);
522524
if (ret == -1) {
523525
log_debug(attach)("Failed to find attach file: %s", fn);
524526
}

‎src/hotspot/os/linux/os_linux.cpp

+15-13
Original file line numberDiff line numberDiff line change
@@ -2743,6 +2743,8 @@ int os::vm_allocation_granularity() {
27432743
void linux_wrap_code(char* base, size_t size) {
27442744
static volatile jint cnt = 0;
27452745

2746+
static_assert(sizeof(off_t) == 8, "Expected Large File Support in this file");
2747+
27462748
if (!UseOprofile) {
27472749
return;
27482750
}
@@ -4990,14 +4992,14 @@ int os::open(const char *path, int oflag, int mode) {
49904992
oflag |= O_CLOEXEC;
49914993
#endif
49924994

4993-
int fd = ::open64(path, oflag, mode);
4995+
int fd = ::open(path, oflag, mode);
49944996
if (fd == -1) return -1;
49954997

49964998
//If the open succeeded, the file might still be a directory
49974999
{
4998-
struct stat64 buf64;
4999-
int ret = ::fstat64(fd, &buf64);
5000-
int st_mode = buf64.st_mode;
5000+
struct stat buf;
5001+
int ret = ::fstat(fd, &buf);
5002+
int st_mode = buf.st_mode;
50015003

50025004
if (ret != -1) {
50035005
if ((st_mode & S_IFMT) == S_IFDIR) {
@@ -5034,17 +5036,17 @@ int os::open(const char *path, int oflag, int mode) {
50345036
int os::create_binary_file(const char* path, bool rewrite_existing) {
50355037
int oflags = O_WRONLY | O_CREAT;
50365038
oflags |= rewrite_existing ? O_TRUNC : O_EXCL;
5037-
return ::open64(path, oflags, S_IREAD | S_IWRITE);
5039+
return ::open(path, oflags, S_IREAD | S_IWRITE);
50385040
}
50395041

50405042
// return current position of file pointer
50415043
jlong os::current_file_offset(int fd) {
5042-
return (jlong)::lseek64(fd, (off64_t)0, SEEK_CUR);
5044+
return (jlong)::lseek(fd, (off_t)0, SEEK_CUR);
50435045
}
50445046

50455047
// move file pointer to the specified offset
50465048
jlong os::seek_to_file_offset(int fd, jlong offset) {
5047-
return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET);
5049+
return (jlong)::lseek(fd, (off_t)offset, SEEK_SET);
50485050
}
50495051

50505052
// This code originates from JDK's sysAvailable
@@ -5053,10 +5055,10 @@ jlong os::seek_to_file_offset(int fd, jlong offset) {
50535055
int os::available(int fd, jlong *bytes) {
50545056
jlong cur, end;
50555057
int mode;
5056-
struct stat64 buf64;
5058+
struct stat buf;
50575059

5058-
if (::fstat64(fd, &buf64) >= 0) {
5059-
mode = buf64.st_mode;
5060+
if (::fstat(fd, &buf) >= 0) {
5061+
mode = buf.st_mode;
50605062
if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) {
50615063
int n;
50625064
if (::ioctl(fd, FIONREAD, &n) >= 0) {
@@ -5065,11 +5067,11 @@ int os::available(int fd, jlong *bytes) {
50655067
}
50665068
}
50675069
}
5068-
if ((cur = ::lseek64(fd, 0L, SEEK_CUR)) == -1) {
5070+
if ((cur = ::lseek(fd, 0L, SEEK_CUR)) == -1) {
50695071
return 0;
5070-
} else if ((end = ::lseek64(fd, 0L, SEEK_END)) == -1) {
5072+
} else if ((end = ::lseek(fd, 0L, SEEK_END)) == -1) {
50715073
return 0;
5072-
} else if (::lseek64(fd, cur, SEEK_SET) == -1) {
5074+
} else if (::lseek(fd, cur, SEEK_SET) == -1) {
50735075
return 0;
50745076
}
50755077
*bytes = end - cur;

‎src/hotspot/os/posix/os_posix.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -279,6 +279,7 @@ static char* reserve_mmapped_memory(size_t bytes, char* requested_addr) {
279279
}
280280

281281
static int util_posix_fallocate(int fd, off_t offset, off_t len) {
282+
static_assert(sizeof(off_t) == 8, "Expected Large File Support in this file");
282283
#ifdef __APPLE__
283284
fstore_t store = { F_ALLOCATECONTIG, F_PEOFPOSMODE, 0, len };
284285
// First we try to get a continuous chunk of disk space
@@ -720,15 +721,15 @@ void os::dll_unload(void *lib) {
720721
}
721722

722723
jlong os::lseek(int fd, jlong offset, int whence) {
723-
return (jlong) BSD_ONLY(::lseek) NOT_BSD(::lseek64)(fd, offset, whence);
724+
return (jlong) ::lseek(fd, offset, whence);
724725
}
725726

726727
int os::fsync(int fd) {
727728
return ::fsync(fd);
728729
}
729730

730731
int os::ftruncate(int fd, jlong length) {
731-
return BSD_ONLY(::ftruncate) NOT_BSD(::ftruncate64)(fd, length);
732+
return ::ftruncate(fd, length);
732733
}
733734

734735
const char* os::get_current_directory(char *buf, size_t buflen) {

‎src/hotspot/os/posix/os_posix.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
// Note: the Posix API aims to capture functionality available on all Posix
2929
// compliant platforms, but in practice the implementations may depend on
30-
// non-Posix functionality. For example, the use of lseek64 and ftruncate64.
30+
// non-Posix functionality.
3131
// This use of non-Posix API's is made possible by compiling/linking in a mode
3232
// that is not restricted to being fully Posix complaint, such as by declaring
3333
// -D_GNU_SOURCE. But be aware that in doing so we may enable non-Posix

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Jul 29, 2024

@openjdk-notifier[bot]
Please sign in to comment.