Skip to content

Commit

Permalink
8318696: Do not use LFS64 symbols on Linux
Browse files Browse the repository at this point in the history
Reviewed-by: ihse, dholmes, kbarrett, mbaesken
  • Loading branch information
thesamesam authored and Kim Barrett committed Jan 20, 2024
1 parent 9049402 commit f4d08cc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
2 changes: 1 addition & 1 deletion make/autoconf/flags-cflags.m4
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER],
[
#### OS DEFINES, these should be independent on toolchain
if test "x$OPENJDK_TARGET_OS" = xlinux; then
CFLAGS_OS_DEF_JVM="-DLINUX"
CFLAGS_OS_DEF_JVM="-DLINUX -D_FILE_OFFSET_BITS=64"
CFLAGS_OS_DEF_JDK="-D_GNU_SOURCE -D_REENTRANT -D_LARGEFILE64_SOURCE"
elif test "x$OPENJDK_TARGET_OS" = xmacosx; then
CFLAGS_OS_DEF_JVM="-D_ALLBSD_SOURCE -D_DARWIN_C_SOURCE -D_XOPEN_SOURCE"
Expand Down
18 changes: 10 additions & 8 deletions src/hotspot/os/linux/attachListener_linux.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -184,6 +184,8 @@ int LinuxAttachListener::init() {
char initial_path[UNIX_PATH_MAX]; // socket file during setup
int listener; // listener socket (file descriptor)

static_assert(sizeof(off_t) == 8, "Expected Large File Support in this file");

// register function to cleanup
if (!_atexit_registered) {
_atexit_registered = true;
Expand Down Expand Up @@ -446,14 +448,14 @@ AttachOperation* AttachListener::dequeue() {

void AttachListener::vm_start() {
char fn[UNIX_PATH_MAX];
struct stat64 st;
struct stat st;
int ret;

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

RESTARTABLE(::stat64(fn, &st), ret);
RESTARTABLE(::stat(fn, &st), ret);
if (ret == 0) {
ret = ::unlink(fn);
if (ret == -1) {
Expand All @@ -473,8 +475,8 @@ int AttachListener::pd_init() {

bool AttachListener::check_socket_file() {
int ret;
struct stat64 st;
ret = stat64(LinuxAttachListener::path(), &st);
struct stat st;
ret = stat(LinuxAttachListener::path(), &st);
if (ret == -1) { // need to restart attach listener.
log_debug(attach)("Socket file %s does not exist - Restart Attach Listener",
LinuxAttachListener::path());
Expand Down Expand Up @@ -513,14 +515,14 @@ bool AttachListener::is_init_trigger() {
}
char fn[PATH_MAX + 1];
int ret;
struct stat64 st;
struct stat st;
os::snprintf_checked(fn, sizeof(fn), ".attach_pid%d", os::current_process_id());
RESTARTABLE(::stat64(fn, &st), ret);
RESTARTABLE(::stat(fn, &st), ret);
if (ret == -1) {
log_trace(attach)("Failed to find attach file: %s, trying alternate", fn);
snprintf(fn, sizeof(fn), "%s/.attach_pid%d",
os::get_temp_directory(), os::current_process_id());
RESTARTABLE(::stat64(fn, &st), ret);
RESTARTABLE(::stat(fn, &st), ret);
if (ret == -1) {
log_debug(attach)("Failed to find attach file: %s", fn);
}
Expand Down
18 changes: 10 additions & 8 deletions src/hotspot/os/linux/os_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2772,6 +2772,8 @@ void os::jvm_path(char *buf, jint buflen) {
void linux_wrap_code(char* base, size_t size) {
static volatile jint cnt = 0;

static_assert(sizeof(off_t) == 8, "Expected Large File Support in this file");

if (!UseOprofile) {
return;
}
Expand Down Expand Up @@ -4262,7 +4264,7 @@ jlong os::Linux::fast_thread_cpu_time(clockid_t clockid) {
// the number of bytes written to out_fd is returned if transfer was successful
// otherwise, returns -1 that implies an error
jlong os::Linux::sendfile(int out_fd, int in_fd, jlong* offset, jlong count) {
return ::sendfile64(out_fd, in_fd, (off64_t*)offset, (size_t)count);
return ::sendfile(out_fd, in_fd, (off_t*)offset, (size_t)count);
}

// Determine if the vmid is the parent pid for a child in a PID namespace.
Expand Down Expand Up @@ -4940,14 +4942,14 @@ int os::open(const char *path, int oflag, int mode) {
oflag |= O_CLOEXEC;
#endif

int fd = ::open64(path, oflag, mode);
int fd = ::open(path, oflag, mode);
if (fd == -1) return -1;

//If the open succeeded, the file might still be a directory
{
struct stat64 buf64;
int ret = ::fstat64(fd, &buf64);
int st_mode = buf64.st_mode;
struct stat buf;
int ret = ::fstat(fd, &buf);
int st_mode = buf.st_mode;

if (ret != -1) {
if ((st_mode & S_IFMT) == S_IFDIR) {
Expand Down Expand Up @@ -4984,17 +4986,17 @@ int os::open(const char *path, int oflag, int mode) {
int os::create_binary_file(const char* path, bool rewrite_existing) {
int oflags = O_WRONLY | O_CREAT;
oflags |= rewrite_existing ? O_TRUNC : O_EXCL;
return ::open64(path, oflags, S_IREAD | S_IWRITE);
return ::open(path, oflags, S_IREAD | S_IWRITE);
}

// return current position of file pointer
jlong os::current_file_offset(int fd) {
return (jlong)::lseek64(fd, (off64_t)0, SEEK_CUR);
return (jlong)::lseek(fd, (off_t)0, SEEK_CUR);
}

// move file pointer to the specified offset
jlong os::seek_to_file_offset(int fd, jlong offset) {
return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET);
return (jlong)::lseek(fd, (off_t)offset, SEEK_SET);
}

// Map a block of memory.
Expand Down
7 changes: 4 additions & 3 deletions src/hotspot/os/posix/os_posix.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -287,6 +287,7 @@ static char* reserve_mmapped_memory(size_t bytes, char* requested_addr) {
}

static int util_posix_fallocate(int fd, off_t offset, off_t len) {
static_assert(sizeof(off_t) == 8, "Expected Large File Support in this file");
#ifdef __APPLE__
fstore_t store = { F_ALLOCATECONTIG, F_PEOFPOSMODE, 0, len };
// First we try to get a continuous chunk of disk space
Expand Down Expand Up @@ -752,11 +753,11 @@ void os::dll_unload(void *lib) {
}

jlong os::lseek(int fd, jlong offset, int whence) {
return (jlong) BSD_ONLY(::lseek) NOT_BSD(::lseek64)(fd, offset, whence);
return (jlong) ::lseek(fd, offset, whence);
}

int os::ftruncate(int fd, jlong length) {
return BSD_ONLY(::ftruncate) NOT_BSD(::ftruncate64)(fd, length);
return ::ftruncate(fd, length);
}

const char* os::get_current_directory(char *buf, size_t buflen) {
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/os/posix/os_posix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

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

7 comments on commit f4d08cc

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk22u

@openjdk
Copy link

@openjdk openjdk bot commented on f4d08cc Jan 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken the backport was successfully created on the branch backport-MBaesken-f4d08ccf in my personal fork of openjdk/jdk22u. To create a pull request with this backport targeting openjdk/jdk22u:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit f4d08ccf from the openjdk/jdk repository.

The commit being backported was authored by Sam James on 20 Jan 2024 and was reviewed by Magnus Ihse Bursie, David Holmes, Kim Barrett and Matthias Baesken.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk22u:

$ git fetch https://github.com/openjdk-bots/jdk22u.git backport-MBaesken-f4d08ccf:backport-MBaesken-f4d08ccf
$ git checkout backport-MBaesken-f4d08ccf
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk22u.git backport-MBaesken-f4d08ccf

@MBaesken
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk21u

@openjdk
Copy link

@openjdk openjdk bot commented on f4d08cc Jan 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken Could not automatically backport f4d08ccf to openjdk/jdk21u due to conflicts in the following files:

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

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk21u. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk21u.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b backport-MBaesken-f4d08ccf

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git f4d08ccf80812d4f26a148fac6bf99b96672a63f

# Backport the commit
$ git cherry-pick --no-commit f4d08ccf80812d4f26a148fac6bf99b96672a63f
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport f4d08ccf80812d4f26a148fac6bf99b96672a63f'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk21u with the title Backport f4d08ccf80812d4f26a148fac6bf99b96672a63f.

Below you can find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit f4d08ccf from the openjdk/jdk repository.

The commit being backported was authored by Sam James on 20 Jan 2024 and was reviewed by Magnus Ihse Bursie, David Holmes, Kim Barrett and Matthias Baesken.

Thanks!

@MBaesken
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on f4d08cc Jan 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken Could not automatically backport f4d08ccf to openjdk/jdk21u-dev due to conflicts in the following files:

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

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk21u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk21u-dev.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b backport-MBaesken-f4d08ccf

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git f4d08ccf80812d4f26a148fac6bf99b96672a63f

# Backport the commit
$ git cherry-pick --no-commit f4d08ccf80812d4f26a148fac6bf99b96672a63f
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport f4d08ccf80812d4f26a148fac6bf99b96672a63f'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk21u-dev with the title Backport f4d08ccf80812d4f26a148fac6bf99b96672a63f.

Below you can find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit f4d08ccf from the openjdk/jdk repository.

The commit being backported was authored by Sam James on 20 Jan 2024 and was reviewed by Magnus Ihse Bursie, David Holmes, Kim Barrett and Matthias Baesken.

Thanks!

Please sign in to comment.