Add UNIX large file support via compiler always-args

On 32-bit Linux and BSD, all libcs support this. Musl always enables it,
and UClibc behaves like Glibc unless it's built without large file
support (which is a terrible idea).

http://wiki.musl-libc.org/wiki/FAQ#Q:_do_i_need_to_define_LARGEFILE64_SOURCE_to_get_64bit_off_t_.3F
https://git.uclibc.org/uClibc/tree/include/features.h#n326

macOS now only ships 64-bit, so this is irrelevant there.

32-bit Windows and older versions of Bionic do not have transparent
large file support and you must use lseek64, etc there, so this won't
affect those. Newer Bionic versions behave like Glibc in theory.

https://msdn.microsoft.com/en-us/library/1yee101t.aspx
http://code.google.com/p/android/issues/detail?id=64613

Includes a linuxlike test for this.

Closes https://github.com/mesonbuild/meson/issues/1032
pull/1465/head
Nirbheek Chauhan 8 years ago committed by Jussi Pakkanen
parent 1713aef364
commit 853634a48d
  1. 37
      mesonbuild/compilers.py
  2. 12
      test cases/linuxlike/10 large file support/meson.build

@ -709,7 +709,10 @@ class CCompiler(Compiler):
return True # When compiling static libraries, so yes.
def get_always_args(self):
return []
'''
Args that are always-on for all C compilers other than MSVC
'''
return ['-pipe'] + get_largefile_args(self)
def get_linker_debug_crt_args(self):
"""
@ -2025,6 +2028,7 @@ class VisualStudioCCompiler(CCompiler):
'3': ['/W4']}
self.base_options = ['b_pch'] # FIXME add lto, pgo and the like
# Override CCompiler.get_always_args
def get_always_args(self):
return self.always_args
@ -2263,6 +2267,34 @@ def get_gcc_soname_args(gcc_type, prefix, shlib_name, suffix, path, soversion, i
else:
raise RuntimeError('Not implemented yet.')
def get_compiler_is_linuxlike(compiler):
if (getattr(compiler, 'gcc_type', None) == GCC_STANDARD) or \
(getattr(compiler, 'clang_type', None) == CLANG_STANDARD) or \
(getattr(compiler, 'icc_type', None) == ICC_STANDARD):
return True
return False
def get_largefile_args(compiler):
'''
Enable transparent large-file-support for 32-bit UNIX systems
'''
if get_compiler_is_linuxlike(compiler):
# Enable large-file support unconditionally on all platforms other
# than macOS and Windows. macOS is now 64-bit-only so it doesn't
# need anything special, and Windows doesn't have automatic LFS.
# You must use the 64-bit counterparts explicitly.
# glibc, musl, and uclibc, and all BSD libcs support this. On Android,
# support for transparent LFS is available depending on the version of
# Bionic: https://github.com/android/platform_bionic#32-bit-abi-bugs
# https://code.google.com/p/android/issues/detail?id=64613
#
# If this breaks your code, fix it! It's been 20+ years!
return ['-D_FILE_OFFSET_BITS=64']
# We don't enable -D_LARGEFILE64_SOURCE since that enables
# transitionary features and must be enabled by programs that use
# those features explicitly.
return []
class GnuCompiler:
# Functionality that is common to all GNU family compilers.
@ -2311,9 +2343,6 @@ class GnuCompiler:
return apple_buildtype_linker_args[buildtype]
return gnulike_buildtype_linker_args[buildtype]
def get_always_args(self):
return ['-pipe']
def get_pch_suffix(self):
return 'gch'

@ -0,0 +1,12 @@
project('trivial test', 'c')
cc = meson.get_compiler('c')
size = cc.sizeof('off_t')
assert(size == 8, 'off_t size is @0@ bytes instead of 8'.format(size))
code = '''#if !defined(_FILE_OFFSET_BITS) || (_FILE_OFFSET_BITS != 64)
#error "Large-file support was not enabled"
#endif'''
assert(cc.compiles(code, name : 'checking for LFS'), 'Large file support was not enabled')
Loading…
Cancel
Save