> 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

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 
 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 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());
  // 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) {
resize_file(int FD, uint64_t Size) {
resize_file(int FD, uint64_t Size);

Is called by:

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;

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

freebsd-current@freebsd.org mailing list
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"

Reply via email to