Re: svn commit: r325320 - head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs [breaks lld on zfs: lld uses fallocate]

From: Mark Millard <markmi_at_dsl-only.net>
Date: Sat, 4 Nov 2017 03:32:12 -0700
> Author: avg
> Date: Thu Nov  2 13:49:08 2017
> New Revision: 325320
> URL: 
> https://svnweb.freebsd.org/changeset/base/325320
> 
> 
> Log:
>   Disable posix_fallocate(2) for ZFS
> . . .

Turns out lld uses fallocate and so can fail
on zfs now.

The following is the lld for a amd64 -> aarch64
cross-buildworld.

/usr/obj/cortexA53_clang/arm64.aarch64/usr/src/arm64.aarch64/tmp/usr/bin/ld: error: cannot open output file a.out: Invalid argument

This resulted from:

Breakpoint 5, 0x0000000000cf1cd1 in llvm::sys::fs::resize_file(int, unsigned long) ()
(gdb) disass
Dump of assembler code for function _ZN4llvm3sys2fs11resize_fileEim:
. . .
   0x0000000000cf1ce5 <+21>:	callq  0x1ad5880 <posix_fallocate>
. . .

via the error status return value handling. It ends up with:

Breakpoint 3, 0x000000000041c6e4 in lld::elf::error(llvm::Twine const&) ()
(gdb) bt
#0  0x000000000041c6e4 in lld::elf::error(llvm::Twine const&) ()
#1  0x00000000004113b1 in void lld::elf::LinkerDriver::link<llvm::object::ELFType<(llvm::support::endianness)1, true> >(llvm::opt::InputArgList&) ()
#2  0x000000000040be3f in lld::elf::LinkerDriver::main(llvm::ArrayRef<char const*>, bool) ()
#3  0x000000000040ae89 in lld::elf::link(llvm::ArrayRef<char const*>, bool, llvm::raw_ostream&) ()
#4  0x000000000054cd61 in main ()


Progressing from posix_fallocate's call to its caller
and so on:

# grep -r "fallocate" /usr/src/contrib/llvm/ | more
/usr/src/contrib/llvm/lib/Support/Unix/Path.inc:  // If we have posix_fallocate use it. Unlike ftruncate it always allocates
/usr/src/contrib/llvm/lib/Support/Unix/Path.inc:  if (int Err = ::posix_fallocate(FD, 0, Size)) {

Is called by:

std::error_code resize_file(int FD, uint64_t Size) {
#if defined(HAVE_POSIX_FALLOCATE)
  // If we have posix_fallocate use it. Unlike ftruncate it always allocates
  // space, so we get an error if the disk is full.
  if (int Err = ::posix_fallocate(FD, 0, Size)) {
    if (Err != EOPNOTSUPP)
      return std::error_code(Err, std::generic_category());
  }
#endif
  // Use ftruncate as a fallback. It may or may not allocate space. At least on
  // OS X with HFS+ it does.
  if (::ftruncate(FD, Size) == -1)
    return std::error_code(errno, std::generic_category());

  return std::error_code();
}

# grep -r "resize_file" /usr/src/contrib/llvm/ | more
/usr/src/contrib/llvm/lib/Support/FileOutputBuffer.cpp:  EC = sys::fs::resize_file(FD, Size);
/usr/src/contrib/llvm/lib/Support/Unix/Path.inc:std::error_code resize_file(int FD, uint64_t Size) {
/usr/src/contrib/llvm/lib/Support/Windows/Path.inc:std::error_code resize_file(int FD, uint64_t Size) {
/usr/src/contrib/llvm/include/llvm/Support/FileSystem.h:std::error_code resize_file(int FD, uint64_t Size);

Is called by:

ErrorOr<std::unique_ptr<FileOutputBuffer>>
FileOutputBuffer::create(StringRef FilePath, size_t Size, unsigned Flags) {
  // Check file is not a regular file, in which case we cannot remove it.
. . .
#ifndef LLVM_ON_WIN32
  // . . .
  EC = sys::fs::resize_file(FD, Size);
  if (EC)
    return EC;
#endif

Is called by:

std::error_code elf::tryCreateFile(StringRef Path) {
  if (Path.empty())
    return std::error_code();
  return FileOutputBuffer::create(Path, 1).getError();
}

Is called by:

template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
  SymbolTable<ELFT> Symtab;
  elf::Symtab<ELFT>::X = &Symtab;
  Target = getTarget();

  Config->MaxPageSize = getMaxPageSize(Args);
  Config->ImageBase = getImageBase(Args);

  // Default output filename is "a.out" by the Unix tradition.
  if (Config->OutputFile.empty())
    Config->OutputFile = "a.out";

  // Fail early if the output file or map file is not writable. If a user has a
  // long link, e.g. due to a large LTO link, they do not wish to run it and
  // find that it failed because there was a mistake in their command-line.
  if (auto E = tryCreateFile(Config->OutputFile))
    error("cannot open output file " + Config->OutputFile + ": " + E.message());


And the error call is then made once
tryCreateFile returns.

===
Mark Millard
markmi at dsl-only.net
Received on Sat Nov 04 2017 - 09:32:21 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:41:13 UTC