602 Commits

Author SHA1 Message Date
Andrew Kelley
b086b7da9e zig cc: complete the -wrap flag implementation
* use a set instead of a list
* use of this flag currently requires LLD
* add documentation
* make it only a zig cc compatibility flag for now because I personally
  think this is an anti-feature.
2023-04-07 07:54:47 -07:00
Zach Cheung
1fdea551b2 add linker -wrap flag 2023-04-07 09:09:38 -04:00
Andrew Kelley
f289277599 Merge remote-tracking branch 'origin/master' into llvm16 2023-04-05 22:05:31 -07:00
Jakub Konka
a88c0b4d08 link: handle -u flag in all linkers
Also clean up parsing of linker args - reuse `ArgsIterator`.

In MachO, ensure we add every symbol marked with `-u` as undefined
before proceeding with symbol resolution. Additionally, ensure those
symbols are never garbage collected.

MachO entry_in_dylib test: pass `-u _my_main` when linking executable
so that it is not incorrectly garbage collected by the linker.
2023-04-01 14:22:44 +02:00
kcbanner
c79073c176 compilation: fixup linker_dynamicbase default in InitOptions 2023-03-25 16:26:48 -04:00
Andrew Kelley
5c4bbd0657 Merge remote-tracking branch 'origin/master' into llvm16 2023-03-17 14:55:22 -07:00
Jacob Young
cfcd6698cd main: add debug option to dump unoptimized llvm ir 2023-03-17 01:57:14 -04:00
Andrew Kelley
1ed569e0b2 Merge remote-tracking branch 'origin/master' into llvm16 2023-03-16 17:33:24 -07:00
Andrew Kelley
363d4a107d add compile log output to build runner 2023-03-15 10:48:15 -07:00
Andrew Kelley
23295f64ca fix ZIR decoding of error notes 2023-03-15 10:48:14 -07:00
Andrew Kelley
2996eb5587 std.Build.RunStep: add maxrss, duration, and cached status 2023-03-15 10:48:13 -07:00
Andrew Kelley
9bf63b0996 stage2: avoid linux-only APIs on other operating systems 2023-03-15 10:48:13 -07:00
Andrew Kelley
8acbfafefb compiler: update function accepts a std.Progress.Node
This makes progress be exposed to the top-level caller of update().

I tossed in a bonus change: when the `zig build` subcommand sees exit
code 2, it omits the "following command failed" line, and the build
runner uses exit code 2 when there are compile errors. This tidies up
the output on build failure by a little bit.
2023-03-15 10:48:13 -07:00
Andrew Kelley
6d88c3e935 add builtin.zig_version_string
sometimes this is more useful than SemanticVersion
2023-03-15 10:48:13 -07:00
Andrew Kelley
6f717b18f0 std.zig.ErrorBundle: rework binary encoding
* Separate into a "WIP" struct and a "finished" struct.
* Use a bit of indirection for error notes to simplify ergonomics of
  this data structure.
2023-03-15 10:48:13 -07:00
Andrew Kelley
572cb24d1a progress towards semantic error serialization
Introduces std.zig.ErrorBundle which is a trivially serializeable set
of compilation errors. This is in the standard library so that both
the compiler and the build runner can use it. The idea is they will
use it to communicate compilation errors over a binary protocol.

The binary encoding of ErrorBundle is a bit problematic - I got a little
too aggressive with compaction. I need to change it in a follow-up
commit to use some indirection in the error message list, otherwise
iteration is too unergonomic. In fact it's so problematic right now that
the logic getAllErrorsAlloc() actually fails to produce a viable
ErrorBundle because it puts SourceLocation data in between the root
level ErrorMessage data.

This commit has a simplification - redundant logic for rendering AST
errors to stderr has been removed in favor of moving the logic for
lowering AST errors into AstGen. So even if we get parse errors, the
errors will get lowered into ZIR before being reported. I believe this
will be useful when working on --autofix. Either way, some redundant
brittle logic was happily deleted.

In Compilation, updateSubCompilation() is improved to properly perform
error reporting when a sub-compilation object fails. It no longer dumps
directly to stderr; instead it populates an ErrorBundle object, which
gets added to the parent one during getAllErrorsAlloc().

In package fetching code, instead of dumping directly to stderr, it now
populates an ErrorBundle object, and gets properly reported at the CLI
layer of abstraction.
2023-03-15 10:48:12 -07:00
Andrew Kelley
ae8e7c8f5a stage2: hot code swapping PoC
* CLI supports --listen to accept commands on a socket
 * make it able to produce an updated executable while it is running
