25 Commits

Author SHA1 Message Date
Andrew Kelley
1f34c03ac1 Merge remote-tracking branch 'origin/master' into llvm12 2021-03-12 18:05:27 -07:00
LemonBoy
f2b96782ec stage2: Fix glibc lookup path for MIPS crt files
Add some more rules to let the compiler find the correct startup files
for the selected target and ABI.
2021-03-09 18:20:34 -05:00
Andrew Kelley
4b1fe8e492 glibc: clang 12 assembler regression workaround
Our glibc stub assembly file looked something like this:

```
.globl _Exit_2_2_5
.type _Exit_2_2_5, %function;
.symver _Exit_2_2_5, _Exit@@GLIBC_2.2.5
.hidden _Exit_2_2_5
_Exit_2_2_5:
```

With clang 12, the shared objects this produced stopped having any
exported symbols. When I removed the `.hidden` directive, it resolved
the issue, however, there are now unwanted exports:

```
$ readelf -W --dyn-syms libc.so.6 | grep sys_errlist
   139: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 _sys_errlist_GLIBC_2_3
   147: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 _sys_errlist_GLIBC_2_4
   395: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 _sys_errlist_GLIBC_2_2_5
   487: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 sys_errlist_GLIBC_2_2_5
  1266: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 _sys_errlist@@GLIBC_2.12
  1267: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 _sys_errlist@GLIBC_2.2.5
  1268: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 _sys_errlist@GLIBC_2.3
  1269: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 _sys_errlist@GLIBC_2.4
  2137: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 sys_errlist@@GLIBC_2.12
  2138: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 sys_errlist@GLIBC_2.2.5
  2139: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 sys_errlist@GLIBC_2.3
  2140: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 sys_errlist@GLIBC_2.4
  2156: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 sys_errlist_GLIBC_2_3
  2161: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 sys_errlist_GLIBC_2_4
```

Every line here without an `@` symbol is an unwanted export. Before, the
unwanted ones had LOCAL HIDDEN linkage.

As a mitigation, I did two things:

 * Added `_GLIBC_` to the unwanted exports so that they would not
   conflict with anything.
 * Made the default export (the `@@` one) the bare symbol name. This
   appears to reduce the unwanted exports to only symbols that have more
   than one symbol (which is still quite many).

This will unblock progress on this branch, however, there is now a new
issue to solve, that the provided glibc stub .so files have too many
symbols exported. We will have to find a way to avoid this.
2021-02-28 00:53:05 -07:00
Andrew Kelley
5b2a79848c stage2: cleanups regarding red zone CLI flags
* CLI: change to -mred-zone and -mno-red-zone to match gcc/clang.
 * build.zig: remove the double negative and make it an optional bool.
   This follows precedent from other flags, allowing the compiler CLI to
   be the decider of what is default instead of duplicating the default
   value into the build system code.
 * Compilation: make it an optional `want_red_zone` instead of a
   `no_red_zone` bool. The default is decided by a call to
   `target_util.hasRedZone`.
 * When creating a Clang command line, put -mred-zone on the command
   line if we are forcing it to be enabled.
 * Update update_clang_options.zig with respect to the recent {s}/{} format changes.
 * `zig cc` integration with red zone preference.
2021-01-11 22:07:21 -07:00
Lee Cannon
8932c2d745 Added support for no red zone 2021-01-11 22:07:14 -07:00
Andrew Kelley
974c008a0e convert more {} to {d} and {s} 2021-01-02 19:03:14 -07:00
LemonBoy
1c13ca5a05 stage2: Use {s} instead of {} when formatting strings 2021-01-02 17:12:57 -07:00
Andrew Kelley
6ab9268a90 stage2: re-use compiler runtime libs across opt modes and strip flag
Previously Zig would need to recompile runtime libs if you changed the
values of --strip or -O. Now, unless the `debug_compiler_runtime_libs`
flag is set (which is currently not exposed to the CLI), Zig will always
choose ReleaseFast or ReleaseSmall for compiler runtime libraries.

When the main application chooses ReleaseFast or ReleaseSmall, that
value is propagated to compiler runtime libraries. Otherwise a decision
is made based on the target, which is currently ReleaseSmall for
freestanding WebAssembly and ReleaseFast for everything else.

Ultimately the purpose of this commit is to have Debug and ReleaseSafe
builds of applications still get optimized builds of, e.g. libcxx and
libunwind, as well as to spend less time unnecessarily rebuilding compiler
runtime libraries.
2020-12-24 14:11:58 -07:00
Andrew Kelley
8219d92987 stage2: fix Cache deadlock and build more of TSAN
* rename is_compiler_rt_or_libc to skip_linker_dependencies
   and set it to `true` for all sub-Compilations. I believe
   this resolves the deadlock we were experiencing on Drone
   CI and on some users' computers. I will remove the CI workaround in
   a follow-up commit.
 * enabling TSAN automatically causes the Compilation to link against
   libc++ even if not requested, because TSAN depends on libc++.
 * add -fno-rtti flags where appropriate when building TSAN objects.
   Thanks Firefox317 for pointing this out.
 * TSAN support: resolve all the undefined symbols. We are still seeing
   a dependency on __gcc_personality_v0 but will resolve this one in a
   follow-up commit.
 * static libs do not try to build libc++ or libc++abi.
2020-12-24 01:18:48 -07:00
Andrew Kelley
42b4a48bc9 WIP start adding support for TSAN 2020-12-24 01:18:47 -07:00
Andrew Kelley
0d1cd0d482 use kprotty's ThreadPool implementation (v5) 2020-12-20 15:08:59 -07:00
Andrew Kelley
013efaf139 std: introduce a thread-local CSPRNG for general use
std.crypto.random

* cross platform, even freestanding
* can't fail. on initialization for some systems requires calling
  os.getrandom(), in which case there are rare but theoretically
  possible errors. The code panics in these cases, however the
  application may choose to override the default seed function and then
  handle the failure another way.
* thread-safe
* supports the full Random interface
* cryptographically secure
* no syscall required to initialize on Linux (AT_RANDOM)
* calls arc4random on systems that support it

`std.crypto.randomBytes` is removed in favor of `std.crypto.random.bytes`.

I moved some of the Random implementations into their own files in the
interest of organization.

stage2 no longer requires passing a RNG; instead it uses this API.

Closes #6704
2020-12-18 12:22:46 -07:00
LemonBoy
5f7352b5b5 stage2: Add -include libc-symbols.h when building crtn.S
This -include is added for nearly every file in glibc's makefiles.
2020-12-15 14:53:46 -05:00
Isaac Freund
343249efd8 stage2: use %type not @type for libc stubs
Apparently ARM uses @ for comments. Everything seems to accept % here
though.
2020-12-13 23:19:23 -05:00
Andrew Kelley
4fd27719b4
Merge pull request #7406 from ifreund/dyn-musl2
stage2: support dynamically linking musl libc
2020-12-12 18:46:07 -05:00
Isaac Freund
1d8f33ca98
stage2: link musl dynamically by default if native
If targeting the native OS and the system libc is musl, link against it
dynamically by default.
2020-12-13 00:40:35 +01:00
Andrew Kelley
6b7ddfbafe glibc: do not provide -lcrypt
glibc is dropping this functionality moving forward.

This is a partial revert of commit
97c0e1cc41c24c6cbb60117751d5b82dcd9d0e43
2020-12-12 12:42:33 -07:00
Andrew Kelley
97c0e1cc41 glibc: additionally provide -lcrypt
also remove redundant "util" string matching.
2020-12-08 13:17:57 -05:00
Jakub Konka
dd522c0c97 stage2 elf: fix glibc to always specify soname 2020-11-27 15:42:39 -07:00
Jakub Konka
375bab8460 stage2 elf: refactor override_soname to soname 2020-11-27 15:42:39 -07:00
joachimschmidt557
7c5a24e08c Turn zig fmt back on in various src/ files 2020-10-05 04:48:58 -04:00
Andrew Kelley
b08fd0e8fc stage2: building musl libc from source 2020-09-23 20:48:47 -07:00
Andrew Kelley
dacd36ca9b stage2: implement using the global cache dir 2020-09-22 14:08:08 -07:00
Andrew Kelley
974333faaf stage2: fix linking libc trying to depend on itself 2020-09-21 21:42:27 -07:00
Andrew Kelley
528832bd3a rename src-self-hosted/ to src/ 2020-09-21 18:38:55 -07:00