Skip to content

self-hosted libc and dynamic linker detection #4478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Feb 18, 2020
Merged

Conversation

andrewrk
Copy link
Member

@andrewrk andrewrk commented Feb 16, 2020

  • libc_installation.cpp is deleted.
    src-self-hosted/libc_installation.zig is now used for both stage1 and
    stage2 compilers.
  • (breaking) move std.fs.File.access to std.fs.Dir.access. The API
    now encourages use with an open directory handle.
  • Add std.os.faccessat and related functions.
  • Deprecate the "C" suffix naming convention for null-terminated
    parameters. "C" should be used when it is related to libc. However
    null-terminated parameters often have to do with the native system
    ABI rather than libc. "Z" suffix is the new convention. For example,
    std.os.openC is deprecated in favor of std.os.openZ.
  • Add std.mem.dupeZ for using an allocator to copy memory and add a
    null terminator.
  • Remove dead struct field std.ChildProcess.llnode.
  • Introduce std.event.Batch. This API allows expressing concurrency
    without forcing code to be async. It requires no Allocator and does
    not introduce any failure conditions. However it is not thread-safe.
  • There is now an ongoing experiment to transition away from
    std.event.Group in favor of std.event.Batch.
  • std.os.execvpeC calls getenvZ rather than getenv. This is
    slightly more efficient on most systems, and works around a
    limitation of getenv lack of integration with libc.
  • (breaking) std.os.AccessError gains FileBusy, SymLinkLoop, and
    ReadOnlyFileSystem. Previously these error codes were all reported
    as PermissionDenied.
  • Add std.Target.isDragonFlyBSD.
  • stage2: access to the windows_sdk functions is done with a manually
    maintained .zig binding file instead of @cImport.
  • Update src-self-hosted/libc_installation.zig with all the
    improvements that stage1 has seen to src/libc_installation.cpp until
    now. In addition, it now takes advantage of Batch so that evented I/O
    mode takes advantage of concurrency, but it still works in blocking
    I/O mode, which is how it is used in stage1.

Checklist:

  • implement faccessat on Windows
  • all tests passing

 * libc_installation.cpp is deleted.
   src-self-hosted/libc_installation.zig is now used for both stage1 and
   stage2 compilers.
 * (breaking) move `std.fs.File.access` to `std.fs.Dir.access`. The API
   now encourages use with an open directory handle.
 * Add `std.os.faccessat` and related functions.
 * Deprecate the "C" suffix naming convention for null-terminated
   parameters. "C" should be used when it is related to libc. However
   null-terminated parameters often have to do with the native system
   ABI rather than libc. "Z" suffix is the new convention. For example,
   `std.os.openC` is deprecated in favor of `std.os.openZ`.
 * Add `std.mem.dupeZ` for using an allocator to copy memory and add a
   null terminator.
 * Remove dead struct field `std.ChildProcess.llnode`.
 * Introduce `std.event.Batch`. This API allows expressing concurrency
   without forcing code to be async. It requires no Allocator and does
   not introduce any failure conditions. However it is not thread-safe.
 * There is now an ongoing experiment to transition away from
   `std.event.Group` in favor of `std.event.Batch`.
 * `std.os.execvpeC` calls `getenvZ` rather than `getenv`. This is
   slightly more efficient on most systems, and works around a
   limitation of `getenv` lack of integration with libc.
 * (breaking) `std.os.AccessError` gains `FileBusy`, `SymLinkLoop`, and
   `ReadOnlyFileSystem`. Previously these error codes were all reported
   as `PermissionDenied`.
 * Add `std.Target.isDragonFlyBSD`.
 * stage2: access to the windows_sdk functions is done with a manually
   maintained .zig binding file instead of `@cImport`.
 * Update src-self-hosted/libc_installation.zig with all the
   improvements that stage1 has seen to src/libc_installation.cpp until
   now. In addition, it now takes advantage of Batch so that evented I/O
   mode takes advantage of concurrency, but it still works in blocking
   I/O mode, which is how it is used in stage1.
@andrewrk andrewrk added breaking Implementing this issue could cause existing code to no longer compile or have different behavior. stage1 The process of building from source via WebAssembly and the C backend. frontend Tokenization, parsing, AstGen, Sema, and Liveness. labels Feb 16, 2020
Rather than `zig0 build ...` the build now does
`zig0 build-lib ...`, avoiding the requirement of linking the build
script, and thus avoiding the requirement of finding native libc,
for systems where libc is the system ABI.
when both `--cache on` and `--output-dir` parameters
are provided. This prevents re-linking `zig` with every
`make` even when `libzigstage2.a` was unchanged.
not sure why the CI is complaining about these now and not in master
branch. but this is a slight code improvement anyway
prevents problems when source is created and then immediately copied to
dest.
Some C compilers, such as Clang, are known to rely on
argv[0] to find the path to their own executable,
without even bothering to resolve PATH. This results
in the message:

error: unable to execute command: Executable "" doesn't exist!

So we tell ChildProcess to expand argv[0] to the absolute path
to give them a helping hand.
crt_dir is only not required for darwin
@andrewrk
Copy link
Member Author

I forgot to mention, this solves #4312.

@andrewrk andrewrk changed the title self-hosted libc detection self-hosted libc and dynamic linker detection Feb 17, 2020
@andrewrk
Copy link
Member Author

The drone CI failure will be fixed by solving #2084.

The current target's ABI cannot be relied on for this.
For example, we may build the zig compiler for target
riscv64-linux-musl and provide a tarball for users to
download. A user could then run that zig compiler on
riscv64-linux-gnu. This use case is well-defined and
supported by Zig. But that means that we must detect
the system ABI here rather than
relying on `std.Target.current`.
@andrewrk andrewrk merged commit e8a8492 into master Feb 18, 2020
@andrewrk andrewrk deleted the self-host-libc-detection branch February 18, 2020 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Implementing this issue could cause existing code to no longer compile or have different behavior. frontend Tokenization, parsing, AstGen, Sema, and Liveness. stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants