mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Sebastian Kemper <sebastian_ml@gmx.net>
To: musl@lists.openwall.com
Subject: [musl] Cross-compiling and -D_LARGEFILE64_SOURCE
Date: Mon, 3 Feb 2020 21:44:17 +0100	[thread overview]
Message-ID: <20200203204416.GA19036@darth.lan> (raw)

Hello list,

I'm working on updating apr in OpenWrt. During configure it uses TRY_RUN
a lot, so we have a lot of configure variables defined to point it into
the right direction.

With one variable I have some trouble: apr_cv_use_lfs64=yes. The trouble
is I don't know whether or not to set it.

It basically forces -D_LARGEFILE64_SOURCE to be included in the
CPPFLAGS. So my first impulse was to force it to "yes". But then I saw
some build logs from Alpine Linux:

https://build.alpinelinux.org/buildlogs/build-edge-x86/main/apr/apr-1.7.0-r0.log

<snip>
checking whether the compiler provides atomic builtins... yes
checking whether to enable -D_LARGEFILE64_SOURCE... no
configure: Configured for Linux 4.14
<snip>

So Alpine is not cross-compiling here, and the result is "no". And this
particular log is for i586 (I thought - before seeing this log - that
maybe -D_LARGEFILE64_SOURCE is needed for non-64-bit platforms).

The TRY_RUN that apr uses to find out whether to add
-D_LARGEFILE64_SOURCE is pasted at the bottom of this mail. If I run
configure on my x86_64 glibc laptop it says "no". In the Alpine logs it
also says "no". If I search the Internet I find some old pastes where
the outcome was "yes", though. It kind of looks like the answer over
time changed from "yes" to "no", for no apparent reason (at least for
me).

If it sets -D_LARGEFILE64_SOURCE it propagates the same flag to its
users via apr-1-config. In the apr sources I see the define also being
used occasionally.

include/arch/unix/apr_arch_file_io.h:

#if APR_HAS_LARGE_FILES && defined(_LARGEFILE64_SOURCE)
#define stat(f,b) stat64(f,b)
#define lstat(f,b) lstat64(f,b)
#define fstat(f,b) fstat64(f,b)
#define lseek(f,o,w) lseek64(f,o,w)
#define ftruncate(f,l) ftruncate64(f,l)
typedef struct stat64 struct_stat;
#else
typedef struct stat struct_stat;
#endif

file_io/unix/open.c:

#if APR_HAS_LARGE_FILES && defined(_LARGEFILE64_SOURCE)
    oflags |= O_LARGEFILE;
#elif defined(O_LARGEFILE)
    if (flag & APR_FOPEN_LARGEFILE) {
        oflags |= O_LARGEFILE;
    }
#endif

I obviously would like LFS support, but I don't know about this
configure variable. I guess the correct answer must be one of these:

"Don't use it"
"Use it"
"Use it if condition X applies"

I guess this is a bit off-topic maybe. But I'm really running out of
ideas :) So if anybody can share some insight I'd really appreciate it.

Kind regards,
Seb

   AC_CACHE_CHECK([whether to enable -D_LARGEFILE64_SOURCE], [apr_cv_use_lfs64], [
   apr_save_CPPFLAGS=$CPPFLAGS
   CPPFLAGS="$CPPFLAGS -D_LARGEFILE64_SOURCE"
   AC_TRY_RUN([
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

void main(void)
{
    int fd, ret = 0;
    struct stat64 st;
    off64_t off = 4242;

    if (sizeof(off64_t) != 8 || sizeof(off_t) != 4)
       exit(1);
    if ((fd = open("conftest.lfs", O_LARGEFILE|O_CREAT|O_WRONLY, 0644)) < 0)
       exit(2);
    if (ftruncate64(fd, off) != 0)
       ret = 3;
    else if (fstat64(fd, &st) != 0 || st.st_size != off)
       ret = 4;
    else if (lseek64(fd, off, SEEK_SET) != off)
       ret = 5;
    else if (close(fd) != 0)
       ret = 6;
    else if (lstat64("conftest.lfs", &st) != 0 || st.st_size != off)
       ret = 7;
    else if (stat64("conftest.lfs", &st) != 0 || st.st_size != off)
       ret = 8;
    unlink("conftest.lfs");

    exit(ret);
}], [apr_cv_use_lfs64=yes], [apr_cv_use_lfs64=no], [apr_cv_use_lfs64=no])
   CPPFLAGS=$apr_save_CPPFLAGS])
   if test "$apr_cv_use_lfs64" = "yes"; then
      APR_ADDTO(CPPFLAGS, [-D_LARGEFILE64_SOURCE])
   fi

             reply	other threads:[~2020-02-03 20:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-03 20:44 Sebastian Kemper [this message]
2020-02-03 21:44 ` Rich Felker
2020-02-03 22:00   ` Sebastian Kemper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200203204416.GA19036@darth.lan \
    --to=sebastian_ml@gmx.net \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).