2023-03-15 10:48:12 -07:00
Andrew Kelley
5b90fa05a4 extract ThreadPool and WaitGroup from compiler to std lib 2023-03-15 10:48:12 -07:00
Andrew Kelley
d399f8a489 Merge remote-tracking branch 'origin/master' into llvm16 2023-02-27 16:10:48 -07:00
Andrew Kelley
c9e02d3e69
Merge pull request #14691 from jacobly0/ctype 2023-02-22 11:06:13 -05:00
Jacob Young
064b355912 CBE: use CType for type definitions 2023-02-21 00:00:19 -05:00
Jacob Young
cf7200e8f9 CBE: remove typedef data structures
Adds a new mechanism for `@tagName` function generation that doesn't
piggyback on the removed typedef system.
2023-02-21 00:00:19 -05:00
Jacob Young
d8fada6b63 CBE: add CType interning 2023-02-20 23:48:36 -05:00
mlugg
b8a96baab8
Improve multi-module error messages
- Fix assertion failure if AstGen failed on a multi-module file
- Cap number of per-error reference notes and total multi-module errors each at 5
- Always put "root of package" reference notes first

Resolves: #14499
2023-02-21 02:05:35 +00:00
mlugg
705d2a3c2c
Implement new module CLI 2023-02-21 01:59:37 +00:00
Andrew Kelley
b5b634e4e8 Merge remote-tracking branch 'origin/master' into llvm16 2023-02-19 10:20:19 -07:00
Andrew Kelley
aeaef8c0ff update std lib and compiler sources to new for loop syntax 2023-02-18 19:17:21 -07:00
Andrew Kelley
efdc94c107 Merge remote-tracking branch 'origin/master' into llvm16 2023-02-18 09:33:27 -07:00
Andrew Kelley
06df842e4d unconditionally pass --no-default-config to clang
As of Clang 16.x, it will by default read extra flags from /etc/clang.
I'm sure the person who implemented this means well, but they have a lot
to learn about abstractions and where the appropriate boundaries between
them are. The road to hell is paved with good intentions. Fortunately it
can be disabled.
2023-02-18 09:32:31 -07:00
Motiejus Jakštys
b1b944a683 [elf linker] add --sort-section
Tested by: created a "hello world" C file and compiled with:

    zig cc -v main.c -Wl,--sort-section=name -o main

... and verified the `--sort-section=name` is passed to ld.lld.

Refs https://github.com/zigchroot/zig-chroot/issues/1
2023-02-16 18:44:56 -05:00
Jakub Konka
4e6f21e2cb comp: reinstate -fcompiler-rt when used with build-obj as output
When the following is specified

```
$ zig build-obj -fcompiler-rt example.zig
```

the resulting relocatable object file will have the compiler-rt
unconditionally embedded inside.

```
$ nm example.o
...
0000000012345678 W __truncsfhf2
...
```
2023-02-14 12:12:22 -05:00
Andrew Kelley
a9e1cf3049
Merge pull request #14571 from ziglang/more-build-zig
std.Build.ConfigHeaderStep: support sentinel-terminated strings
2023-02-13 17:23:19 -05:00
AdamGoertz
c8dc00086e
Add -ferror-tracing and -fno-error-tracing compile options 2023-02-13 16:23:13 +02:00
Andrew Kelley
9cb52ca6ce move the cache system from compiler to std lib 2023-02-13 06:42:25 -07:00
Dominic
948754c5d4
clone package table into custom test runner
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2023-02-08 22:39:38 +11:00
dweiller
edc0e84270 allow custom test runners to import modules 2023-02-08 16:35:32 +11:00
dweiller
1f7390f399 fix custom test runner package path resolution
Fixes #13970.

This fix makes test runners resolve package paths relative to the
directory the test runner is in. This means it is not possible to import
a file from outside the file tree root at the directory containing the
test runner.
2023-02-08 14:30:37 +11:00
Andrew Kelley
81c27c74bc use build.zig.zon instead of build.zig.ini for the manifest file
* improve error message when build manifest file is missing
 * update std.zig.Ast to support ZON
 * Compilation.AllErrors.Message: make the notes field a const slice
 * move build manifest parsing logic into src/Manifest.zig and add more
   checks, and make the checks integrate into the standard error
   reporting code so that reported errors look sexy

closes #14290
2023-02-03 00:06:11 -07:00
Jakub Konka
5de2aae63c link: decouple DI atoms from linker atoms, and manage them in Dwarf linker 2023-02-01 15:03:55 +01:00
Veikka Tuominen
220020599c
Merge pull request #13670 from mlugg/fix/astgen-ambiguous-package
AstGen: detect and error on files included in multiple packages
2023-01-23 14:25:42 +02:00
Andrew Kelley
8484df5bd2 zig cc: add -Wno-overriding-t-option to clang on darwin
This avoids a warning that sometimes occurs when providing both a
-target argument that contains a version as well as the
-mmacosx-version-min argument. Zig provides the correct value in both
places, so it doesn't matter which one gets overridden.
2023-01-22 12:27:18 -07:00
mlugg
5f9186d0ce
AstGen: detect and error on files included in multiple packages
Previously, if a source file was referenced from multiple packages, it
just became owned by the first one AstGen happened to reach; this was a
problem, because it could lead to inconsistent behaviour in the compiler
based on a race condition. This could be fixed by just analyzing such
files multiple times - however, it was pointed out by Andrew that it
might make more sense to enforce files being part of at most a single
package. Having a file in multiple packages would not only impact
compile times (due to Sema having to run multiple times on potentially a
lot of code) but is also a confusing anti-pattern which more often than
not is a mistake on the part of the user.

Resolves: #13662
2023-01-22 19:00:03 +00:00
mlugg
6d71d79dc2
Package: store package name directly
By @Vexu's suggestion, since fetching the name from the parent package
is error-prone and complex, and optimising Package for size isn't really
a priority.
2023-01-22 19:00:03 +00:00
Motiejus Jakštys
6b3f59c3a7 zig run/cc: recognize "-x language"
This commit adds support for "-x language" for a couple of hand-picked
supported languages. There is no reason the list of supported languages
to not grow (e.g. add "c-header"), but I'd like to keep it small at the
start.

Alternative 1
-------------

I first tried to add a new type "Language", and then add that to the
`CSourceFile`. But oh boy what a change it turns out to be. So I am
keeping myself tied to FileExt and see what you folks think.

Alternative 2
-------------

I tried adding `Language: ?[]const u8` to `CSourceFile`. However, the
language/ext, whatever we want to call it, still needs to be interpreted
in the main loop: one kind of handling for source files, other kind of
handling for everything else.

Test case
---------

*standalone.c*

    #include <iostream>

    int main() {
        std::cout << "elho\n";
    }

Compile and run:

    $ ./zig run -x c++ -lc++ standalone.c
    elho
    $ ./zig c++ -x c++ standalone.c -o standalone && ./standalone
    elho

Fixes #10915
2023-01-13 21:38:11 -05:00
Frank Denis
6ad92108e2 ELF linker: support common-page-size and max-page-size lld opts
These linker flags are required to build static ELF binaries that
can run under the Blink emulator:

https://github.com/jart/blink/issues/14
2023-01-05 19:39:17 -07:00
kcbanner
9c0a41f88a rebase fixup 2023-01-04 21:45:06 -05:00
kcbanner
b42442f5b4 windows: fixes to support using zig cc/c++ with CMake on Windows
Using zig cc with CMake on Windows was failing during compiler
detection. -nostdinc was causing the crt not to be linked, and Coff/lld.zig
assumed that wWinMainCRTStartup would be present in this case.

-nostdlib did not prevent the default behaviour of linking libc++ when
zig c++ was used. This caused libc++ to be built when CMake ran
ABI detection using zig c++, which fails as libcxxabi cannot compile
under MSVC.

- Change the behaviour of COFF -nostdinc to set /entry to the function that the
default CRT method for the specified subsystem would have called.
- Fix -ENTRY being passed twice if it was specified explicitly and -nostdlib was present.
- Add support for /pdb, /version, /implib, and /subsystem as linker args (passed by CMake)
- Remove -Ddisable-zstd, no longer needed
- Add -Ddisable-libcpp for use when bootstrapping on msvc
2023-01-04 21:45:06 -05:00
kcbanner
a03c8ef4bf fixup formatting 2023-01-04 21:45:06 -05:00
kcbanner
b97a68c529 windows: supporting changes for boostrapping via msvc
- add support for passing through .def files to the linker,
  required for building libLTO.dll in LLVM
- fixup libcpp linking conditionals
- add option to skip linking zstd for use in bootstrapping (when
  building against an LLVM with LLVM_ENABLE_ZSTD=OFF)
2023-01-04 21:45:06 -05:00
kcbanner
0471eea0e2 build: first pass on geting stage3 building under x64_64-windows-msvc 2023-01-04 21:45:05 -05:00