Compare commits

...
4825 Commits
Author SHA1 Message Date
Rui Ueyama 57f5c77174 ARC 2025-04-15 16:49:41 +09:00
Rui Ueyama ac6f1ec18e Do not hide foo@@VER if both foo@@VER and foo are defined
Fixes https://github.com/rui314/mold/issues/1442
2025-04-15 12:28:31 +09:00
Rui Ueyama d19f822ec0 Simplify 2025-04-15 11:51:11 +09:00
Rui Ueyama a97a628ee8 Resolve versioned symbols early
Fixes https://github.com/rui314/mold/issues/1440
2025-04-11 14:46:27 +09:00
Rui Ueyama 2888aade4c Refactor 2025-04-10 12:59:13 +09:00
Rui Ueyama 0172f22ab5 Refactor 2025-04-07 17:25:28 +09:00
Rui Ueyama 418d4ff62a Fix CI 2025-04-07 11:26:18 +09:00
Rui Ueyama 5249edc57f Simplify 2025-04-07 10:37:08 +09:00
Rui Ueyama 1870845f88 Refactor 2025-04-07 09:07:12 +09:00
Rui Ueyama d15c41a8dd Process --repro early
If mold crashes before --repro is processed, no .repro.tar file is
created. So we want to process the option as early as possible.
2025-04-07 08:50:26 +09:00
Rui Ueyama b7c8a843b2 Ignore --mmap-output-file
For the sake of completeness, --mmap-output-file is ignored just like
--no-mmap-output-file is.
2025-04-03 16:57:37 +09:00
Rui Ueyama 9b77a7ea86 Fix CI 2025-04-03 16:02:20 +09:00
Rui Ueyama af396ad5d9 Add --audit and --depaudit
These are for the sake of compatibility with GNU ld.
2025-04-03 15:36:05 +09:00
Rui Ueyama a2ee7371d5 Handle -mllvm as a synonym for -plugin-opt
Related to https://github.com/rui314/mold/pull/1437
2025-04-03 09:26:17 +09:00
Rui Ueyama c9812cf09f Merge pull request #1436 from christycylee/ignore_no_mmap_output_file
Ignore no-mmap-output-file for compatibility.
2025-04-03 08:59:31 +09:00
Christy Lee e9c070a3c2 Ignore no-mmap-output-file for compatibility. 2025-04-02 11:39:53 -07:00
Rui Ueyama 02e75be9fa Simplify 2025-04-02 21:55:17 +09:00
Rui Ueyama d5609a9bb8 Fix CI 2025-04-02 18:28:37 +09:00
Rui Ueyama 5d24db5a64 Handle COMDAT symbols in LTO IR object files
Before 9306f69a61, we completely ignored
duplciate symbol errors in IR object files. After that commit, we've
been accidentally reporting duplicate comdat symbols as errors.

Fixes https://github.com/rui314/mold/issues/1434
2025-04-02 17:54:41 +09:00
Rui Ueyama aeec8baee5 Revert "Take r_delta into account when computing distance"
This reverts commit b74a771886
because it broke buildbots.
2025-04-02 10:48:57 +09:00
Rui Ueyama b74a771886 Take r_delta into account when computing distance 2025-04-01 16:56:21 +09:00
Rui Ueyama 0124058ef7 Refactor 2025-03-26 20:56:04 +09:00
Rui Ueyama e302a2509c Fix CI 2025-03-26 20:56:02 +09:00
Rui Ueyama f70db66373 Use std::ranges 2025-03-26 20:26:51 +09:00
Rui Ueyama 9c0cbc8e6c Fix R_AARCH64_PREL16 range 2025-03-25 18:01:38 +09:00
Rui Ueyama a9acbd6b6f Refactor 2025-03-24 16:03:52 +09:00
Rui Ueyama b9d65a5787 Update RV32 toolchain 2025-03-24 15:40:06 +09:00
Rui Ueyama 50766f1ad4 Remove endbr32 support
It looks like Linux is going to support CET only on x86-64 (i.e. endbr64),
and it is very unlikely that x86-32 will get CET support. So I'll remove
the instruction from the code we generate for x86-32.
2025-03-23 18:07:21 +09:00
Rui Ueyama 3496ad1291 Update comments 2025-03-22 13:39:54 +09:00
Rui Ueyama 8a3d374251 Simplify 2025-03-22 11:20:07 +09:00
Rui Ueyama 96b2710849 Fix CI 2025-03-20 16:32:29 +09:00
Rui Ueyama a43f3953f0 Do not create redundant range extension thunks
Previously, we created thunks for all PLT function calls.
2025-03-20 13:25:05 +09:00
Rui Ueyama 2bc6ddc41c Refactor 2025-03-19 11:18:15 +09:00
Rui Ueyama f6575d53c1 Report an error if CREL contains addends for REL-type targets
Fixes https://github.com/rui314/mold/issues/1430
2025-03-18 10:52:55 +09:00
Rui Ueyama bf1ec5ac8f Allow very large offsets in SHT_CREL 2025-03-14 15:32:38 +09:00
Rui Ueyama b291100cfe Refactor 2025-03-14 15:05:16 +09:00
Rui Ueyama c43a859a90 Support CREL as input section
Fixes https://github.com/rui314/mold/issues/1427
2025-03-13 15:17:11 +09:00
Rui Ueyama 6e3d0e3a3c Fix build failure on Windows 2025-03-12 14:24:11 +09:00
Rui Ueyama 790ce3f64d Downgrade mimalloc to 2.2.2
mimalloc 3.0.1 cannot be compiled on Windows, so we don't want to stick
with the 2.x series for the time being.
2025-03-12 14:05:35 +09:00
Rui Ueyama cbd7f74c2e Upgrade bundled xxhash to 0.8.3 2025-03-12 13:38:26 +09:00
Rui Ueyama 3fe25fc69d Upgrade bundled mimalloc to 3.0.1 2025-03-12 13:34:39 +09:00
Rui Ueyama 823ef09585 Upgrade bundled blake3 to 1.6.1 2025-03-12 13:32:26 +09:00
Rui Ueyama f20f57060a Upgrade bundled zstd to 1.5.7 2025-03-12 11:44:12 +09:00
Rui Ueyama 0061d53409 Merge pull request #1425 from christycylee/buck_files
Remove extraneous build files
2025-03-11 10:35:56 +09:00
Rui Ueyama 82affb94d8 Fix out-of-bound memory access
Related to https://github.com/rui314/mold/issues/1426
2025-03-10 14:54:17 +09:00
Rui Ueyama 4f782fb7dc Refactor 2025-03-08 17:13:48 +09:00
Rui Ueyama e9eb6020a6 Skip if textrel is prohibited by default 2025-03-08 10:47:29 +09:00
Christy Lee 23a662cbb9 Remove extraneous build files 2025-03-07 14:23:22 -08:00
Rui Ueyama 32c8f6dd61 Bump mold version to 2.37.1 2025-03-07 14:32:02 +09:00
Rui Ueyama c95476d2fe Fix spurious "dupilcate symbol" error for LTO
Fixes https://github.com/rui314/mold/issues/1421
2025-03-07 13:17:37 +09:00
Rui Ueyama 3981f4f3d4 Bump mold version to 2.37.0 2025-03-05 15:36:27 +09:00
Rui Ueyama d4ad627919 Fix test 2025-03-05 14:22:32 +09:00
Rui Ueyama befe780cf8 Make --discard-section a hidden experimental option 2025-03-05 14:15:19 +09:00
Rui Ueyama 879fe682ee Check if TLSDESC is actually supported 2025-03-05 14:14:38 +09:00
Rui Ueyama 805a8b2b62 Install binary packages if available 2025-03-05 14:14:38 +09:00
Rui Ueyama ec360760d6 Merge pull request #1423 from christycylee/discard-section
Discard section
2025-03-05 14:14:33 +09:00
Christy Lee 30541fc1e8 Add --discard-section feature 2025-03-04 12:49:03 -08:00
Rui Ueyama 9ebd889a73 Use actions/checkout@v4 2025-03-03 17:49:59 +09:00
Rui Ueyama f15bd7537e Fix CI 2025-03-03 11:54:00 +09:00
Rui Ueyama f2ac49824c Fix CI 2025-03-03 10:45:35 +09:00
Rui Ueyama 716fb9c06d Merge pull request #1422 from LarsGullik/lto-dep-file
Remove temporary lto files from dependency-file
2025-03-03 10:45:09 +09:00
Rui Ueyama 50231607f9 Improve comments 2025-03-03 09:53:11 +09:00
Lars Gullik Bjønnes fb7a650186 Mark lto temporary files to not be a dependency
Removes the temporary file created by the compiler
from the dependency list created with --dependency-file.

Without this build systems will never report "Nothing to do",
but always do a re-link of the final object.
2025-03-03 01:10:19 +01:00
Lars Gullik Bjønnes a399548dfa Add test for lto in combination with depencency-file
There should not be any temporary files listed
as dependencies.
2025-03-03 00:39:31 +01:00
Rui Ueyama 11a62121e3 Expand a comment 2025-02-28 16:15:07 +09:00
Rui Ueyama a067b0106b Refactor 2025-02-28 16:15:07 +09:00
Rui Ueyama 7607ad6371 Refactor 2025-02-27 09:14:37 +09:00
Rui Ueyama eab8217962 Ensure that the assembler emits desired relocations 2025-02-27 09:10:13 +09:00
Rui Ueyama f46959819b Run more tests on CI 2025-02-26 17:31:38 +09:00
Rui Ueyama a17202d2b5 Support R_X86_64_CODE_6_GOTTPOFF
R_X86_64_CODE_5_{GOTPCRELX,GOTTPOFF,GOTPC32_TLSDESC} and
R_X86_64_CODE_6_{GOTPCRELX,GOTPC32_TLSDESC} are defined just for
completeness (*), so we've implemented all APX relocations with
this change.

* https://gitlab.com/x86-psABIs/x86-64-ABI/-/merge_requests/53
2025-02-26 16:29:32 +09:00
Rui Ueyama 83152acc8b Support R_X86_64_CODE_4_{GOTPCRELX,GOTTPOFF,GOTPC32_TLSDESC}
These relocations are for Intel APX (Advanced Performance Extension)
that extends the number of general-purpose registers from 16 to 32.
GNU assembler that comes with GCC 14 or newer can compile the test code.
2025-02-26 15:59:04 +09:00
Rui Ueyama 88ea3a1aa5 Update LoongArch cross toolchain 2025-02-25 19:58:50 +09:00
Rui Ueyama 0302affc11 Attempt to fix CI 2025-02-25 13:39:17 +09:00
Rui Ueyama 34986d26df Attempt to fix CI 2025-02-25 13:04:26 +09:00
Rui Ueyama 1fbbcec3da Support R_ARM_THM_JUMP8 2025-02-25 11:32:44 +09:00
Rui Ueyama 9ae7e700fa Use gcr.io instead of docker.io 2025-02-23 22:18:23 +09:00
Rui Ueyama f496c31008 Refactor 2025-02-23 21:52:59 +09:00
Christy Lee 48a84176ac Add --discard-section feature 2025-02-21 13:52:16 -08:00
Rui Ueyama 7fe4bee499 Merge pull request #1418 from christycylee/centos 2025-02-21 08:00:36 +09:00
Christy Lee 015d5388a0 Allow installing dependencies on centos 2025-02-20 13:39:04 -08:00
Rui Ueyama 9306f69a61 Report a "symbol duplication" error for LTO
Fixes https://github.com/rui314/mold/issues/1414
2025-02-17 17:03:42 +09:00
Rui Ueyama b82028d45d Merge pull request #1277 from perseoGI/conan/update-readme 2025-02-13 19:43:17 +09:00
PerseoGI 123faa82dc Update readme redirecting to conan website with mold instructions 2025-02-13 11:23:14 +01:00
Rui Ueyama 93f540a10a Use x86 GitHub runners
It looks like Qemu on ARM64 is unstable on ARM64 runners. I observed
occasional failures with SEGV.
2025-02-13 09:31:32 +09:00
Rui Ueyama 143d447a66 Take sentinel into account when estimating section size 2025-02-09 14:34:56 +09:00
Rui Ueyama 8b089859ee Improve tests 2025-02-09 14:22:54 +09:00
Rui Ueyama 4b754fd944 [ARM32] Emit the sentinel in .ARM.exidx 2025-02-09 13:40:07 +09:00
Rui Ueyama b9f938e801 Improve tests 2025-02-09 11:47:12 +09:00
Rui Ueyama 6e50f3a5e7 Remove a redundant test 2025-02-09 11:38:48 +09:00
Rui Ueyama c2df589e05 Skip a test 2025-02-09 11:18:05 +09:00
Rui Ueyama 247ae9500c Fix tests 2025-02-09 10:43:34 +09:00
Rui Ueyama 85e8d4179e Use ARM64 runners because they are faster than x86 runners
I believe this is just due to the lower number of users on ARM64
runners compared to x86. However, based on my measurements, ARM64
builds all binaries in 1h30m, whereas x86 takes 2h30m.
2025-02-09 10:14:05 +09:00
Rui Ueyama 9185ee4b05 [PPC64V1] Garbage-collect text sections 2025-02-09 10:11:45 +09:00
Rui Ueyama 16f75990f9 [ARM32] Garbage-collect .ARM.exidx sections 2025-02-09 10:11:45 +09:00
Rui Ueyama 34053cc52e Fix tests 2025-02-09 10:11:45 +09:00
Rui Ueyama 810946130d Collect generated files on test failure 2025-02-09 08:48:18 +09:00
Rui Ueyama 33b6f3dee9 Rename a test 2025-02-09 07:35:44 +09:00
Rui Ueyama 14a276ecde Set pipefail to test rigorously
We need to stop using `grep -q` because grep terminates immediately after
finding the first match with `-q`, causing SIGPIPE to the process on the
other side of the pipe.
2025-02-09 07:33:54 +09:00
Rui Ueyama 245d265b4b Simplify 2025-02-08 19:28:39 +09:00
Rui Ueyama 0619541234 Simplify 2025-02-08 18:41:01 +09:00
Rui Ueyama 8f57d2affd Simplify 2025-02-08 18:15:07 +09:00
Rui Ueyama 501f66b24c Report duplicate symbol errors even if --gc-sections is given
Fixes https://github.com/rui314/mold/issues/1414
2025-02-08 13:50:06 +09:00
Rui Ueyama 6ef9ffb81a Fix CI 2025-02-08 13:50:06 +09:00
Rui Ueyama 9ab2c31086 Improve tests 2025-02-08 13:35:43 +09:00
Rui Ueyama 182bd7b68c Refactor 2025-02-08 13:00:08 +09:00
Rui Ueyama 09e205d11e Make $plt symbols local
Related to https://github.com/rui314/mold/issues/1413
2025-02-08 11:46:23 +09:00
Rui Ueyama 7e5e396aae Add a missing entry 2025-02-07 23:14:27 +09:00
Rui Ueyama b8914d0a94 Avoid cache line false sharing 2025-02-07 09:46:20 +09:00
Rui Ueyama 359e5134c9 Refactor 2025-02-05 22:16:03 +09:00
Rui Ueyama 4ed6f48f55 Refactor 2025-02-05 18:53:11 +09:00
Rui Ueyama 48beed9fdf Refactor 2025-02-05 18:20:10 +09:00
Rui Ueyama 42cc55e6d9 Update mold.1 (automated commit) 2025-02-03 02:33:40 +00:00
Rui Ueyama 04103ae60a Fix typo 2025-02-03 11:24:09 +09:00
Rui Ueyama 0966f1858c Refactor 2025-02-03 11:24:05 +09:00
Rui Ueyama 56748ed199 Refactor 2025-02-02 18:54:27 +09:00
Rui Ueyama 11387b3c19 Fix relocations for the large code model 2025-02-02 18:53:46 +09:00
Rui Ueyama 04d71affd1 Define __rela_iplt_{start,end} as absolute symbols if not necessary
Previously, these symbols were defined relative to a section. That is
logically correct, because the runtiem is supposed to apply IREL
relocs between `__rela_iplt_start` and `__rela_iplt_end`, so their
actual locations shouldn't matter if there's no IREL relocs (i.e. they
refer to the same location.)

However, under some circumstances, glibc reads `__rela_iplt_start`
before applying base relocations and `__rela_iplt_end` after applying
them due to compiler instruction reordering.

Therefore, we need to make them absolute symbols that don't require
base relocations.

Fixes https://github.com/rui314/mold/issues/1407
2025-02-02 10:54:33 +09:00
Rui Ueyama 6cb2f31236 Refactor 2025-02-02 10:54:33 +09:00
Rui Ueyama 01392bd53a Use Debian 9 as the base image
It's year of 2025, so a distro from 2017 should be old enough to build
our binary distribution.
2025-01-31 20:25:14 +09:00
Rui Ueyama 7cb0b817f5 Fully quailify container image URLs for better compatibility 2025-01-31 16:00:03 +09:00
Rui Ueyama ea38c1544f Upgrade upload-artifcat action 2025-01-31 11:23:14 +09:00
Rui Ueyama 80a2d24948 Compress debug sections in background
If both --separate-debug-info and --compress-debug-info are given, we want to
compress debug sections in background so that the delay caused by compression
is not visible to users.
2025-01-31 10:26:35 +09:00
Rui Ueyama ded9292ba9 Merge pull request #1409 from 0x2Adr1/compress_debug_sections_separate_debug_file
Honor --compress-debug-sections with --separate-debug-file
2025-01-31 10:21:39 +09:00
Adrien Garin 6d1c96f34b Add --no-detach 2025-01-30 07:31:00 -06:00
Rui Ueyama 0849789fd5 Build loongarch64 binaries 2025-01-30 18:06:31 +09:00
Rui Ueyama 7f771d6ed9 Fix test 2025-01-30 18:05:56 +09:00
Rui Ueyama b8a46ede02 Merge pull request #1406 from sicherha/skip_s390x_tests_with_buggy_gcc
[ELF][S390X] Skip tests that fail due to buggy code produced by GCC
2025-01-30 18:03:46 +09:00
Adrien Garin bab7dd1b2e Honor --compress-debug-sections with --separate-debug-file 2025-01-29 11:54:46 -06:00
Rui Ueyama ebe887f0ae Update README 2025-01-29 13:07:01 +09:00
Rui Ueyama df30516630 Unbreak build-all buildbot 2025-01-29 10:07:28 +09:00
Rui Ueyama e8101a4d8a Use the ARM64 builder to build ARM32 binary
I didn't know if Azure ARM64 servers support ARM32 instructions, but
apparently they do because running ARM32 code is much faster on ARM64
GitHub Actions runners.
2025-01-29 08:37:52 +09:00
Rui Ueyama 6291f1b86c Add an entry for Rocky Linux 2025-01-28 11:34:59 +09:00
Christoph Erhardt a570e8953c [ELF][S390X] Skip tests that fail due to buggy code produced by GCC
`bno-symbolic` and `canonical-plt` still fail with GCC 15.
`rodata-name` started failing with GCC 14.
2025-01-24 21:03:07 +01:00
Rui Ueyama 5cc0e9d0a1 Build ARM64 binary on push 2025-01-24 09:47:34 +09:00
Rui Ueyama 4bb8e03b24 Build an ARM64 binary on a native ARM64 host
This change speeds up building an ARM64 binary on a GitHub Actions runner.
2025-01-22 20:56:10 +09:00
Rui Ueyama bcadb4e30f Refactor 2025-01-21 13:43:28 +09:00
Rui Ueyama a2eda6acc4 [RISC-V] Do not leave a useless ld instruction
ld may cause a fault at runtime, so we want to make sure that that is
replaced with a nop if relaxed.
2025-01-21 13:25:09 +09:00
Rui Ueyama e60e04feb2 Fix Windows build
Cherrypick https://github.com/microsoft/mimalloc/commit/5764845c4d3d9fe77ae3c2fbfcc2beedce368b1d
to fix Windows CI.
2025-01-21 08:01:50 +09:00
Rui Ueyama 3651dba6ef Upgrade bundled mimalloc to 2.1.9 2025-01-20 20:18:10 +09:00
Rui Ueyama c20d027441 Refactor 2025-01-20 20:18:10 +09:00
Rui Ueyama 66b5ed66c6 [ARM32] Increase the default page size to 64 KiB
... to maximize compatibility with broader hardware.
2025-01-20 20:16:38 +09:00
Rui Ueyama 0b747d8334 Merge pull request #1404 from kei-gnu/upgrade-checkout-actions
Upgrade checkout actions
2025-01-20 18:49:48 +09:00
kei-gnu 73f86aeadd upgrade checkout actions 2025-01-20 10:52:05 +09:00
Rui Ueyama ceee495584 Fix R_ARM_THM_JUMP19 2025-01-20 09:22:58 +09:00
Rui Ueyama 3d89c1181b Refactor 2025-01-19 21:31:34 +09:00
Rui Ueyama f014a1d015 Read R_ARM_THM_JUMP19 relocation addends 2025-01-19 21:27:01 +09:00
Rui Ueyama f25e450f2b Show "LTO plugin missing" error correctly
Fixes https://github.com/rui314/mold/issues/1403
2025-01-19 12:09:42 +09:00
Rui Ueyama 1fbc6f3dec Refactor 2025-01-19 10:38:38 +09:00
Rui Ueyama 4679573654 Refactor 2025-01-19 10:32:40 +09:00
Rui Ueyama af608f5651 Fix CI 2025-01-17 23:06:07 +09:00
Rui Ueyama 5a9c465210 Fix CI 2025-01-17 21:41:41 +09:00
Rui Ueyama 1822e47a43 Make -z dynamic-undefined-weak work for executable
Fixes https://github.com/rui314/mold/issues/1401
2025-01-17 19:44:40 +09:00
Rui Ueyama 06f20e9d69 Add new x86-64 relocations
These relocations are for Intel Advanced Performance Extensions.
The real implementation will be added once major compilers start
supporting APX.
2025-01-17 08:49:06 +09:00
Rui Ueyama 8929bd4a8d Fix test
Fixes https://github.com/rui314/mold/issues/1400
2025-01-17 08:40:58 +09:00
Rui Ueyama 3b1e2a9aa3 Rename a function 2025-01-15 11:22:11 +09:00
Rui Ueyama 721eafc7dd Refactor 2025-01-15 09:38:55 +09:00
Rui Ueyama 4de8daf34f Fix typo 2025-01-15 09:38:55 +09:00
Rui Ueyama f7624ee1f9 Simplify 2025-01-15 08:15:35 +09:00
Rui Ueyama 500416f8f6 Improve test 2025-01-15 07:50:56 +09:00
Rui Ueyama c6c12d43f5 Fix CI 2025-01-14 14:08:22 +09:00
Rui Ueyama 7fc2a6e935 Fix CI 2025-01-14 13:25:32 +09:00
Rui Ueyama 9fe8831db3 Fix CI 2025-01-14 12:41:29 +09:00
Rui Ueyama 2bb42badde Do not emit bad dynamic relocations when sections are shrunk 2025-01-14 11:42:40 +09:00
Rui Ueyama 48077dd91a Refactor 2025-01-11 21:28:01 +09:00
Rui Ueyama cf0d750734 Set the basename of an output path to .gnu.version_d 2025-01-11 19:49:36 +09:00
Rui Ueyama 48dd767ad3 Refactor 2025-01-11 19:47:50 +09:00
Rui Ueyama 3c89ad66a2 Refactor 2025-01-11 17:44:55 +09:00
Rui Ueyama 8cd5574bfb Use shrink_to_fit instead of = {} assignment
I'm no C++ expert, but it looks like `vec = {}` is not guaranteed to
release memory.
2025-01-11 14:01:10 +09:00
Rui Ueyama 0ca543e104 Optimize create_output_section() 2025-01-11 13:12:53 +09:00
Rui Ueyama e5f80fd822 Refactor 2025-01-11 13:12:53 +09:00
Rui Ueyama fe8e061427 Refactor
This new logic was found by ChatGPT o1 pro.
2025-01-10 17:34:00 +09:00
Rui Ueyama 05ceb7da0d Revert "Build daily binary for loongarch64"
This reverts commit 12a141b03b to unbreak
buildbots.
2025-01-10 17:26:34 +09:00
Rui Ueyama 3cec2e68be Upgrade Clang 2025-01-10 10:50:44 +09:00
Rui Ueyama 12a141b03b Build daily binary for loongarch64 2025-01-10 09:37:43 +09:00
Rui Ueyama 562361345b Use the latest version of clang 2025-01-10 08:09:58 +09:00
Rui Ueyama 432ffeabf5 Fix typo 2025-01-10 07:59:05 +09:00
Rui Ueyama be0870719f Check if test system supports TLSDESC 2025-01-09 22:12:24 +09:00
Rui Ueyama a66750b1ec Update README.md 2025-01-09 21:06:26 +09:00
Rui Ueyama c3a957c4dc Bump mold version to 2.36.0 2025-01-09 12:53:32 +09:00
Rui Ueyama f193d2b603 Format 2025-01-09 12:53:32 +09:00
Rui Ueyama d2859f597c Simplify 2025-01-09 11:51:58 +09:00
Rui Ueyama 06a21efbdb Improve a test 2025-01-08 17:40:52 +09:00
Rui Ueyama 13aa1685c9 Update mold.1 (automated commit) 2025-01-08 07:00:45 +00:00
Rui Ueyama 55fcd3facf Document --package-metadata 2025-01-08 15:58:11 +09:00
Rui Ueyama 5d454308f2 Remove BitVector and use std::vector<bool>
Even though std::vector<bool> is often critisized for being inconsistent
with other std::vector<T> where T != bool, it suffices for our purpose.
2025-01-08 13:51:21 +09:00
Rui Ueyama a01fe171d0 Refactor 2025-01-08 11:11:16 +09:00
Rui Ueyama 207c4e99f0 Pass --pids-limit=-1 to podman
Without it, fork(2) may fail with EAGAIN inside podman containers.
2025-01-07 16:13:48 +09:00
Rui Ueyama 0dfdc014e2 Change the path of mold binary 2025-01-07 13:24:06 +09:00
Rui Ueyama eec3f6b716 [RISC-V] Fix R_RISCV_HI20 relaxation
We didn't compensate LO12's sign extension when computing the range.
This resulted in a wrong relaxation that breaks the output binary.
2025-01-07 11:41:22 +09:00
Rui Ueyama a483530a3c Refactor 2025-01-07 11:41:22 +09:00
Rui Ueyama 0d1068e460 Refactor 2025-01-06 22:31:06 +09:00
Rui Ueyama fd0fc9a3cf Refactor 2025-01-06 22:27:33 +09:00
Rui Ueyama 40b881b7bb Simplify 2025-01-06 16:41:48 +09:00
Rui Ueyama 35cde381b7 Refactor 2025-01-06 15:41:25 +09:00
Rui Ueyama 6d8c5ca90b Fix symbol size computation 2025-01-06 13:50:15 +09:00
Rui Ueyama aa4d065fde Do not call get_r_delta() unless necessary
get_r_delta performs a binary search on a vector, so it's not cheap.
If we can avoid calling that function, we should.
2025-01-06 13:36:24 +09:00
Rui Ueyama 0af930ae28 Refactor 2025-01-06 11:07:00 +09:00
Rui Ueyama d29fabf084 Refactor 2025-01-05 22:40:46 +09:00
Rui Ueyama 2ee1d47ca8 Do not add useless entries to r_deltas 2025-01-05 20:52:59 +09:00
Rui Ueyama 8e27616934 Include the number of code-shrinking relocations into the output of `--stats' 2025-01-05 20:12:31 +09:00
Rui Ueyama a7b8c6061a Ensure that the first byte of .dynsym is '\0' 2025-01-05 19:48:46 +09:00
Rui Ueyama aef5f3231c Refactor 2025-01-05 15:31:25 +09:00
Rui Ueyama 38ae2990a0 Refactor 2025-01-05 14:53:50 +09:00
Rui Ueyama e6345d5b14 Reflect the result of code-shrinking relaxation to symbol sizes 2025-01-05 13:49:07 +09:00
Rui Ueyama ba35344bd0 Add a comment 2025-01-05 12:50:50 +09:00
Rui Ueyama c33ca0b001 Refactor 2025-01-05 11:09:45 +09:00
Rui Ueyama 77935f1807 Accept very large input text sections 2025-01-04 22:11:24 +09:00
Rui Ueyama 3234d88600 [RISC-V][LoongArch] Reduce memory usage for shrinking sections
Previously, 4 bytes were allocated for each relocation in a text
section to store the number of bytes removed before each relocation.
Now, only the locations where bytes are removed are stored.

This commit improves performance by ~4% when linking clang-19 for RISC-V.
2025-01-04 21:12:02 +09:00
Rui Ueyama 1e8cee85bb Name each thunk symbol unique name
Previously, if symbol `foo` appears more than once in multiple thunks,
they got the same name `foo$thunk`. Now, they are named `foo$thunk0`,
etc.
2025-01-03 17:37:17 +09:00
Rui Ueyama 2352ec647d Fix a range extension thunk creation issue
Previously, we failed to create range extension thunks if we have
a very large input section.
2025-01-03 17:37:17 +09:00
Rui Ueyama 88d5e74825 Refactor 2025-01-03 17:37:17 +09:00
Rui Ueyama d884620f9d Attempt to fix buildbots 2025-01-03 14:28:04 +09:00
Rui Ueyama e55363ec8a Attempt to fix CI 2025-01-03 13:32:00 +09:00
Rui Ueyama a297859c53 Emit an IRELATIVE relocation instead of GLOB_DAT for an ifunc in DSO
Fixes https://github.com/rui314/mold/issues/1385
2025-01-03 12:53:34 +09:00
Rui Ueyama 0a112d0aa9 Refactor 2025-01-03 10:52:37 +09:00
Rui Ueyama 6a342f2c64 Refactor 2025-01-03 09:15:55 +09:00
Rui Ueyama d0bcd35bf5 Add a safety margin when computing branch offsets 2025-01-02 21:34:47 +09:00
Rui Ueyama f609510e3c Refactor 2025-01-02 21:21:25 +09:00
Rui Ueyama 9fc0ace817 Reduce memory usage of range extension thunks
Previously, we allocate 4 byte struct for each relocation to store a
reference to a thunk in case the relocation needs to branch to a thunk.
Most references are null because most relocations don't need thunks.

This commit changes how we manage references to range extension thunks.
Now, thunk addresses are stored to symbols rather than to relocations.

Linking clang-19 for ARM64 is now ~7% faster than before.
2025-01-02 18:09:45 +09:00
Rui Ueyama 89f3ba89da Refactor 2025-01-02 12:05:00 +09:00
Rui Ueyama 09e7616186 Refactor 2025-01-01 08:43:38 +09:00
Rui Ueyama 2342938cea Simplify 2024-12-31 21:43:28 +09:00
Rui Ueyama 047675b762 Unbreak ARM32 buildbot 2024-12-31 17:15:17 +09:00
Rui Ueyama 531e43eddf Do not mark DSOs as needed if they are referenced only indirectly
Fixes https://github.com/rui314/mold/issues/1395
2024-12-31 17:15:15 +09:00
Rui Ueyama 50a75c25e3 Refactor 2024-12-31 17:15:14 +09:00
Rui Ueyama 7a69bd45ac Refactor 2024-12-30 23:18:25 +09:00
Rui Ueyama 006de74706 Merge .rodata.cst.<symbol-name>.cst<N> sections to .rodata.cst<N> 2024-12-30 14:43:09 +09:00
Rui Ueyama 952fdde7ae Add a relocation overflow check 2024-12-30 11:12:17 +09:00
Rui Ueyama dfce2fc8fa [s390x] Reserve _GLOBAL_OFFSET_TABLE_[2]
ELF Application Binary Interface s390x Supplement Version 1.6.1, p.58 says
that "The doublewords at _GLOBAL_OFFSET_TABLE_[1...2] are reserved for
system use."

We had previously reserved GOT[0] and GOT[1], but we did not reserve GOT[2].

It's most likely that GOT[2] is not actually in use, as it appears that
mold-linked programs work without it. But we need to adhere to the psABI.
2024-12-30 09:05:10 +09:00
Rui Ueyama 50fd4beb3e [s390x] Relax GOT-loading LGRL instructions 2024-12-30 07:55:55 +09:00
Rui Ueyama 0b8090994b Simplify 2024-12-29 10:02:29 +09:00
Rui Ueyama 37e6d2f4cb Merge pull request #1394 from sicherha/fix_ifunc-alias_test_on_RHEL10
Fix `arch-x86_64-ifunc-alias` test on RHEL 10
2024-12-28 19:26:21 +09:00
Christoph Erhardt 0c06bef82b Fix arch-x86_64-ifunc-alias test on RHEL 10
On RHEL 10, GCC is configured with the `--with-arch_64=x86-64-v3`
option, which makes it implicitly use the `-march=x86-64-v3`
command-line flag by default.

This breaks the `arch-x86_64-ifunc-alias` test: since the `x86-64-v3`
microarchitecture level includes SSSE3 and AVX2, GCC appears to
interpret the `default` and `ssse3,avx2` targets as the same thing, and
omits generating a resolver function.

Fix the test by forcing GCC's target architecture to the `x86-64`
baseline.
2024-12-28 10:47:07 +01:00
Rui Ueyama 53dbfd96de Make Ctrl-C work for dist.sh 2024-12-28 18:40:15 +09:00
Rui Ueyama 938f145150 Attempt to fix CI 2024-12-27 22:35:00 +09:00
Rui Ueyama 930ba5a7f1 Do not compress .tar.gz with zip 2024-12-27 22:35:00 +09:00
Rui Ueyama 4107c336a8 Simplify 2024-12-27 22:15:25 +09:00
Rui Ueyama d4db31ceaf Merge pull request #1389 from sicherha/improvement_lambdas_and_ranges
Small improvements: lambdas and ranges
2024-12-27 19:33:03 +09:00
Rui Ueyama 30f68106db Merge pull request #1391 from sicherha/debian_11_CI_pipeline
Add CI pipeline for Debian 11
2024-12-27 19:32:24 +09:00
Rui Ueyama e56fc35820 Attempt to unbreak GitHub Actions 2024-12-27 19:27:36 +09:00
Rui Ueyama b8fa19bf24 Merge pull request #1392 from chinrw/dev
Try again to use Podman instead of Docker
2024-12-27 18:30:27 +09:00
Ruowen Qin d9bd1468d0 Try again to use Podman instead of Docker
Switch from Docker to Podman for container builds and remove unused
buildx steps. Also this commit updates GitHub Actions workflows to use
redhat-actions/podman-login and docker/setup-qemu-action@v3, removing
references to Docker Buildx.

Fixes: ec1d7120aa ("Use docker only on GitHub Actions")
Signed-off-by: Ruowen Qin <[email protected]>
2024-12-27 17:11:22 +08:00
Christoph Erhardt b5dfab17da Add CI pipeline for Debian 11
Debian 11 ships GCC 10 and CMake 3.18, which happen to be precisely the
minimum versions required for building mold from source.

Add a CI pipeline to prevent future commits from inadvertently breaking
compatibility with older toolchains.
2024-12-27 08:50:42 +01:00
Christoph Erhardt 7d1c970a39 Make non-capturing lambdas actually non-capturing 2024-12-27 08:37:48 +01:00
Rui Ueyama e6e1cfac31 Handle "L0^A" symbol as local
I don't know about the details, but it looks like "L0^A" is sometimes
used as a local symbol name.
2024-12-27 16:35:43 +09:00
Rui Ueyama 38bca63747 Make the source directory read-only for the build script
So that even a malicious container cannot silently modify our
source files.
2024-12-27 06:29:01 +09:00
Rui Ueyama 606ce43c5b Add loongarch64 support 2024-12-27 06:15:29 +09:00
Rui Ueyama 41413f9d7c Refactor 2024-12-26 20:42:39 +09:00
Rui Ueyama ec1d7120aa Use docker only on GitHub Actions
I don't know how to fix the build breakage on GitHub, so let's keep
using Docker there.
2024-12-26 19:56:26 +09:00
Rui Ueyama bcce7091e7 Run build-x86 GitHub Action on push to any branch 2024-12-26 18:03:55 +09:00
Rui Ueyama e3cb2aa09e Use podman instead of docker
I prefer podman over docker because podman works without the daemon
and doesn't need the root priviledge.
2024-12-26 17:10:03 +09:00
Rui Ueyama 7e7d75fb4b Format 2024-12-26 17:08:52 +09:00
Rui Ueyama e333e435bd Merge pull request #1388 from sicherha/improvement_cleanup
Miscellaneous small cleanups
2024-12-26 17:08:43 +09:00
Christoph Erhardt afd2fab630 Replace putenv() with setenv()
The use of `putenv()` is discouraged for portability reasons:
https://pubs.opengroup.org/onlinepubs/9799919799/functions/putenv.html
2024-12-25 19:17:17 +01:00
Christoph Erhardt 26493c0ca8 Replace stat() with equivalent std::filesystem calls 2024-12-25 19:17:17 +01:00
Christoph Erhardt 9402ca357c Construct std::vector elements in place
This is slightly more efficient than creating the objects and
subsequently copying them into the vector.
2024-12-25 19:17:17 +01:00
Christoph Erhardt 5572679c2d Remove duplicate if-case
Reported by clang-tidy: the same code already exists 50 lines below this
one.
2024-12-25 13:49:42 +01:00
Rui Ueyama 179d5d4b5c Merge pull request #1387 from sicherha/improvement_includes 2024-12-25 20:32:40 +09:00
Christoph Erhardt f169f1c45c Reorganise TBB #includes
Add missing `#include`s and remove unused ones.
2024-12-25 11:41:04 +01:00
Christoph Erhardt e05f3b5362 Include the C++ variant of C headers 2024-12-25 11:41:02 +01:00
Christoph Erhardt a5b3a22517 Remove unused #includes 2024-12-25 11:40:29 +01:00
Rui Ueyama 82263dce4d Merge pull request #1386 from jinghao-jia/main
Restore executable overwriting behavior on Linux 6.13 or later
2024-12-25 18:12:38 +09:00
Jinghao Jia 1a012dda4d Restore executable overwriting behavior on Linux 6.13 or later
Linux upstream has reverted commit 2a010c412853 ("fs: don't block
i_writecount during exec") and the change is merged in the 6.13 cycle.
This means the executable overwriting behavior can be restored on Linux
kernel version 6.13 or later.

Note that there is probably not much we can do for 6.11 / 6.12 kernels.
Although the reversion is backported, many distros do not use upstream
sub-version numbers which means we cannot determine whether the kernel
has this reversion based on its version number.

Signed-off-by: Jinghao Jia <[email protected]>
2024-12-25 01:55:07 -06:00
Rui Ueyama dfe02f41cb Add a test 2024-12-24 17:16:34 +09:00
Rui Ueyama b582ad3589 Format 2024-12-24 17:16:32 +09:00
Rui Ueyama 2d7b6b23e3 [LoongArch] Increase the max page size from 16 KiB to 64 KiB
Even though 16 KiB is the common page size, the Linux kernel for
LoongArch supports 64 KiB pages. Currently, mold-generated binaries
run only on systems with <=16 KiB page.

Note that unlike GNU ld, increasing the maximum page size doesn't
increase the on-disk binary size of generated binaries.
2024-12-22 17:44:53 +09:00
Rui Ueyama 7ddc8f4654 Rename --encoded-package-metadata to --package-metadata
This is an alternative to https://github.com/rui314/mold/pull/1383

The upcoming version of GNU binutils's ld now treats arguments for
`--package-metadata` as percent-encoded strings and decodes them before
writing to .note.package.

Additionally, GNU ld will support `%[<charname>]`, where `<charname>` can be
`comma`, `lbrace`, `rbrace`, `quot`, or `space`. This feature could improve
readability when manually writing command-line arguments.

That said, I don't believe we need to support these metacharacters, for the
following reasons:

1. This option is specifically designed for distribution package maintainers
   to embed metadata into binaries, and is not intended for general use.

2. Command-line arguments for this option are always generated by build
   scripts, not written manually.

If we need these character names, we can add that later.

Furthermore, GNU ld does not appear to report errors for orphan '%'
characters that are not followed by valid hex values; instead, it simply
passes through such characters. I find this behavior fragile. We will report
an error for invalid '%' characters.

With these considerations in mind, I'll just rename the existing
`--encoded-package-metadata` option to `--package-metadata`.
2024-12-22 10:07:23 +09:00
Rui Ueyama 4bbd93f06f Refactor 2024-12-22 10:07:23 +09:00
Rui Ueyama a76d259c0b Merge pull request #1384 from bdrung/ctest-with-logs 2024-12-22 05:27:57 +09:00
Benjamin Drung a557ea1012 ci: run ctest with --output-on-failure
In case ctest fails in the CI, no error logs are printed. This makes
debugging harder.

So run ctest with `--output-on-failure` to ease debugging in case of
failures.
2024-12-21 20:37:31 +01:00
Rui Ueyama 06f6a56043 Merge pull request #1380 from sicherha/fix_system_mimalloc
Add missing `#include "common.h"` - fixes broken `MOLD_USE_SYSTEM_MIMALLOC`
2024-12-20 10:39:39 +09:00
Christoph Erhardt ac9568f17b Disable mimalloc when a sanitizer is used
Combining mimalloc and AddressSanitizer triggers a segmentation fault in
many tests.

Combining mimalloc and ThreadSanitizer leads to duplicate symbols for
the `new` and `delete`
operators, causing the build to fail.
Example message from a failed GitHub Actions build:
```
mold: error: duplicate symbol:
third-party/mimalloc/libmimalloc-debug.a(alloc.c.o):
/usr/lib/llvm-18/lib/clang/18/lib/linux/libclang_rt.tsan_cxx-x86_64.a(tsan_new_delete.cpp.o):
operator delete(void*, std::align_val_t)
```
2024-12-20 00:03:47 +01:00
Christoph Erhardt 9c9145eb6e Add missing #include "common.h"
This allows the compiler to make sure that the implementation of
`set_mimalloc_options()` matches its declaration.

More importantly, it indirectly pulls in `config.h`, where the macros
`MOLD_USE_SYSTEM_MIMALLOC` and `MOLD_USE_MIMALLOC` are conditionally
defined. Without these, the build configuration is ignored.
2024-12-19 22:06:23 +01:00
Rui Ueyama 3cb551424b Fix CI 2024-12-16 17:27:33 +09:00
Rui Ueyama ee8e50a3f7 Bump mold version to 2.35.1 2024-12-15 13:26:50 +09:00
Rui Ueyama 4bbf85c2ea Refactor 2024-12-13 11:13:06 +09:00
Rui Ueyama 6257f12c1f Simplify 2024-12-12 12:45:53 +09:00
Rui Ueyama ea460af09c Fix function prototypes
Fixes https://github.com/rui314/mold/issues/1370
2024-12-12 12:13:29 +09:00
Rui Ueyama a0f9641ae1 Upgrade BLAKE3 to 1.5.5 2024-12-11 20:13:03 +09:00
Rui Ueyama 9204e1dc12 Upgrade OneTBB to 2022.0.0 2024-12-11 20:13:03 +09:00
Rui Ueyama 396666fd48 Preserve the original relocation order as much as possible 2024-12-11 20:13:03 +09:00
Rui Ueyama 74024ea0df Refactor 2024-12-11 15:22:22 +09:00
Rui Ueyama 79aac78581 Refactor 2024-12-09 18:37:01 +09:00
Rui Ueyama 04066d1c1a [RISC-V] Remove GP-relative relocations
These relocations were deleted from the psABI in
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/commit/ad025461defeb610c684427719ce5ac5e8d8d857.
2024-12-09 18:33:30 +09:00
Rui Ueyama 2a78b1b333 Make ICF deterministic
Fixes https://github.com/rui314/mold/issues/1377
2024-12-09 15:13:20 +09:00
Rui Ueyama 27162691b7 Bump mold version to 2.35.0 2024-12-08 14:58:53 +09:00
Rui Ueyama fe6090efff Revert "Upgrade RV32 toolchain"
This reverts commit c7042f416e because it broke CI.
2024-12-05 18:29:47 +09:00
Rui Ueyama c7042f416e Upgrade RV32 toolchain 2024-12-05 16:44:09 +09:00
Rui Ueyama e56b649968 Increase the maximum retry count for our concurrent hashmap
Fixes https://github.com/rui314/mold/issues/1365
2024-12-05 14:17:56 +09:00
Rui Ueyama 0f56a792c3 Upgrade LoongArch toolchain 2024-12-04 16:06:01 +09:00
Rui Ueyama 5bb914553f Fix typo 2024-11-26 13:21:41 +09:00
Rui Ueyama 26d898e9bd Use macos-latest instead of macos-12
macos-12 has been deprecated.
2024-11-26 07:45:07 +09:00
Rui Ueyama eec3bb4478 Simplify 2024-11-26 07:01:50 +09:00
Rui Ueyama fa3026611b Merge pull request #1373 from bl4ckb0ne/test-x86-variants
test: match more x86 arch name variants
2024-11-26 06:59:21 +09:00
Simon Zeni a649156e0f test: match more x86 arch name variants 2024-11-25 11:06:25 -05:00
Rui Ueyama e2e1146a0b [s390x] Fix .hash section
For whatever reason, the entry size for .hash is 8 bytes insetad of 4 on s390x.

Fixes https://github.com/rui314/mold/issues/1372
2024-11-23 13:20:07 +09:00
Rui Ueyama baf4f76f53 Report an error even without NDEBUG=1 if a ConcurrentMap becomes full 2024-11-02 17:05:01 +09:00
Rui Ueyama 85be067813 Try to silence benign mimalloc warning messages
https://github.com/rui314/mold/issues/1367
2024-10-30 13:29:57 +09:00
Rui Ueyama 8e4f7b5383 Do not ovewrite an existing file if running on Linux 6.11.0 or later
https://github.com/rui314/mold/issues/1361
2024-10-29 16:33:45 +09:00
Rui Ueyama a066efa995 Use madvise(2) if available 2024-10-29 16:01:04 +09:00
Rui Ueyama f184021eca Refactor 2024-10-27 16:42:36 +09:00
Rui Ueyama 0841ffcb20 Refactor 2024-10-20 11:33:38 +09:00
Rui Ueyama 9cf1165a34 Fix CI 2024-10-19 11:33:06 +09:00
Rui Ueyama 9aa4ded614 Remove LICENSE.third-party
We don't need to create a copy of license files for third-party software
as we keep an original license file for each subdirectory. It is probably
a bit risky to create copies of license files because it is easy to become
out-of-sync. So I'll just remove this file.
2024-10-19 11:08:12 +09:00
Rui Ueyama e7e764ccf0 Revert "Refactor"
This reverts commit 5ba5b4960f to fix CI.
2024-10-19 09:47:53 +09:00
Rui Ueyama 5ba5b4960f Refactor 2024-10-18 20:57:07 +09:00
Rui Ueyama bb57289385 Refactor 2024-10-18 18:46:23 +09:00
Rui Ueyama 0e28522b5c Fix filler instruction for sh4be
If running in big-endian mode, SH4 processors expects both data and
instructions to be encoded in big-endian. Therefore, nop need to be
reversed for sh4be.
2024-10-17 16:13:46 +09:00
Rui Ueyama 882e7eb15b Support big-endian ARM64 2024-10-17 12:27:12 +09:00
Rui Ueyama 3a0bb87dfe Refactor 2024-10-17 12:27:10 +09:00
Rui Ueyama 832973cef5 Run a test for -z rewrite-endbr on GitHub Actions 2024-10-16 16:22:51 +09:00
Rui Ueyama 0cb9fc613c Support big-endian SH4
This commit adds experimental big-endian SH4 support. Since we already
support little-endian SH4, it wasn't too difficult to support its big-
endian variant.

Some tests related to C++ exceptions fail due to mysterious errors.
I don't have time to debug it, so I'll disable them for now.

Closes https://github.com/rui314/mold/issues/1273
2024-10-15 14:23:54 +09:00
Rui Ueyama 8931cf81f4 Update mold.1 (automated commit) 2024-10-15 04:49:05 +00:00
Rui Ueyama ecdd0f71b6 Update the man page 2024-10-15 13:48:07 +09:00
Rui Ueyama cb9344fab8 Run tests 2024-10-15 13:48:05 +09:00
Rui Ueyama 382e45ea30 Align .gnu.version_r and .gnu.version_d to 4 byte boundaries
They don't contain 8 byte date items, so they don't need to be aligned
to 8 byte boundaries.
2024-10-11 19:51:52 +09:00
Rui Ueyama fdaa13c374 Merge .gnu.build.attributes sections into a single section
It looks like gold does this.
2024-10-11 19:42:14 +09:00
Rui Ueyama fa2411cc08 Refactor 2024-10-10 10:14:36 +09:00
Rui Ueyama a69b332f86 Enable GC-sections and ICF not only for Release but also for RelWithDebInfo 2024-10-09 21:11:55 +09:00
Rui Ueyama 20dccf2b77 Refactor 2024-10-09 15:59:15 +09:00
Rui Ueyama ffd10dd447 Do not include mimalloc-new-delete.h if mimalloc is disabled
Including mimalloc-new-delete.h overrides new and delete operators
with mimalloc. If a user choose not to use mimalloc, we shouldn't
include that file.

https://github.com/rui314/mold/issues/1355
2024-10-09 14:41:36 +09:00
Rui Ueyama ce9cdb1bae [ICF] Handle RELRO sections correctly
When control reaches here, `output_section` is always a nullptr.
2024-10-08 19:35:03 +09:00
Rui Ueyama 979084b593 Use .llvm_addrsig to find address significance for executable sections
This change should allow more executable sections to be merged by ICF.
2024-10-08 17:47:41 +09:00
Rui Ueyama c562c733ce Move target-dependent data members to the end of class definitions
So that the data layouts for other data members become the same.
This makes ICF work better.
2024-10-08 17:45:25 +09:00
Rui Ueyama 3c6f57cc27 Refactor 2024-10-08 14:57:32 +09:00
Rui Ueyama c16d6e8cc0 Remove to_abs_path
This function is not necessary.

I don't know how it could leak memory, but it was reported
that it does in https://github.com/rui314/mold/issues/1355.
2024-10-08 13:01:12 +09:00
Rui Ueyama 91e2daf3bf Create release binaries with Clang instead of GCC
LLVM/Clang works better with mold's --icf=safe because of the presence
of LLVM address significance table.
2024-10-07 19:29:01 +09:00
Rui Ueyama 7204c6dec8 Do not set a value to relr.dyn section's sh_link
The ELF ABI doesn't say anything about sh_link field of SHT_RELR section,
so setting a value to it is simply wrong.
2024-10-06 15:28:36 +09:00
Rui Ueyama 3441cbb636 Enable GC sections and ICF for binary distributions to reduce file size 2024-10-06 09:49:32 +09:00
Rui Ueyama 3070e798f3 Refactor 2024-10-05 20:05:43 +09:00
Rui Ueyama 754354991b Simplify 2024-10-05 15:37:03 +09:00
Rui Ueyama 86fe020558 Fix CI 2024-10-05 15:13:46 +09:00
Rui Ueyama 40e7b983d6 Fix CI 2024-10-05 14:44:22 +09:00
Rui Ueyama f69ecd616d Merge pull request #1353 from praetorian20/main 2024-10-05 13:03:17 +09:00
Rui Ueyama d683f62e01 Add a rule for KDE Neon
Fixes https://github.com/rui314/mold/issues/1354
2024-10-05 12:44:20 +09:00
Ashish Sadanandan 205a091924 Use readelf for compress-debug-sections verification
RHEL 8.7's version of dwarfdump (2018-01-29) is too old to recognize the
SHF_COMPRESSED flag in debug info, so the compress-debug-sections test
fails despite the debug sections being compressed as intended.

To fix this, we will use readelf to dump information about the
executable. The COMPRESSED flag can be verified using this.
2024-10-04 20:44:05 -06:00
Rui Ueyama 7b4d2e77ee Refactor 2024-10-05 10:08:23 +09:00
Rui Ueyama 2c9ba071bc Refactor 2024-10-04 20:47:50 +09:00
Rui Ueyama de65f6bd75 Bump mold version to 2.34.1 2024-10-04 15:00:22 +09:00
Rui Ueyama 186272a425 Handle R_ARM_TARGET1 as a synonym for R_ARM_ABS32
This fixes a regression introduced in 431fc39db0.

Fixes https://github.com/rui314/mold/issues/1351
2024-10-04 14:18:13 +09:00
Rui Ueyama 5fcbf25260 Refactor 2024-10-03 15:19:47 +09:00
Rui Ueyama 16eb5139f1 [RISC-V] Set DT_RISCV_VARIANT_CC if there's a dynamic symbol with STO_RISCV_VARIANT_CC 2024-10-02 20:41:13 +09:00
Rui Ueyama 35be7ba887 Refactor 2024-10-02 20:39:50 +09:00
Rui Ueyama 55f0289a41 Non-SHF_ALLOC sections' addresses should be displayed as zero for --Map 2024-09-30 13:28:22 +09:00
Rui Ueyama 36dd6babe1 Refactor 2024-09-29 19:04:22 +09:00
Rui Ueyama 91b6818b62 Revert "Refactor"
This reverts commit 9e9539144e because
the new code didn't compile on macOS.
2024-09-27 21:45:49 +09:00
Rui Ueyama 9e9539144e Refactor 2024-09-27 17:51:54 +09:00
Rui Ueyama feb9b3eb4e Set 0 to DT_AARCH64_VARIANT_PCS
It looks like only the presence of the entry is important, but by
convention, GNU ld and lld set 0 to a DT_AARCH64_VARIANT_PCS dynamic
entry, so we should follow suit.
2024-09-27 17:51:54 +09:00
Rui Ueyama 4b3fc4e82a Refactor 2024-09-27 17:51:54 +09:00
Rui Ueyama ed7cc1b85a Bump mold version to 2.34.0 2024-09-25 10:01:39 +09:00
Rui Ueyama 3711ddb95e Drop DEC Alpha processor support
Keeping DEC Alpha support is difficult because there are no Alpha
machines available for toolchain developers, and even if there were,
no modern Linux distros still support Alpha. For example, Debian
dropped Alpha support in Debian 6.0. As a result, I cannot test my
linker with real-world programs.

In fact, I believe mold has never been able to link real-world large
programs. Object files for Alpha are compiled with the small code
model by default, so it is not easy to support it in the linker.

There's no means to verify that my implementation is correct for Alpha
because Alpha's psABI has never been published by DEC. The most
"reliable" source of correctness is GNU ld's source code and comments.

Last but not least, I believe there are literally zero mold/Alpha
users. Unlike some other retro computers like the m68k, Alpha doesn't
seem to get much love from the community, perhaps because the
availability of Alpha machines was limited in the first place, even in
the 90s.

Therefore, I'll remove Alpha support now. If there's someone who wants
to keep it, we can resurrect and re-test it.

This change should make the mold binary size a little smaller.
2024-09-24 17:29:34 +09:00
Rui Ueyama 0ee12e4115 Do not strip linker-synthesized symbols when --retain-symbols-file is given
This is an attempt to fix https://github.com/rui314/mold/issues/1346
2024-09-21 17:08:32 +09:00
Rui Ueyama 87c9929df9 Merge pull request #1345 from andreas-schwab/main 2024-09-19 17:32:46 +09:00
Andreas Schwab f5f14d3faa test/absolute-symbols.sh: move symbol address out of the heap
Fixes #1340

Signed-off-by: Andreas Schwab <[email protected]>
2024-09-19 09:53:41 +02:00
Rui Ueyama 5be5ea9ff5 Fix CI 2024-09-18 15:18:44 +09:00
Rui Ueyama f1739bffd0 Refactor 2024-09-18 15:03:54 +09:00
Rui Ueyama 1efbe3f141 Do not lower the priority of DSO symbols than in-archive symbols
This commit reverts 0612ea41f1 and
instead solves the original issue with a different approach.

Now, if a hidden symbol was resolved to a DSO symbol, we'll redo
symbol resolution so that the symbol won't be resolved to the same one
next time.

This should fix our build-all buildbot.
2024-09-17 13:23:17 +09:00
Rui Ueyama 5ba1c36fbb Refactor 2024-09-17 12:27:08 +09:00
Rui Ueyama c217134d97 Refactor 2024-09-17 11:58:42 +09:00
Rui Ueyama fea866d910 Refactor 2024-09-15 19:18:06 +09:00
Rui Ueyama 3b3bc7b41e Make builders runnable by hand 2024-09-15 19:13:45 +09:00
Rui Ueyama 0612ea41f1 Lower the priority of DSO symbols than in-archive symbols
Assume both `foo.a` and `bar.so` define the same symbol `baz`.
If `baz`'s symbol visibility is hidden, it needs to be resolved within
the output file, i.e., from `foo.a`. However, previously, such symbol
was resolved to the one in `bar.so`.

To fix the problem, we'll lower the symbol priority for DSOs.

Fixes https://github.com/rui314/mold/issues/1342
2024-09-15 17:17:43 +09:00
Rui Ueyama 940ac8125c Refactor 2024-09-15 16:22:18 +09:00
Rui Ueyama 583ba8ade1 Fix daily builder 2024-09-15 11:13:56 +09:00
Rui Ueyama 82feeed693 Build mold binary with mold 2024-09-14 19:11:51 +09:00
Rui Ueyama e7e41329ef Refactor 2024-09-14 17:14:30 +09:00
Rui Ueyama 63d990e49a Upgrade upload-artifact github action 2024-09-14 16:00:17 +09:00
Rui Ueyama 8d5b753337 Fix buildbot 2024-09-14 15:10:50 +09:00
Rui Ueyama 431fc39db0 Change how we handle word-size absolute relocations
Word-size absolute relocations, such as R_X86_64_64, are special from
the linker's point of view because only such symbols can be promoted
to dynamic symbols. This patch handles them separately.
2024-09-14 11:59:20 +09:00
Rui Ueyama 7734a93217 Improve a test 2024-09-14 08:04:15 +09:00
Rui Ueyama 806d7409da Refactor 2024-09-07 19:47:18 +09:00
Rui Ueyama 2e326cc006 Refactor 2024-09-07 15:31:56 +09:00
Rui Ueyama e1ace5ea00 Add a FreeBSD test runner 2024-09-02 14:58:30 +09:00
Rui Ueyama 8e010c2095 Update comments 2024-09-01 13:20:50 +09:00
Rui Ueyama 6758b53bff Fix CI 2024-08-31 15:14:26 +09:00
Rui Ueyama f6822fb0f3 Make executables iwth zero-size segments loadable on FreeBSD
Fixes https://github.com/rui314/mold/issues/1338
2024-08-31 14:52:11 +09:00
Rui Ueyama f0d39b2460 Add a rule for FreeBSD 2024-08-31 13:26:52 +09:00
Rui Ueyama a3e69502b0 Refactor 2024-08-30 12:04:56 +09:00
Rui Ueyama 4645248106 Merge pull request #1337 from leleliu008/fix-netbsd-no-alloca.h 2024-08-30 04:58:24 +09:00
leleliu008 80648584cf alloca.h is missing on NetBSD
alloca(3) is defined in stdlib.h on NetBSD

Reference: https://man.netbsd.org/alloca.3

Signed-off-by: leleliu008 <[email protected]>
2024-08-29 20:22:03 +08:00
Rui Ueyama d4c2073cda Fix test
Previous test passed even without 1c321022d0.
2024-08-27 20:09:40 +09:00
Rui Ueyama fe7237e454 Merge pull request #1335 from ywgrit/main 2024-08-27 17:04:46 +09:00
Xin Wang 4da257e6fb LoongArch: change test of R_LARCH_CALL36 with bigger offset 2024-08-27 15:14:56 +08:00
Rui Ueyama ed617fef05 Merge pull request #1170 from mominul/patch-1
Update README.md
2024-08-27 13:19:16 +09:00
Xin Wang 1c321022d0 LoongArch: fix error offset for relaxation of R_LARCH_CALL36 2024-08-26 16:37:09 +08:00
Rui Ueyama ed4cae9354 Add a test 2024-08-24 14:33:13 +09:00
Rui Ueyama 2d390565c1 Fix the section-shrinking relaxation 2024-08-24 13:53:02 +09:00
Rui Ueyama 5e72d88940 Update a document 2024-08-24 13:21:38 +09:00
Rui Ueyama 213f2ecec5 Refactor 2024-08-23 13:45:02 +09:00
Rui Ueyama 23b3778383 Refactor 2024-08-22 18:25:28 +09:00
Rui Ueyama b9776af9b2 Refactor 2024-08-22 17:34:42 +09:00
Rui Ueyama 25794c6003 Refactor 2024-08-22 11:09:55 +09:00
Rui Ueyama 7fa561699e Refactor 2024-08-21 13:57:26 +09:00
Rui Ueyama 127ba25dab [LoongArch] Fix TLSDESC relaxation
R_LARCH_TLS_DESC_PC_HI20 is a GOT-loading relocation, so we need to
compute the distance to the symbol's GOT entry instead of to the
symbol's address.
2024-08-21 13:25:59 +09:00
Rui Ueyama 6a1742ea90 Refacotr 2024-08-21 12:53:16 +09:00
Rui Ueyama e013d27b54 Add a test 2024-08-21 12:40:56 +09:00
Rui Ueyama 37e175b4a4 Merge pull request #1333 from ywgrit/main
LoongArch: apply relaxation to tls desc
2024-08-21 12:12:15 +09:00
Xin Wang 982b901077 LoongArch: apply relaxation to tls desc 2024-08-21 09:44:43 +08:00
Rui Ueyama f0797bb8f2 Improve CI 2024-08-18 14:22:57 +09:00
Rui Ueyama 18f8c425dc Do not use precompiled headers
`-fpch-preprocess` doesn't seem to improve build speed that much,
so don't use it.
2024-08-18 12:56:38 +09:00
Rui Ueyama 194239f8c6 Enable some tests 2024-08-18 12:39:29 +09:00
Rui Ueyama 401e019b05 Add a test
We also don't want to skip empty string because if a user specifies
an empty string, it is their intention whatever that intention is.
2024-08-18 11:38:47 +09:00
cristian64 0c74e8274e Fix infinite loop in split_by_comma_or_colon(). (#1332)
* Fix infinite loop in `split_by_comma_or_colon()`.

The mere presence of a `,` or a `:` in the input string would make the
function enter an infinite loop, effectively freezing the program until
all available memory was exhausted. The string position in the loop was
not incremented past the `,` or the `;` character that had just been
read.

The function is currently used only in the `--exclude-libs` option. The
freeze is reproducible with:

```bash
$ mold --exclude-libs foo,bar
```

The longer the string after the first `,` or `:` is, the faster memory
exhaustion is reached.

* Skip empty parts in `split_by_comma_or_colon()`.
2024-08-18 11:34:12 +09:00
Rui Ueyama cf5d054eb4 Fix CI 2024-08-17 16:17:31 +09:00
Rui Ueyama d9bf693fb8 [LoongArch] Do not emit local symbols by default 2024-08-17 15:09:08 +09:00
Rui Ueyama cf38f81c39 Refactor 2024-08-17 15:09:08 +09:00
Rui Ueyama 2eeb7b411e Simplify 2024-08-17 06:38:31 +09:00
Rui Ueyama ecc7ce022b Skip ELF symbols whose section numbers are the reserved range
Fixes https://github.com/rui314/mold/issues/1331
2024-08-16 13:26:12 +09:00
Rui Ueyama a6b182b065 Refactor 2024-08-16 13:26:12 +09:00
Rui Ueyama e30f01fe93 Refactor 2024-08-16 12:48:16 +09:00
Rui Ueyama ac84d2cdbb Refactor 2024-08-16 11:18:12 +09:00
Rui Ueyama 742ea87d41 Merge .ARM.exidx entries
This change should make our output for ARM32 a little bit smaller.
2024-08-15 17:15:45 +09:00
Rui Ueyama fa546965ec Refactor 2024-08-15 14:11:55 +09:00
Rui Ueyama f68657d201 Refactor 2024-08-15 13:34:41 +09:00
Rui Ueyama 23bc92c66f Emit PT_GNU_PROPERTY program header if .note.gnu.property is present
It looks like Linux kernel reads this program header to enable BTI on ARM64.
2024-08-15 12:57:45 +09:00
Rui Ueyama c2956484ca Refactor 2024-08-15 12:26:29 +09:00
Rui Ueyama 3f593c62ae Remove code for macOS 2024-08-14 21:29:08 +09:00
Rui Ueyama 5b8594979b Reorganize directory structure 2024-08-14 20:52:09 +09:00
Rui Ueyama 7571305cd1 Fix CI 2024-08-14 20:06:28 +09:00
Rui Ueyama 0631f9750e Fix a Docker image build failure
Fixes https://github.com/rui314/mold/issues/1330
2024-08-14 19:10:40 +09:00
Rui Ueyama b51d6ab5cb Avoid LD_PRELOAD 2024-08-14 19:10:40 +09:00
Rui Ueyama 93c4f35615 Fix minor issues 2024-08-14 17:38:53 +09:00
Rui Ueyama 510b2d68c0 Reorganize directory structure 2024-08-14 16:23:25 +09:00
Rui Ueyama d6d8d2e494 [LoongArch] Fix symbol value computation for the extreme code model
The LoongArch extreme code model uses the following instructions to
materialize a 64-bit value in a regiter.

  pcalau12i $t1, %pc_hi20(g2)
  addi.d    $t0, $zero, %pc_lo12(g2)
  lu32i.d   $t0, %pc64_lo20(g2)
  lu52i.d   $t0, $t0, %pc64_hi12(g2)

The previous relocation formula expected that `page(pc)` would be
consistent for all the instructions, but this assumption is incorrect
if the instruction sequence crosses a 4 KiB boundary.

Now, the LoongArch psABI requires that the machine instructions must be
consecutive, and the relocations for lu32.d and lu52i.d uses
`page(pc - 8)` and `page(pc - 16)` instead of `page(pc)`.

This psABI change gave me an impression that the LoongArch's extreme code
model was poorly designed and inadequately tested. If these instructions
must be consecutive, only a single relocation referring to the beginning
of the instructions would suffice, which relocates all the following four
instructions at once.

Maybe we do not need to support the relocations for the extreme code model
because the code model was buggy at the spec level, which suggests that no
one is using them. But I'm not sure if it is safe to remove them, so let's
just follow the psABI change.
2024-08-14 13:52:12 +09:00
Rui Ueyama 9e0c1c81dd Refactor 2024-08-13 20:52:38 +09:00
Rui Ueyama ac5031198c Simplify 2024-08-13 20:18:50 +09:00
Rui Ueyama 11d5426781 Update mold.1 (automated commit) 2024-08-13 09:22:48 +00:00
Rui Ueyama afc52eea70 Accept --build-id=fast for the sake of compatibility with lld
Fixes https://github.com/rui314/mold/issues/1328
2024-08-13 18:20:56 +09:00
Rui Ueyama 6248d964fb Refactor 2024-08-13 18:15:20 +09:00
Rui Ueyama addb5f1675 [SPARC] Relax TLS GD/LD relocations 2024-08-13 17:18:01 +09:00
Rui Ueyama ed22d76ef0 Refactor 2024-08-13 14:46:53 +09:00
Rui Ueyama a73e9b2dac Update comments 2024-08-13 11:27:45 +09:00
Rui Ueyama 5dfa1cf07c Update comments 2024-08-10 09:51:13 +09:00
Rui Ueyama 4164285a13 Fix CI 2024-08-09 22:10:53 +09:00
Rui Ueyama 1f53bd5bfa Attempt to fix CI 2024-08-09 18:22:07 +09:00
Rui Ueyama a32d294df8 Update comments 2024-08-09 18:02:14 +09:00
Rui Ueyama dbaa6d7341 [LoongArch] Support TLSDESC 2024-08-09 17:49:12 +09:00
Rui Ueyama 23a9e7261d Refactor 2024-08-09 15:04:04 +09:00
Rui Ueyama 5a9919b433 Fix a crash bug
Fixes https://github.com/rui314/mold/issues/1326
2024-08-09 12:38:56 +09:00
Rui Ueyama 1d24b70996 Use crc32() instead of crc32_z()
Old zlib does not support crc32_z. The difference between the two is
that crc32() takes an input size as an unsigned int while crc32_z()
takes as size_t. For our use case, size is guranteed to be short, so
crc32() is safe to use.
2024-08-08 20:06:19 +09:00
Rui Ueyama f18d1c1ffc Attempt to fix build failure on 32 bit Alpine distros
Fixes https://github.com/rui314/mold/issues/1323
2024-08-08 10:09:41 +09:00
Rui Ueyama 1ab637cea4 Bump mold version to 2.33.0 2024-08-07 12:32:13 +09:00
Rui Ueyama 573b8a45df Update mold.1 (automated commit) 2024-08-06 05:26:45 +00:00
Rui Ueyama 0bf00a4247 Remove --encoded-package-metadata from docs
It's not clear whether or not the option would be added to the GNU linker,
so I"ll make this a hidden option for now.

https://github.com/rui314/mold/pull/1308
2024-08-06 14:25:45 +09:00
Rui Ueyama 43d9536a05 Fix an assertion failure
https://github.com/rui314/mold/issues/573
2024-08-05 20:06:45 +09:00
Rui Ueyama 893ec1b362 Format 2024-08-05 15:08:57 +09:00
Rui Ueyama 1aa966c2ad Refactor 2024-08-05 13:26:03 +09:00
ywgrit 121f917884 LoongArch: support relaxation of pcalau12i/ld.d to pcalau12i/addi.d or pcaddi (#1322)
[LoongArch] support relaxation of pcalau12i/ld.d to pcalau12i/addi.d
2024-08-05 12:26:03 +09:00
Rui Ueyama 17a9481522 Merge .sdata, .srodata and .sbss
RISC-V uses these sections for small data/rodata/bss.
2024-08-03 14:58:27 +09:00
Rui Ueyama 06e8bf8933 Update mold.1 (automated commit) 2024-08-03 03:15:37 +00:00
Rui Ueyama f7af61f80c Update man page 2024-08-03 12:14:59 +09:00
Rui Ueyama 25b34bb472 Update mold.1 (automated commit) 2024-08-02 11:02:16 +00:00
Rui Ueyama 22f85c1b6f Rename --remove-landing-pad -z rewrite-endbr 2024-08-02 19:18:03 +09:00
Rui Ueyama dd8d9714cb dSupport --dynamic-list-data
Fixes https://github.com/rui314/mold/issues/1320
2024-08-01 18:51:34 +09:00
Rui Ueyama 982f07168d Refactor 2024-08-01 11:51:28 +09:00
Rui Ueyama 218d89b005 Rename a test 2024-07-31 21:00:12 +09:00
Rui Ueyama bada67bb39 Handle R_LARCH_CALL36 as a function-calling relocation 2024-07-31 20:58:45 +09:00
Rui Ueyama db03248e72 Fix comments 2024-07-31 20:05:52 +09:00
Rui Ueyama 47c092aac0 Remove range extension support from LoongArch
It looks like emitting PCADDU18I + JIRL instead of just BL for function
calls is a way to go, so we don't want to bother to maintain range
extension thunks for the psABI.

Since no other linkers support range extension thunks for LoongArch other
than us, removing the support should be OK.
2024-07-31 19:23:03 +09:00
Rui Ueyama 4e6b4c43cd Refactor 2024-07-31 19:09:56 +09:00
Rui Ueyama 2c6f379d69 Support R_LARCH_CALL36 2024-07-31 17:51:34 +09:00
Rui Ueyama bf79ae1190 Refactor 2024-07-31 14:55:05 +09:00
Rui Ueyama 96fda95624 Add a test for LoongArch relaxation 2024-07-31 11:48:04 +09:00
Rui Ueyama b71bfccb46 Improve pcalau12i+addi.d relaxation
This should unbreak our buildbots.
2024-07-31 11:36:32 +09:00
Rui Ueyama a4dc015c0d Update comments 2024-07-31 10:39:22 +09:00
ywgrit 74b359fe62 [LoongArch] Support relax of pcalau12i/addi.d->pcaddi (#1318)
Relax pcalau12i/addi.d to pcaddi
2024-07-31 10:39:06 +09:00
Rui Ueyama 197a74ded6 Add comments 2024-07-29 16:03:35 +09:00
Rui Ueyama 9aa4fcc6cd Show skipped tests
I don't know why, but the previous regular expression didn't match with
a line consisting just with "skipped".
2024-07-29 13:41:34 +09:00
Rui Ueyama 36915416dd Run a binary under Intel SDE CPU emulator with CET enabled 2024-07-29 13:16:12 +09:00
Rui Ueyama 411dcfd0b1 Fix comments 2024-07-29 13:13:54 +09:00
Rui Ueyama 35564d5f2c Update mold.1 (automated commit) 2024-07-29 02:00:32 +00:00
Rui Ueyama bba20b3fe7 Fix typos 2024-07-29 10:59:12 +09:00
Rui Ueyama 55e516da6f Update mold.1 (automated commit) 2024-07-29 01:55:03 +00:00
Rui Ueyama 2c3dcc4370 Document --remove-landing-pads 2024-07-29 10:52:31 +09:00
Rui Ueyama 1fb6dd3b46 Rename -z rewrite-endbr --remove-landing-pads
This is because we want to support it for non-x86-64 targets.
Using the x86 instruction name as a parameter name is not desirable.
2024-07-29 10:52:21 +09:00
Rui Ueyama ed7eec5969 Fix -z rewrite-endbr
Previously, functions that are referred to only by section symbols were
not considered address-taken, and we always rewrote endbr64s with NOPs for
such functions. That caused a runtime fault when such function was called
indirectly.

Now, endbr64s for such symbols are retained.

I tried to build clang-19 as a release build with and without `-z
rewrite-endbr` and counted the number of endbr64 instructions in each
binary. Here is the result:

  Before: 110,615
  After:   91,799

So the feature reduces the number of gadgets by 17%. Both binaries worked
fine with Intel SDE CPU emulator with `-cet 1 -cet_raise 1`, so I think
it's finally working as expected.

I also tried to build mold itself with and without the feature. Here is
the result:

  Before: 27,430
  After:  17,725

This is a 35% reduction. I confirmed that mold built with `-z rewrite-endbr`
can self-host under Intel SDE.

The rewrite_endbr pass is extremely fast. It took only 7 milliseconds
for a ~210 MiB clang-19 binary on my Threadripper 7990X machine. We
may want to consider enabling it by default at some point.
2024-07-29 09:06:26 +09:00
Rui Ueyama 3f7236d268 Refactor 2024-07-28 19:42:05 +09:00
Rui Ueyama 766ce80297 Update comments 2024-07-28 17:01:13 +09:00
Rui Ueyama 61af6f3c59 Report an error for an enormously large r_addend 2024-07-27 16:14:20 +09:00
Rui Ueyama 464f7655d6 Use break instead of nop as a filler 2024-07-27 14:50:38 +09:00
Rui Ueyama d1674d86ac Add comments 2024-07-27 14:50:38 +09:00
Rui Ueyama 36e5b4b949 Relax R_LARCH_TLS_LE_{HI20_R,ADD_R,LO12_R} 2024-07-27 11:03:45 +09:00
Rui Ueyama 98a7cff0c5 Handle R_LARCH_RELAX 2024-07-27 11:03:45 +09:00
Rui Ueyama 34ed39c873 Refactor 2024-07-27 11:03:43 +09:00
Rui Ueyama 2bbba15068 Create canonical PLTs for PIEs
We cannot guarantee pointer equality for some corner cases without them.
2024-07-24 10:56:39 +09:00
Rui Ueyama a478db77c2 Do not obtain an unnecessary lock 2024-07-22 12:05:19 +09:00
Rui Ueyama d829e425df Add a missing #include
https://github.com/microsoft/mimalloc/pull/917
2024-07-22 11:06:37 +09:00
Rui Ueyama f5b2b82295 Skip a test if LD_PRELOAD doesn't work
May be related to the following issues:

  https://github.com/rui314/mold/issues/1305
  https://github.com/rui314/mold/issues/1309
2024-07-22 10:39:32 +09:00
Rui Ueyama e3876ddbd4 Refactor 2024-07-22 08:47:25 +09:00
Rui Ueyama b8556e37bb Fix CI 2024-07-21 20:18:31 +09:00
Rui Ueyama bbfaa0bb30 Fix CI 2024-07-21 19:47:12 +09:00
Rui Ueyama 5606087776 Support -z x86-64-v[234] 2024-07-21 18:51:28 +09:00
Rui Ueyama b919548b27 Refactor 2024-07-21 16:42:39 +09:00
Rui Ueyama ed7414e1c7 Update mold.1 (automated commit) 2024-07-21 06:16:56 +00:00
Rui Ueyama fa1237fc08 Document --no-allow-shlib-undefined 2024-07-21 15:14:48 +09:00
Rui Ueyama 1dc99aaade Fix CI 2024-07-21 13:26:58 +09:00
Rui Ueyama 3001f02b55 Support --no-allow-shlib-undefined
Fixes https://github.com/rui314/mold/issues/1313
2024-07-21 13:06:57 +09:00
Rui Ueyama 39442dbdf0 Refactor 2024-07-20 16:05:37 +09:00
Rui Ueyama 6c4ca4e40c Attempt to fix CI 2024-07-20 15:06:15 +09:00
Rui Ueyama bdca85e15a Make Integer's constructor constexpr 2024-07-20 14:54:58 +09:00
Rui Ueyama 1ccc77ac7f Refactor 2024-07-20 13:38:03 +09:00
Rui Ueyama b99ed6e7ae Refactor 2024-07-20 13:10:33 +09:00
Rui Ueyama 6ee6410948 Build and test on more Linux distros 2024-07-19 18:03:57 +09:00
Rui Ueyama d187dac602 Install binary packages in Gentoo 2024-07-19 18:03:57 +09:00
Rui Ueyama 2b4c365161 Run tests on Alpine Linux with musl libc 2024-07-19 15:46:15 +09:00
Rui Ueyama 70ea7ade7f Do not use the extended regexp
It looks like Busybox's grep doesn't support regexp backreferences.

Fixes https://github.com/rui314/mold/issues/1309
2024-07-19 15:23:52 +09:00
Rui Ueyama 56a94d2693 Fix a test on musl
Fixes https://github.com/rui314/mold/issues/1309
2024-07-19 14:54:33 +09:00
Rui Ueyama 14a4b05950 Always create a .eh_frame section even if it's empty
glibc's `__register_frame_info_bases` expect that it can read a terminator
if a .eh_frame is empty. Removing the section completely caused a crash bug
on Alpine Linux with musl as libc.

Specifically, mold-generated binaries crash if all the following
condition were met:

 1. musl is used as a libc
 2. .eh_frame is empty
 3. libgcc_s.so is linked

Prior to 06b592683c, condition (3) was not
usually satisfied, so we didn't notice this issue. Now, the shared library
is linked against almost all output files because the file is referenced by
`__deregister_frame_info`.

https://github.com/bminor/glibc/blob/910aae6e5a2196938fc30fa54dd1e96f16774ce7/sysdeps/generic/unwind-dw2-fde.c#L105-L107

Fixes https://github.com/rui314/mold/issues/1309
2024-07-19 14:51:00 +09:00
Rui Ueyama 14d525c1a1 Refactor 2024-07-18 21:04:55 +09:00
Rui Ueyama 5b7ae06bde Update mold.1 (automated commit) 2024-07-18 06:53:23 +00:00
Rui Ueyama e67f5e62ae Fix update-manpage workflow 2024-07-18 15:51:56 +09:00
Rui Ueyama bae9598190 Refactor 2024-07-18 13:54:16 +09:00
Rui Ueyama 9acda6f939 Make update-manpage workflow runnable by hand 2024-07-18 13:06:08 +09:00
Rui Ueyama 7b52f34c38 Make test scripts more verbose 2024-07-18 12:57:32 +09:00
Rui Ueyama 9874a9daa7 Document --encoded-package-metadata
https://github.com/rui314/mold/pull/1308
2024-07-18 11:57:48 +09:00
Rui Ueyama aecf39d459 Do not crash when an empty argument is given 2024-07-18 11:57:48 +09:00
Rui Ueyama 9eacc638f3 Improve a test 2024-07-18 11:57:48 +09:00
Rui Ueyama 0c34ec1f50 Refactor 2024-07-18 09:39:01 +09:00
Rui Ueyama a778f9c5f4 Merge pull request #1308 from bdrung/encoded-package-metadata
Add --encoded-package-metadata
2024-07-17 22:23:44 +09:00
Rui Ueyama d7b079c4fb Refactor 2024-07-17 21:26:36 +09:00
Benjamin Drung cfe60991a5 Add --encoded-package-metadata
Specifying the compiler flag `-Wl,--package-metadata=<JSON>` might not
work, because the shells might eat the quotation marks and the compiler
splits the JSON at the commas.

Ubuntu tried to using a specs file to set `--package-metadata` but that
turned out to be too fragile. autopkgtests might use the compiler flags
but the needed environment variables are not set in the test
environment. Debugging a crash of an application build with the -spec
parameter lacks the environment variables. People like to iteratively
continue building the software in the build directory while hacking on
the package and then have no environment variable set.

So introduce a `--encoded-package-metadata` linker flag that takes a
percent-encoded JSON. Percent-encoding is used because it is a
standard and simple to implement.

Bug-Ubutru: https://bugs.launchpad.net/bugs/2071468
Signed-off-by: Benjamin Drung <[email protected]>
2024-07-17 14:14:48 +02:00
Rui Ueyama 2acf634340 Fix typo 2024-07-17 18:50:48 +09:00
Rui Ueyama 09f1008186 Handle R_LARCH_TLS_LE_HI20_R and R_LARCH_TLS_LE_LO12_R 2024-07-17 18:36:12 +09:00
Rui Ueyama baf9ae9038 Fix a test on Debian
If the default linker doesn't complain, just skip the test.

Fixes https://github.com/rui314/mold/issues/1301
2024-07-16 12:00:08 +09:00
Rui Ueyama cdcb428f26 Remove dead code 2024-07-15 13:41:57 +09:00
Rui Ueyama 36bc198b9a Refactor 2024-07-15 13:36:07 +09:00
Rui Ueyama 428a9c4228 Skip a test on m68k
https://github.com/rui314/mold/pull/1304
2024-07-15 11:19:06 +09:00
Rui Ueyama 666b18b851 Use __attribute__((aligned)) instead of a C macro 2024-07-15 11:06:11 +09:00
Rui Ueyama f180ac21c8 Fix build on non-m68k hosts
https://github.com/rui314/mold/pull/1304
2024-07-14 21:49:58 +09:00
Rui Ueyama 0b1be96a13 Merge pull request #1304 from chewi/m68k-alignment
Align Chuck, InputSection, and SectionFragment to at least 4 bytes
2024-07-14 21:44:35 +09:00
James Le Cuirot 1f444a21d2 Align Chuck, InputSection, and SectionFragment to at least 4 bytes
There are already static_asserts to check this, so it is almost always
true anyway, but not on m68k, which aligns to 2 bytes by default.
2024-07-14 10:22:04 +01:00
Rui Ueyama 4eeebf0221 Define Script class and move linker script-related code there 2024-07-14 16:41:03 +09:00
Rui Ueyama b2a1e4b83e Move reader-related attributes to ReaderContext 2024-07-14 11:10:59 +09:00
Rui Ueyama 08938402c9 Rename a variable 2024-07-13 18:19:11 +09:00
Rui Ueyama 4c569c8c8c Accept --library as a synonym for -l
No one has complained about it so far, but according to the GNU ld manual,
`--library` is a synonym for `-l`.
2024-07-13 18:18:35 +09:00
Rui Ueyama 03a2105d39 Change how we resolve relocations referring to mergeable sections
Previously, we find a string in a mergeable string section by offset
after adding a relocation addend to a symbol value. Now, we find a
string just by a symbol value and then add a relocation addend later.

Assume a mergeable section containing two strings as an example.

  foo\0bar\0
  ^    ^
  .L1  .L2

Previously, a relocation referring to .L2 - 1 referred to the end of
.L1. Now, it refers to one byte before .L2.

Section symbol is an exception to this rule, because it seems it's
what the compiler is assuming. The rules seem arbitrary, but it looks
like we need them for the compatibility with existing object files.

Fixes https://github.com/rui314/mold/issues/1300
2024-07-13 17:25:44 +09:00
Rui Ueyama d2870ac574 Upgrade bundled mimalloc to 2.1.7 2024-07-11 15:38:18 +09:00
Rui Ueyama 8497b7e1dc Upgrade OneTBB in ./third-party to version 2021.13.0 2024-07-11 15:38:18 +09:00
Rui Ueyama 0e2b6b010d Update mold.1 (automated commit) 2024-07-11 04:39:27 +00:00
Rui Ueyama 84263109b1 Revert "Allow numbers other than 1 for MOLD_JOBS"
This reverts commit 863893057e because
it's unstable.
2024-07-11 13:36:55 +09:00
Rui Ueyama 162bcca5df Update mold.1 (automated commit) 2024-07-11 02:10:41 +00:00
Rui Ueyama 2fb3c9da57 Update man page 2024-07-11 11:09:03 +09:00
Rui Ueyama 83ee4962b1 Fix test flakiness for SH4 2024-07-11 09:58:16 +09:00
Rui Ueyama e03f74a357 Fix CI
Fixes https://github.com/rui314/mold/issues/1299
2024-07-10 15:52:46 +09:00
Rui Ueyama 8c1b25b3aa Obtain a file lock with flock() while creating a separate debug file 2024-07-09 17:49:39 +09:00
Rui Ueyama 315dfd3244 Fix CI 2024-07-09 15:25:53 +09:00
Rui Ueyama 02ca830f42 Refactor 2024-07-09 15:07:41 +09:00
Rui Ueyama 18da5b654e Add --no-detach to write to a separate debug file in the foreground
--detach is the default.
2024-07-09 12:06:41 +09:00
Rui Ueyama 97a1e218c5 Simplify crc32_solve()
The code was originally written by Pete Cawley
https://gist.github.com/corsix/bdfc8f2f1dc0f28de39f74de9bf4f060
2024-07-09 10:15:26 +09:00
Rui Ueyama f9e4cb1a7f Add a missing #include 2024-07-08 10:43:40 +09:00
Rui Ueyama 60760a892a Attempt to fix CI 2024-07-08 09:59:07 +09:00
Rui Ueyama 596ffa959a Add --separate-debug-info
This option is to separate debug info to a different file. The debug
info file's filename is stored to the main output file's .gnu_debuglink
section. gdb can read the section contents and followg the link to
find debug info in another file.

Fixes https://github.com/rui314/mold/issues/1294
2024-07-08 09:28:32 +09:00
Rui Ueyama cd3b817f13 Make notify_parent idempotent 2024-07-07 22:49:35 +09:00
Rui Ueyama 19de40fed4 Refactor 2024-07-07 22:45:17 +09:00
Rui Ueyama e78e12b15b Refactor 2024-07-07 22:24:42 +09:00
Rui Ueyama 5b4377842b Fix CI 2024-07-07 21:50:53 +09:00
Rui Ueyama 16ee9f48a4 Fix CI 2024-07-07 17:58:21 +09:00
Rui Ueyama 8e3679e4e5 Refactor 2024-07-06 13:11:09 +09:00
Rui Ueyama 7089304046 Simplify 2024-07-05 19:47:33 +09:00
Rui Ueyama 5ab3708e9f Merge pull request #1298 from yujincheng08/patch-1
Fix cross-compile lto on MacOS
2024-07-05 19:45:10 +09:00
Rui Ueyama aa939d7a6a Temporarily disable ASAN tests
It looks like starting with Clang 18.1.3, ASAN began reporting an
error on OneTBB.
2024-07-05 18:27:00 +09:00
Rui Ueyama a63bbcd7b1 Attempt to fix CI 2024-07-05 17:58:13 +09:00
Rui Ueyama 339f9c485a Attempt to fix CI 2024-07-05 17:42:32 +09:00
LoveSy 4905f6d3f2 Use macos-12 because macos-11 has been removed
https://github.blog/changelog/2024-05-20-actions-upcoming-changes-to-github-hosted-macos-runners/#macos-11-deprecation-and-removal
2024-07-05 15:32:37 +08:00
Rui Ueyama cb8cc1c8f0 Refactor 2024-07-05 16:00:09 +09:00
Rui Ueyama c6b54532e9 Refactor 2024-07-04 16:17:25 +09:00
Rui Ueyama 3936134823 Refactor 2024-07-04 15:08:37 +09:00
Rui Ueyama 55ca05bab6 Refactor 2024-07-04 13:59:29 +09:00
LoveSy 7305a5c5dd Fix cross-compile lto on MacOS 2024-07-03 21:55:22 +08:00
Rui Ueyama b145377c39 Merge pull request #1296 from marxin/improve-gdb-index-test
Improve --gdb-index test by using readelf --debug=gdb_index
2024-07-01 17:15:51 +09:00
Martin Liska 08f2a74be7 Improve --gdb-index test by using readelf --debug=gdb_index 2024-06-30 16:07:47 +02:00
Rui Ueyama 82fb10fe26 Fix a test 2024-06-28 15:57:10 +09:00
Rui Ueyama 34f4d654d3 Add an entry for AlmaLinnux 2024-06-28 15:54:39 +09:00
Rui Ueyama 091395df33 Link with -ldl for dlopen()
Fixes https://github.com/rui314/mold/issues/1293
2024-06-28 11:00:37 +09:00
Rui Ueyama a38be94064 Simplify 2024-06-27 19:51:06 +09:00
Rui Ueyama cf1c02d097 Bump mold version to 2.32.1 2024-06-27 14:04:26 +09:00
Rui Ueyama 3dbe2ac704 Do not write relocation addends for RISC-V
Probably due to a bug in glibc, static PIE binaries crash on startup
in some environment.

Fixes https://github.com/rui314/mold/issues/1291
2024-06-27 13:09:58 +09:00
Rui Ueyama 35d67a3fab Add a missing #include for getenv() 2024-06-26 15:10:54 +09:00
Rui Ueyama f60fada438 Refactor 2024-06-24 16:09:35 +09:00
Rui Ueyama c419dcde1b Merge pull request #1289 from yujincheng08/main
ci: add msys2
2024-06-24 09:49:34 +09:00
LoveSy ebfe4f13c6 fix mingw compiles 2024-06-23 15:40:28 +00:00
LoveSy 8f9b59cbe6 ci: add msys2 2024-06-23 23:21:50 +08:00
Rui Ueyama 63f26708fd Unbreak daily buildbot 2024-06-23 12:38:59 +09:00
Rui Ueyama 07b09a66d3 Attempt to fix CI 2024-06-22 13:51:30 +09:00
Rui Ueyama 4cc61361f3 Refactor 2024-06-22 13:08:43 +09:00
Rui Ueyama 5535e7a6b7 Style change 2024-06-22 10:56:36 +09:00
Rui Ueyama 06b592683c Make weak undefined symbols to mark shared libraries as "needed"
It is not clearly defined when undefined weak symbols are resolved.
It looks like there are two possible approaches:

 1. Promote all weak undefined symbols to dynamic ones so that they'll
    have another chance to be resolved at load-time, or

 2. Promote weak undefined symbols to dynamic ones only when there are
    definitions in other DSOs at link-time.

(1) provides the maximum flexibility. For example, consider a main program
that has a weak undefined symbol `foo` and there's no DSO that defines it
at link-time. In (1), `foo` gets promoted to a dynamic symbol, so that one
of its depending DSO is upgraded to define `foo`, the main executable's
`foo` is resolved to that symbol at load-time. On the other hand, in (2),
`foo` would have already been converted to an absolute symbol at address
zero at link-time, so you need to rebuild the main executable to use the
new definition of `foo` in the shared library.

However, (1) is not compatible with copy relocations. This is because we
need to know the size of the symbol when creating a copy relocation, but
that information is not available unless we have a definition. It's also
not compatible with canonical PLTs because canonical PLTs have non-zero
addresses and therefore weak undefined symbols would always be resolved to
non-zero addresses.

As a workaround, GNU ld promotes weak undefs to dynamic symbols only when
they don't need copy relocations or canonical PLTs. In other words, weak
undef's behavior is different between -fPIC and -fno-PIC. In the former
case, they become dynamic symbols, and vice versa.

I don't think that workaround is a good one. So, mold took the second
approach.

There is, however, another thing to consider. What if we can find a
defined symbol in a DSO that is specified as `-as-needed`? Previously,
mold did not mark the library as "needed" and converted the weak undef
into an absolute symbol.

However, libstdc++ assumes that if weak undef symbol
`__pthread_key_create` is not resolved, it assumes that multi-threading is
not used in the executable, which resulted in a mis-detection with mold.

Therefore, this patch changes the mold's behavior so that it makes weak
undefs to keep DSOs "needed".

Fixes https://github.com/rui314/mold/issues/1286
2024-06-22 10:46:17 +09:00
Rui Ueyama 0b5e5dcbb5 Fix -Wunused-result 2024-06-22 10:46:17 +09:00
Rui Ueyama b1695c6018 Merge pull request #1287 from yujincheng08/lto
Support lto on mingw
2024-06-22 07:54:25 +09:00
LoveSy 48ee8e8257 Handle stackoverflow 2024-06-21 17:42:33 +08:00
LoveSy 50bf031d49 Support lto on mingw 2024-06-21 17:42:27 +08:00
Rui Ueyama bf05198d53 Merge pull request #1285 from yujincheng08/patch-2 2024-06-20 11:17:47 +09:00
Rui Ueyama f9a37e9dd4 Remove dead code
get_self_path() is used by `mold -run`, which is not available on
macOS or Windows.
2024-06-20 09:31:44 +09:00
LoveSy cf9e59954b Use __has_include instead 2024-06-19 23:50:40 +08:00
LoveSy 7cce297318 Only define STDERR_FILENO when not defined 2024-06-19 23:48:14 +08:00
Rui Ueyama 1f94716fce Attempt to fix CI 2024-06-18 22:40:52 +09:00
Rui Ueyama 863893057e Allow numbers other than 1 for MOLD_JOBS 2024-06-18 18:28:28 +09:00
Rui Ueyama b83b1950c0 Merge pull request #1281 from ziyao233/outgoing/fix-static-flag 2024-06-17 08:10:20 +09:00
Yao Zi d2774b0da9 Use $CXX to detect cxxflags
Use $CXX instead of $CC to detect whether C++ programs could be built
statically. Add function test_cxxflags for convenience.

Fix test error in an environment where C++ programs cannot be built
statically, with error like:

  mold: fatal: library not found: c++

Signed-off-by: Yao Zi <[email protected]>
2024-06-16 20:16:34 +00:00
PerseoGI cd7287f0de Update README adding Conan usage instructions 2024-06-13 11:26:14 +02:00
Rui Ueyama cff858bad5 Attempt to fix CI 2024-06-13 16:47:50 +09:00
Rui Ueyama 7669a3ce67 Attempt to fix CI 2024-06-13 16:11:48 +09:00
Rui Ueyama 3ad387f20c Refactor 2024-06-13 13:33:45 +09:00
Rui Ueyama af6d356468 Attempt to fix CI 2024-06-11 14:49:53 +09:00
Rui Ueyama 768f1dffdd Attempt to fix CI 2024-06-11 14:43:54 +09:00
Rui Ueyama 2a25c81834 Refactor 2024-06-11 13:37:21 +09:00
Rui Ueyama 24b8941f60 Refactor 2024-06-10 20:36:40 +09:00
LoveSy 841a186346 Fix corrupted .riscv.attributes ISA string (#1276)
Fix corrupted .riscv.attributes ISA string
extension name can contain digits
2024-06-10 19:56:40 +09:00
Rui Ueyama ec04bfda9d Bump mold version to 2.32.0 2024-06-09 12:44:21 +09:00
Rui Ueyama 8cd85aaa29 Make --undefined=ignore-in-object-files to override -z defs
The interaction between these flags are unnecessarily complicated,
but it looks like `--undefined=ignore-in-object-files` needs to
share the same internal flag as `-z defs` so that they override
each other.

Fixes https://github.com/rui314/mold/issues/1270
2024-05-31 22:00:03 +09:00
Rui Ueyama 01bc0b522d Update mold.1 (automated commit) 2024-05-31 04:53:42 +00:00
Rui Ueyama 48e777ad7b Update man page 2024-05-31 13:51:59 +09:00
Rui Ueyama 0955c30852 Update mold.1 (automated commit) 2024-05-30 09:51:42 +00:00
Rui Ueyama 02ec7156c1 Update man page 2024-05-30 18:50:35 +09:00
Rui Ueyama c7c8583946 Allow larger range extension thunks
Fixes https://github.com/rui314/mold/issues/1224
2024-05-27 15:43:43 +09:00
Rui Ueyama 08b0a1629d Do not emit incorrect relocations for mergeable sections with --relocatable
Fixes https://github.com/rui314/mold/issues/1265
2024-05-24 13:01:10 +09:00
Rui Ueyama 02b439af48 Upgrade bundled mimalloc to 2.1.6
Fixes https://github.com/rui314/mold/issues/1257
2024-05-21 11:55:39 +09:00
Rui Ueyama a8cd2e84e0 Support R_PPC64_TPREL16_LO_DS
Fixes https://github.com/rui314/mold/issues/1262
2024-05-21 11:22:51 +09:00
Rui Ueyama a25226eb13 Replace our SipHash implementation with https://github.com/rui314/siphash 2024-05-18 12:15:26 +09:00
Rui Ueyama 91f9c4d167 Avoid unaligned memory access 2024-05-17 15:39:19 +09:00
Rui Ueyama 416b0d336f Optimize
Teaching the compiler that `buflen` cannot be negative and also doesn't
take a large value allows it to optimize code a little bit more than
it currently does.
2024-05-16 11:52:58 +09:00
Rui Ueyama ca4738d5e2 Use Siphash-1-3 instead of SipHash-2-4
I couldn't find any report that the reduced round version is broken
despite being used at a lot of places (e.g. Rust's hash table uses
SipHash-1-3). So I assume it's secure.
2024-05-16 11:44:25 +09:00
Rui Ueyama 4281f45f06 Do not record response files as dependency files
Fixes https://github.com/rui314/mold/issues/1258
2024-05-16 10:31:21 +09:00
Rui Ueyama 08be7ff2d2 Use SipHash-2-4 instead of SipHash-1-3
Because I wasn't not sure SipHash-1-3 is considered as a secure MAC.
2024-05-12 09:11:32 +09:00
Rui Ueyama 47030cf6ca Fix thread-unsafe code
BitVector is not therad-safe if two threads write to the same byte
at the same time.
2024-05-11 19:56:07 +09:00
Rui Ueyama a5e5ad75fe Refactor 2024-05-11 19:56:07 +09:00
Rui Ueyama 0ce1c78012 Refactor 2024-05-11 16:54:54 +09:00
Rui Ueyama a250aea2f9 Refactor 2024-05-11 16:38:13 +09:00
Rui Ueyama 1fa4e34cec Inline memcpy
Teaching the compiler that `buflen` can never be negative here allows
it to inline subsequent `memcpy` function calls.
2024-05-11 16:28:46 +09:00
Rui Ueyama 1290a02a4e Refactor 2024-05-11 15:22:56 +09:00
Rui Ueyama 10b69883bd Refactor 2024-05-11 14:39:09 +09:00
Rui Ueyama fa8e95a289 Use SipHash instead of Blake3 for Identical Code Folding 2024-05-11 14:39:09 +09:00
Rui Ueyama 6373eb05a7 Refactor 2024-05-10 15:51:22 +09:00
Rui Ueyama 3ec4b1787e Refactor 2024-05-08 16:43:42 +09:00
Rui Ueyama 74129bfc86 Fix a test
Fixes https://github.com/rui314/mold/issues/1249
2024-05-06 13:54:17 +09:00
Rui Ueyama 595f98da78 Do not attempt to run an executable built with -z rodynamic
Such executables seem to crash immediately on older systems.
2024-05-06 13:12:33 +09:00
Rui Ueyama 2649b69e95 Fix CI 2024-05-05 22:43:58 +09:00
Rui Ueyama d20dc21e2a Update mold.1 (automated commit) 2024-05-05 13:22:52 +00:00
Rui Ueyama 7ac0816aa9 Fix typo 2024-05-05 22:21:56 +09:00
Rui Ueyama 154b6b047d Update mold.1 (automated commit) 2024-05-05 13:19:41 +00:00
Rui Ueyama 9a233df7e2 Support -z rodynamic
LLVM lld supports the flag.

Fixes https://github.com/rui314/mold/issues/1253
2024-05-05 22:17:52 +09:00
Rui Ueyama 7b2cb47727 Refactor 2024-05-05 13:08:04 +09:00
Rui Ueyama d683e8aa0b Add a test for SHF_GNU_RETAIN 2024-05-05 12:41:55 +09:00
Rui Ueyama 5ec3d2dcc2 Do not use std::osyncstream 2024-05-04 20:37:28 +09:00
Rui Ueyama edcf252603 Rename SyncOut -> Out 2024-05-04 18:16:04 +09:00
Rui Ueyama 024b03791a Remove extraneous newlines from "symbol missing" errors 2024-05-04 18:09:25 +09:00
Rui Ueyama 230ef819c2 Refactor 2024-05-04 18:08:09 +09:00
Rui Ueyama 5bdf48695a Use std::osyncstream 2024-05-04 17:42:47 +09:00
Rui Ueyama 78fea38b12 Remove a use of thread-local variable 2024-05-04 17:42:46 +09:00
Rui Ueyama 4510f4af81 Use pause instruction on ARM7 and ARM8
https://github.com/rui314/mold/issues/1250
2024-05-04 13:09:36 +09:00
Rui Ueyama a3480e8a2b Merge pull request #1251 from wahjava/fix-on-freebsd
Fix build on FreeBSD
2024-05-04 12:48:30 +09:00
Ashish SHUKLA 5396667ad5 Fix build on FreeBSD 2024-05-03 15:44:26 +00:00
Rui Ueyama f0f61cc7ad Do not use yield asm instruction on arm32
`yield` may not exist on older ARM processors.

Fixes https://github.com/rui314/mold/issues/1250
2024-05-03 21:44:27 +09:00
Rui Ueyama b237fd1ae9 Refactor 2024-05-03 20:35:14 +09:00
Rui Ueyama 2b67afb8a3 Simplify
We no longer use `sold` as a command name.
2024-05-03 15:55:26 +09:00
Rui Ueyama 20fa8d56f5 Bump mold version to 2.31.0 2024-05-03 10:04:55 +09:00
Rui Ueyama ed1e3c06a2 Do not copy mold executable to a test directory
mold executable can be quite large (~600 MiB with debug info),
so we don't want to casually copy that file.
2024-05-03 10:04:01 +09:00
Rui Ueyama fdbe7eecf9 Do not set root as the file owner 2024-05-02 14:52:17 +09:00
Rui Ueyama 16ad212919 Update the build script
It looks like ftp.gnu.org started redirecting incoming HTTP requests
to HTTPS.
2024-05-02 14:03:37 +09:00
Rui Ueyama 5c0cce3d6c Merge pull request #1246 from thesamesam/which-hunt 2024-04-30 17:50:06 +09:00
Sam James ec0a9d09dd test: use command -v, not non-portable which
`which` isn't in POSIX and several Linux distributions are trying to
remove it from their base system, see e.g. https://lwn.net/Articles/874049/.

Just use `command -v` which is POSIX.

Signed-off-by: Sam James <[email protected]>
2024-04-30 07:54:40 +01:00
Rui Ueyama ea054ccced Allow a newline or a tab at the begining of a linker script
Previously, the first four byte must have been "printable" bytes,
which exclude newlines or tabs.
2024-04-29 19:41:11 +09:00
Rui Ueyama cbbe23aa46 Do not show "entry symbol not found" error when creating a DSO 2024-04-28 18:06:54 +09:00
Rui Ueyama 990b0daae2 Optimize Aho-Corasick string search
We use Aho-Corasick string search algorithm for version script.
If all symbols in a version script do not start with '*', we can
terminate the algorithm early.
2024-04-28 17:53:20 +09:00
Rui Ueyama a16316e916 Show warning messages in purple instead of red 2024-04-28 16:56:25 +09:00
Rui Ueyama 14952546a4 Do not edit binary files with sed
Fixes https://github.com/rui314/mold/issues/1244
2024-04-28 15:43:28 +09:00
Rui Ueyama 020b1a78d9 Do not set the .text address as an entry adddress if -e is missing
lld does not do that too.
2024-04-28 15:43:28 +09:00
Rui Ueyama 6b70e02bf5 Report an error if a mergeable/merged section is too large
We use u32 as an index into mergeable/merged sections, so we cannot
handle extremely large sections.
2024-04-28 15:43:28 +09:00
Rui Ueyama 31969a2756 Refactor 2024-04-28 15:43:28 +09:00
Rui Ueyama 53ebcd80d8 Reduce memory usage
This change saves ~1 GiB memory allocation when linking ~3.8 GiB clang-19
binary because the binary contains tons of mergeable strings for debug info.
2024-04-26 14:51:01 +09:00
Rui Ueyama d714301180 Optimize 2024-04-25 18:04:18 +09:00
Rui Ueyama 002d619b11 Attempt to fix a test failure
I believe some version of objcopy corrupts an object file when
renaming a section. In this change, I use sed instead of objcopy
as a workaround.

Fixes https://github.com/rui314/mold/issues/1244
2024-04-25 16:59:40 +09:00
Rui Ueyama 55bb6bc318 Refactor 2024-04-25 15:42:01 +09:00
Rui Ueyama 05066e5279 Refactor 2024-04-25 12:17:21 +09:00
Rui Ueyama 131993634f Simplify 2024-04-24 16:05:19 +09:00
Rui Ueyama 40f6b17eda Optimize 2024-04-24 14:32:44 +09:00
Rui Ueyama 7a8ebc4dc7 Refactor 2024-04-24 13:19:20 +09:00
Rui Ueyama a9346f5c82 Add a test 2024-04-24 12:54:54 +09:00
Rui Ueyama 3104ce1dd2 Update the rule for Gentoo 2024-04-23 22:14:17 +09:00
Rui Ueyama d213f2b25d Add a rule for Clear Linux 2024-04-23 21:49:15 +09:00
Rui Ueyama 813089047f Refactor 2024-04-23 21:49:15 +09:00
Rui Ueyama 0ed5a9842a Refactor 2024-04-23 13:42:46 +09:00
Rui Ueyama f037cd0740 Refactor 2024-04-22 17:55:57 +09:00
Rui Ueyama c9faf3d345 Optimize 2024-04-22 17:47:06 +09:00
Rui Ueyama db8758060a Fix CI 2024-04-21 16:40:54 +09:00
Rui Ueyama c8ac0919a9 Fix CI 2024-04-21 15:44:21 +09:00
Rui Ueyama a2432e125a Refactor 2024-04-21 15:23:56 +09:00
Rui Ueyama e498e2fd83 Do not create .copyrel.rel.ro if -z norelro is given 2024-04-21 14:52:51 +09:00
Rui Ueyama c65121a370 Revert "Upgrade OneTBB in ./third-party to version 2021.12.0"
This reverts commit ddc63ba9b2 because it
broke macOS build.
2024-04-19 14:31:27 +09:00
Rui Ueyama fdc935718d Upgrade zlib in ./third-party to v1.3.1 2024-04-19 13:03:36 +09:00
Rui Ueyama 18d3b64bfb Upgrade zstd in ./third-party to v1.5.6 2024-04-19 12:35:31 +09:00
Rui Ueyama ddc63ba9b2 Upgrade OneTBB in ./third-party to version 2021.12.0 2024-04-19 12:28:54 +09:00
Rui Ueyama 5576b88604 Upgrade blake3 in ./third-party to v1.5.1 2024-04-19 12:25:41 +09:00
Rui Ueyama 852be4a465 Refactor 2024-04-18 22:15:03 +09:00
Rui Ueyama fb3c6029d0 Do not link against libblake3.so if we built it from ./third-party
Fixes https://github.com/rui314/mold/issues/1238
2024-04-18 21:57:16 +09:00
Rui Ueyama 9acd9ae894 Refactor 2024-04-18 21:08:48 +09:00
Rui Ueyama d478addd2b Refactor 2024-04-18 20:47:14 +09:00
Rui Ueyama 6463a7c48a Fix non-deterministic behavior 2024-04-18 20:21:55 +09:00
Rui Ueyama 7434465334 Fix CI 2024-04-18 17:00:29 +09:00
Rui Ueyama f7b705959e Remove a pragma
It looks like Clang recognize `#pragma GCC unroll`. Instead of adding
more C preprocessor directives here, I'd like to rely on the default
compiler optimizations.
2024-04-18 16:11:02 +09:00
Rui Ueyama 1648f716f4 Attempt to fix CI 2024-04-18 16:00:11 +09:00
Rui Ueyama 108b08fadb Fix a test 2024-04-18 14:47:36 +09:00
Rui Ueyama 204566cd14 Fix a crash bug involving synthesized symbols
If a synthesized symbol overrides an imported symbol, the symbol's
`is_imported` flag must be reset.

Technically, `compute_import_export` is called too early, and this
function call should be moved after `create_synthetic_sections`.
However, fixing the issue that way was very hard because until we
create output sections, we don't know what __start_/__stop_ symbols
need to be synthesized, but in order to create output sections,
we need to compute import/export bits.

So, in this commit, we simply reset `is_imported` flag for
synthesized symbols.

https://github.com/rui314/mold/pull/1236
2024-04-18 14:45:58 +09:00
Rui Ueyama a3b4192e15 Revert "Give symbols in .so higher priority than those in .a"
This reverts commit dfa26d0882 because it
caused mysterious runtime issues with XWayland. I also observed that the
change affected gnupg and others.

Fixes https://github.com/rui314/mold/issues/1235
2024-04-15 21:42:52 +09:00
Rui Ueyama dfa26d0882 1;10;0cGive symbols in .so higher priority than those in .a
Previously, .so and .a were of the same priority and therefore symbols
in those were resolved based on their positions in the command line;
whichever file appears first in the command line took precedence.

Here is the problem we are trying to solve with this change: KiCad
passes unnecessary .a files to the linker along with some .so files.
Some symbols are defined both by .a and by .so.

If a symbol is resolved from .a, the linker pulls out the file from
the archive, but because the .a file does not really provide a
complete set of object files, it ended with "undefined symbol" error.

If a symbol is resolved from .so, everything is fine.

This is arguably a bug in KiCad, or at least depending on the order of
files in the command line is very fragile. But maybe this change could
fix the issue without too much side effects. So let's see how it goes.

Fixes https://github.com/rui314/mold/discussions/1234
2024-04-15 12:19:50 +09:00
Rui Ueyama 2683a07955 Refactor 2024-04-14 19:11:54 +09:00
Rui Ueyama 62bfc5fd8c Remove unnecessary dependencies 2024-04-13 21:13:13 +09:00
Rui Ueyama f666282b4e Silence -Wunused-result
Fixes https://github.com/rui314/mold/issues/1228
2024-04-13 17:30:56 +09:00
Rui Ueyama 77aefdf6a6 Refactor 2024-04-13 17:30:32 +09:00
Rui Ueyama 60ce1aaf01 Improve a test
We want to make sure that absolute symbols in DSOs are dynamically
resolved.
2024-04-12 16:36:40 +09:00
Rui Ueyama 496e2f3eb3 Refactor 2024-04-11 14:26:37 +09:00
Rui Ueyama 93bae76f49 Update mold.1 (automated commit) 2024-04-10 07:04:37 +00:00
Rui Ueyama 7d17aa83eb Add --Bsymbolic-non-weak and --Bsymbolic-non-weak-functions
GNU ld doesn't support these options, but LLVM lld do.
2024-04-10 16:00:19 +09:00
Rui Ueyama 7835e45ded Update mold.1 (automated commit) 2024-04-10 05:28:22 +00:00
Rui Ueyama 0cf209002c Update the man page 2024-04-10 14:27:50 +09:00
Rui Ueyama 57f2260301 Update mold.1 (automated commit) 2024-04-09 12:24:04 +00:00
Rui Ueyama 76445ce73c Update the man page 2024-04-09 21:23:28 +09:00
Rui Ueyama 99a5b1541e Support -z start-stop-visibility=hidden
Fixes https://github.com/rui314/mold/issues/826
2024-04-08 13:11:15 +09:00
Rui Ueyama d432e987a0 Ignore --long-plt option
Our ARM32 PLT is always long, so we can safely ignore the flag.

Fixes https://github.com/rui314/mold/issues/1230
2024-04-06 10:29:38 +09:00
Rui Ueyama 71457375e4 Simplify 2024-04-05 22:37:12 +09:00
Rui Ueyama 8dc311c2d2 Attempt to fix CI 2024-04-05 22:31:27 +09:00
Rui Ueyama faa5e57913 Simplify 2024-04-05 21:08:57 +09:00
Rui Ueyama 4396784dbd Handle STT_COMMON as a synonym for STT_OBJECT 2024-04-05 20:33:13 +09:00
Rui Ueyama 81b714c4f3 Simplify 2024-04-03 15:29:14 +09:00
Rui Ueyama cb739c62a9 Refactor 2024-04-01 23:59:08 +09:00
Rui Ueyama 58cfc6ba39 Make RISC-V build reproducible 2024-03-30 16:28:46 +09:00
Rui Ueyama fafc315dac Simplify 2024-03-29 21:52:52 +09:00
Rui Ueyama ffcd64792d Update mold.1 (automated commit) 2024-03-29 11:14:42 +00:00
Rui Ueyama 8c24b22b2d Update the man page 2024-03-29 18:03:20 +09:00
Rui Ueyama 6fe9bdc3db Simplify 2024-03-29 17:43:06 +09:00
Rui Ueyama 9d8b243e39 Keep symbols specified by --undefined-glob during garbage collection 2024-03-29 17:39:12 +09:00
Rui Ueyama 9884e19b7f Attempt to fix Windows bot 2024-03-29 17:39:12 +09:00
Rui Ueyama 5304a343e4 Simplify 2024-03-29 15:42:10 +09:00
Rui Ueyama 38e8f06def Use trap instructions instead of nop to fill gaps 2024-03-29 15:39:59 +09:00
Rui Ueyama b93b85bcd5 Refactor 2024-03-29 12:38:57 +09:00
Rui Ueyama 587360662c Refactor 2024-03-29 11:25:36 +09:00
Rui Ueyama 95431aa7cf Do not run certain tests on qemu user-mode emulation
Fixes https://github.com/rui314/mold/pull/1206
2024-03-28 23:29:53 +09:00
Rui Ueyama 7de092df28 Remove dead code 2024-03-28 18:01:03 +09:00
Rui Ueyama 03b57c2655 Simplify 2024-03-28 17:47:28 +09:00
Rui Ueyama a1c835b993 Support --undefined-glob option 2024-03-28 16:44:43 +09:00
Rui Ueyama 4ada2f52da Refactor 2024-03-28 16:25:21 +09:00
Rui Ueyama 9bb1a8207a Update README.md 2024-03-28 13:08:53 +09:00
Rui Ueyama a9e76295ff Simplify 2024-03-28 11:52:33 +09:00
Rui Ueyama 4e3364ddd3 Format 2024-03-27 18:42:55 +09:00
Rui Ueyama 6e5ae45c1a Disable test on ppc64le
Fixes https://github.com/rui314/mold/issues/1221
2024-03-27 16:27:37 +09:00
Rui Ueyama 11c9376a50 Fix tests for musl libc-based systems
Fixes https://github.com/rui314/mold/issues/1221
2024-03-27 16:27:37 +09:00
Rui Ueyama b5f2a7b1ce Do not call do_lto() if all LTO input files are dead
Fixes https://github.com/rui314/mold/issues/1226
2024-03-27 15:27:52 +09:00
Rui Ueyama 3df7c8e89c Export __global_pointer$ from executable
RISC-V psABI requires that symbol to be exported from an executable
if there's a GP-relative reference. For simplicity, we always export
it from executable as long as it has a .dynamic section.

https://github.com/rui314/mold/issues/1222
2024-03-25 17:57:52 +09:00
Rui Ueyama 0edbe29d38 Simplify 2024-03-25 17:57:52 +09:00
Rui Ueyama 8df5a76203 Attempt to fix Windows CI 2024-03-25 17:57:52 +09:00
Rui Ueyama 32c4a09deb Fix file paths in .repro tar file
Previously, all pathnames were accidentally recorded as the name of
the tar file itself.

Fixes https://github.com/rui314/mold/issues/1227
2024-03-25 17:15:51 +09:00
Rui Ueyama ee6907f678 Fix "skipping incompatible file" errors
https://github.com/rui314/mold/pull/1217
2024-03-25 14:52:54 +09:00
Rui Ueyama 03640029db Refactor 2024-03-21 15:03:45 +09:00
Rui Ueyama 7a65ed9082 Refactor 2024-03-21 11:00:13 +09:00
Rui Ueyama b10f818106 Attempt to fix Windows build 2024-03-21 10:42:30 +09:00
Rui Ueyama caad70dd6f Do not group mergeable sections in an output file
Runtime doesn't care where mergeable sections are, but it's reported
that Valgrind does. So, grouping mergeable sections just doesn't seem
to make sense.

https://github.com/rui314/mold/pull/1223
2024-03-20 22:15:05 +09:00
Rui Ueyama 6fe4f23074 Attempt to fix CI 2024-03-20 18:41:57 +09:00
Rui Ueyama fd8fb73492 Refactor 2024-03-20 17:37:57 +09:00
Rui Ueyama 7c8ed4d2e1 Refactor 2024-03-20 15:05:16 +09:00
Rui Ueyama 08fada7de0 Update README.md 2024-03-20 13:44:09 +09:00
Rui Ueyama 163975d82a Make linker script INPUT command to look for a file from the script's directory
https://github.com/rui314/mold/pull/1217
2024-03-19 17:16:38 +09:00
Rui Ueyama dda521e2bc [ARM32] Show "recompile with -fPIC" error for absolute relocations
Fixes https://github.com/rui314/mold/issues/1220
2024-03-19 13:19:05 +09:00
Rui Ueyama e7dc90dadc Refactor 2024-03-18 17:10:18 +09:00
Rui Ueyama 8375741489 Merge pull request #1201 from nga888/win-mem-map-output-file
Add "basic" support for memory mapping to Windows OutputFile
2024-03-16 11:35:25 +09:00
Rui Ueyama 042b14653e Do not update the man page for branches other than main 2024-03-16 09:18:48 +09:00
Rui Ueyama c7f6a91da5 Bump mold version to 2.30.0
libtool mistakes mold 2.4.1 as GNU ld 2.4 and wrongly concludes that our
linker does not support anonymous versioning and suppresses some uses of
version scripts. That has been causing subtle compatibility issues with
programs that use libtool to create their .so files.

Here is the code that mistakes our linker as GNU ld:
https://git.savannah.gnu.org/cgit/libtool.git/tree/m4/libtool.m4?h=v2.4.7#n5066

As a workaround, I decided to bump our linker version so that the version
number is sufficiently large. This is admittedly ugly but I think it's the
simplest solution for the problem.
2024-03-15 18:40:46 +09:00
Rui Ueyama c26260e38d Do not set symbol size to imported dynamic symbols
The dynamic linker does not seem to care about st_size of undefined
dynamic symbols, but semantically it shouldn't be an arbitrary number.
2024-03-15 11:35:48 +09:00
Rui Ueyama ac04d79ad2 Extend test timeout from 1 hour to 3 hours 2024-03-15 11:35:43 +09:00
Rui Ueyama 052b89e8d6 Copy mold to the top source directory
test/gentoo-test.sh depends on the presence of the file.
2024-03-14 16:15:29 +09:00
Rui Ueyama c395da1c54 Do not create an unnecessary gap in file for BSS
Fixes https://github.com/rui314/mold/issues/1216
2024-03-13 16:01:04 +09:00
Rui Ueyama 16b0564d49 Fix CI 2024-03-12 14:38:42 +09:00
Rui Ueyama d21207cc79 Handle sections with an unknown section type as errors
Fixes https://github.com/rui314/mold/issues/1215
2024-03-12 14:13:52 +09:00
Rui Ueyama c4b69a1077 Re-throw a signal
Previously, mold exists silently when it gets killed by SIGSEGV.
This change makes it verbose; now the parent process would report
an error.
2024-03-11 16:04:55 +09:00
Rui Ueyama c85dd8881b Refactor 2024-03-10 18:21:04 +09:00
Rui Ueyama 8eae0a33b3 [PPC32] Do not discard .got2 even if --gc-sections is given
Even though .got2 may not be referenced directly, we use that section
when processing relocations.
2024-03-10 18:16:11 +09:00
Rui Ueyama 6356fa09e9 Fix gentoo package name 2024-03-09 16:18:07 +09:00
Rui Ueyama 641e7c2b05 Use madvise instead of munmap
Using madvise(2) is clearer than munmap(2), and the madvise approach
seems to be slightly faster than mmap on my machine.
2024-03-09 13:39:59 +09:00
Rui Ueyama c60d1d0877 Use xxhash instead of gdb_hash for the internal hashmap for .gdb_index
Our ConcurrentMap uses linear probing to find unused hash table entry.
It gives up if 128 consective slots are occupied, and the whole process
dies with the "ConcurrentMap is full" error message. So our hash
function's quality must be high.

For .gdb_index, we used to use gdb_index() to compute keys for the
ConcurrentMap. It turned out that the function's quality is poor,
generating very similar output for short strings.

This commit changes the hash function to xxhash.

Fixes https://issues.chromium.org/issues/40276991#comment5
2024-03-06 13:12:53 +09:00
Rui Ueyama c45dd19d47 Do not trap SIGABRT unless older versions of TBB is in use 2024-03-05 10:04:54 +09:00
Rui Ueyama 51f871f43b Silently ignore broken .llvm_addrsig
Fixes https://github.com/rui314/mold/issues/1213
2024-03-04 16:57:12 +09:00
Rui Ueyama 89a4720575 Correctly print out error messages from signal handlers 2024-03-03 14:27:43 +09:00
Rui Ueyama 081e447a1b Simplify 2024-03-02 17:42:57 +09:00
Rui Ueyama da0ee683a3 Show sha256 checksum 2024-03-02 13:27:27 +09:00
Rui Ueyama c6e5e2c0a0 Dogfood setup-mold 2024-03-01 20:23:35 +09:00
Rui Ueyama fb3c166f80 Bump mold version to 2.4.1 2024-03-01 11:30:05 +09:00
Rui Ueyama 39643aaf94 Fix GCC warning
Fixes https://github.com/rui314/mold/issues/1208
2024-03-01 10:44:35 +09:00
Rui Ueyama 50bdf39ba5 Mark shared symbols as weak if all references are weak
Previously, mold marked an imported symbol as a strong one if the
symbol came from a DSO and was exported as a strong symbol by the DSO.
This logic resulted in a miscomputation of the weakness bit, causing a
compatibility issue with other linkers.

Now, an imported symbol is marked as strong only when there's at least
one strong reference to it. In other words, if all references to an
imported symbol are weak, the symbol will be imported as a weak one.

Fixes https://github.com/llvm/llvm-project/issues/83080
2024-02-29 12:57:11 +09:00
Rui Ueyama 1e413d4121 Fix GCC warning
Fixes https://github.com/rui314/mold/issues/1205
2024-02-28 14:03:41 +09:00
Rui Ueyama fcda712238 Attempt to fix GCC warnings
Fixes https://github.com/rui314/mold/issues/1204
2024-02-27 16:38:45 +09:00
Rui Ueyama d4ff48a07e [PPC64V2] Emit _savegpr0_*, _restgpr0_*, _savegpr1_* and _restgpr1_* symbols
Fixes https://github.com/rui314/mold/issues/1203
2024-02-27 14:35:19 +09:00
Rui Ueyama 21f25545a8 Update README 2024-02-27 12:02:44 +09:00
Andrew Ng 37f975bf82 Add "basic" support for memory mapping to Windows OutputFile
This is a "basic" implementation that does not make use of intermediate
temporary files.

Has been seen to improve linking performance by up to ~1.78x.
2024-02-26 11:34:33 +00:00
Rui Ueyama 58558e319c RISC-V: Define __global_pointer$ for DSO
Fixes https://github.com/rui314/mold/issues/1182
2024-02-26 14:38:38 +09:00
Rui Ueyama 48f6a08352 Refactor 2024-02-26 12:29:27 +09:00
Rui Ueyama 01e9f42c10 Merge pull request #1198 from nga888/win-build-tidy
Minor fixes for the Windows build
2024-02-26 12:12:11 +09:00
Rui Ueyama 8c3967886c Remove code for the sold linker 2024-02-25 14:29:53 +09:00
Rui Ueyama 8a4fb3b445 Merge pull request #1199 from nga888/win-mem-map-file-handling
Fixes and improvements to Windows file handling and memory mapping
2024-02-25 12:58:08 +09:00
Rui Ueyama 04c9b62660 Update README 2024-02-24 15:08:05 +09:00
Rui Ueyama 4790349f79 Update README 2024-02-24 15:07:25 +09:00
Rui Ueyama 3e6005a1e7 Update benchmark results 2024-02-24 15:04:34 +09:00
Andrew Ng 9e3565027a Fixes and improvements to Windows file handling and memory mapping
Prior to this change, links on Windows were failing with:

  mold: fatal: <input file>: CreateFileMapping failed: 5

"5" is the Windows error code for ERROR_ACCESS_DENIED.

Use native Windows file API in MappedFile. Create read only mapping with
FILE_MAP_COPY view because the file mapping contents may be modified in
process but should not be written back.

On Windows, it is important that files are opened in "binary" mode to
avoid automatic "text" mode conversions which can result in "corrupted"
input/output.
2024-02-23 14:40:39 +00:00
Rui Ueyama 6d8e6afbf2 Fix R_PPC64_DTPREL16_LO_DS
Fixes https://github.com/rui314/mold/issues/1192
2024-02-23 17:14:25 +09:00
Rui Ueyama 5b5f431717 Fix CI 2024-02-22 09:13:26 +09:00
Andrew Ng 796e2556b6 Minor fixes for the Windows build
Removes some Windows build warnings.

Fixes conversion of Windows FILETIME to nsec in get_usage() used by
TimerRecord.
2024-02-21 15:24:07 +00:00
Rui Ueyama 8090737d56 Merge sections with different flags into a single section
Previously, mold didn't merge sections with the same name but different
section flags into a single section. This behavior is different from other
linkers and caused a compatibility issue.

Now, mold merges input sections by their names and types.

Fixes https://github.com/rui314/mold/issues/1196
2024-02-21 18:50:47 +09:00
Rui Ueyama d39a0c7035 Refactor 2024-02-21 18:21:03 +09:00
Rui Ueyama de696ba5a4 --repro: Do not try to reopen files with different paths
Fixes https://github.com/rui314/mold/issues/1197
2024-02-21 17:11:04 +09:00
Rui Ueyama cefa2d9100 Add Red Hat Enterprise Linux
Fixes https://github.com/rui314/mold/issues/1191
2024-02-20 15:11:42 +09:00
Rui Ueyama 9f07fd035c Support R_PPC64_DTPREL16_LO_DS
Fixes https://github.com/rui314/mold/issues/1192
2024-02-20 13:07:02 +09:00
Rui Ueyama 7ead7231c9 Fix CI 2024-02-19 16:50:23 +09:00
Rui Ueyama b0a3a5ce62 Drop SHF_COMPRESSED when creating a relocatable file
We always uncompress compressed sections when copying, so we should
not propagate the flag.

Fixes https://github.com/rui314/mold/issues/1195
2024-02-19 16:22:39 +09:00
Rui Ueyama 64c2084c8a Pass GCC offload data to the LTO backend
Fixes https://github.com/rui314/mold/issues/1190
2024-02-19 15:12:43 +09:00
Rui Ueyama 4c355239ad Refactor 2024-02-19 15:12:43 +09:00
Rui Ueyama 79169ea315 Format 2024-02-19 15:12:43 +09:00
Rui Ueyama 4db866d5c3 Merge pull request #1193 from gruenich/feature/range-loop-reference 2024-02-11 03:11:50 +09:00
Christoph Grüninger 83a5bfbfb1 elf/cmdline.cc: Add missing references in range-for loops
std::string is a non-trivial type, this change ensures its
copy-ctor and dtor don't get called.
Found by Clazy (range-loop-reference)


Signed-off-by: Christoph Grüninger <[email protected]>
2024-02-10 17:42:07 +01:00
Rui Ueyama c9651d9b2b Merge pull request #1187 from aokblast/fix/fileoffset 2024-02-04 00:37:32 +09:00
aokblast 8c99dd0f2c Feat: use accumulate address on sections with SHT_ALLOC 2024-02-03 22:03:55 +08:00
Rui Ueyama 25351379ab Fix CI 2024-02-02 02:59:50 +09:00
Rui Ueyama ba67c5d977 Fix CI 2024-02-02 02:35:12 +09:00
Rui Ueyama 7f8d77d84e Do not optimize absolute symbols in DSOs 2024-02-02 01:28:09 +09:00
Rui Ueyama 91a88ee80f Merge pull request #1186 from dancrossnyc/upstream
illumos: Treat absolute symbols specially
2024-02-02 01:25:18 +09:00
Rui Ueyama 206fe8527f Do not try to use /proc/self/exe on macOS
That path does not exist on macOS.

Fixes https://github.com/rui314/mold/issues/1185
2024-02-01 16:23:24 +01:00
Dan Cross bed5b1731b illumos: Treat absolute symbols specially
illumos is a descendent of Solaris/OpenSolaris, and treats
symbols with shndx=SHN_ABS and st_value=0 specially, such that
they should be marked imported.  This change adds a special
case for this behavior, wrapped up in a function that #ifdef's
out on other platforms.  With this patch, executables linked
with mold on illumos run; without it, they do not.

The original behavior was spotted by Luqman Aden (@luqmana).
This also patches a small bogon in the third-party `mimalloc`
code.  I've sent that same fix upstream, but so far the
maintainer has not resonded, so replicate here.

Fixes #1183

Signed-off-by: Dan Cross <[email protected]>
2024-02-01 13:55:05 +00:00
Rui Ueyama c36b83fdea Merge pull request #1177 from ishitatsuyuki/icf-workaround
Ignore addrsig sections corrupted by strip
2024-01-20 20:59:56 +09:00
Tatsuyuki Ishi fede4a8102 Ignore addrsig sections corrupted by strip
When removing symbols, the indices in .llvm_addrsig also needs to be
updated, but binutils is not aware of this and leaves the table in a
corrupt state.

Use the same test as what LLD uses to reject potentially corrupted addrsig
sections.

Unfortunately, testing this seems tricky. While producing a file with OOB
addrsig index is not hard, it's hard to consistently trigger a segfault
with that access.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2024-01-20 17:28:51 +09:00
Rui Ueyama 29c0baa151 Merge pull request #1175 from filipnavara/aadwarf 2024-01-19 18:57:18 +09:00
Rui Ueyama 5d04d9c6cd Merge pull request #1176 from sicherha/fix_unit_tests_on_s390x 2024-01-19 17:58:52 +09:00
Christoph Erhardt 2415b3e0bb [ELF][S390X] Skip tests that still fail with GCC 14
Signed-off-by: Christoph Erhardt <[email protected]>
2024-01-18 21:53:12 +01:00
Filip Navara d832547ba2 Add support for .eh_frame section on arm32 2024-01-18 18:28:26 +01:00
Muhammad Mominul Huque f05e32df4a Update README.md
GCC doesn't accept a path as an argument to `-fuse-ld`. `-fuse-ld=mold` is enough.

Tested with
```
gcc (GCC) 13.2.1 20231205 (Red Hat 13.2.1-6)
```
2023-12-31 18:21:30 +06:00
Rui Ueyama fe118f6347 Fix CI 2023-12-24 14:42:01 +09:00
Rui Ueyama 9554b92c86 Allow escaped meta-characters in version script patterns 2023-12-24 14:04:51 +09:00
Rui Ueyama 669ada024e Simplify 2023-12-24 13:53:02 +09:00
Rui Ueyama e1e16bf85a Fix version script priority
Previously, if two or more VERSION clauses match to the same symbol,
the first one took precedence. This was incompatible with GNU ld, which
gives the last one the highesth priority.

This change inverted the priority so that the last one will take
precedence other the others.

Fixes https://github.com/rui314/mold/issues/1158
2023-12-23 18:20:22 +09:00
Rui Ueyama 35516a6fc2 Do not include '@' in symbol name
Fixes https://github.com/rui314/mold/issues/1168
2023-12-23 15:37:39 +09:00
Rui Ueyama 51ecb10b01 Refactor 2023-12-23 15:35:43 +09:00
Rui Ueyama 10ce09fe0c Refactor 2023-12-23 15:16:02 +09:00
Rui Ueyama 0702d4185a Refactor 2023-12-19 15:32:43 +09:00
Rui Ueyama afe57e99d1 Update comments 2023-12-15 11:55:53 +09:00
Rui Ueyama e921486008 Fix CI
It seems some versions of objdump cannot disassemble c.li instruction.
2023-12-13 13:26:56 +09:00
Rui Ueyama 70d59ca1cd Improve test 2023-12-12 22:11:35 +09:00
Rui Ueyama 2ccaa81aab Relax a GOT load into a direct address materialization
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/397
2023-12-12 16:41:18 +09:00
Rui Ueyama 4db2eb91e9 Do not rewrite endbr64 of exported functions
Pointed out by @MaskRay at
https://github.com/llvm/llvm-project/issues/74400#issuecomment-1848686317.
2023-12-12 15:36:43 +09:00
Badini Rachid RodrigueandBADINI Rachid Rodrigue a4daff2d83 Add entry for EndeavouOS (#1165)
---------

Co-authored-by: BADINI Rachid Rodrigue <[email protected]>
2023-12-12 04:08:42 +09:00
Rui Ueyama cc884d57ca Fix cross building of ARM64 binaries on big-endian machines
It's probably very rare to do so, but mold couldn't create ARM64
binaries on big-endian machines due to a typo in an ELF struct
definition.
2023-12-10 16:06:52 +09:00
Rui Ueyama 0c8a872c37 Avoid using the HOST environment variable
It seems HOST is a fairly common environment variable. Let's use
MACHINE instead.

Fixes https://github.com/rui314/mold/issues/1163
2023-12-07 09:45:29 +09:00
Rui Ueyama 663ac74610 Simplify 2023-12-06 19:51:22 +09:00
Rui Ueyama f04aebf1e0 Simplify 2023-12-06 13:04:58 +09:00
Rui Ueyama bcf3b48e98 Simplify 2023-12-06 11:33:46 +09:00
Rui Ueyama e7cc9455c9 Merge pull request #1161 from ishitatsuyuki/prealloc
Use fallocate when creating a new output
2023-12-06 11:05:17 +09:00
Tatsuyuki Ishi e909535684 Use fallocate when creating a new output
Using ftruncate() creates holes inside files, that on first (write) page
fault gets allocated an actual disk block.  There are several
disadvantages with this:
- Allocating block one-by-one is slower than doing it all at once.
- As we write to the output in parallel the write order is not exactly
  sequential.  The allocated blocks can also be out-of-order and make the
  on-disk representation fragmented.

Instead, use posix_fallocate() which allocates a contiguous on-disk block
(if possible).  It's arguably a better fit for linker output, since holes
are unlikely to be present after writing all the output (any contiguous
zeroes should just go into .bss).

I benchmarked this by linking mold with debug symbols.  On an 8-core
desktop, it is 5% (1.0s -> 0.95s) faster, but on a 64-core workstation it
is actually 40% slower (0.37s -> 0.52s).  The total amount of System time
is reduced (6.7s -> 5.2s), however.  I suspect that the reduced page fault
work ends up causing more lock contention.

Despite potential regression on high-core systems I still think this
change is justified because of the better on-disk layout.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2023-12-05 16:07:48 +09:00
Rui Ueyama cea54cb865 Check the runtime libtbb version to handle sigabrt 2023-12-05 12:25:52 +09:00
Rui Ueyama 3bc2e9bdb1 Revert "Set DF_SYMBOLIC if -Bsymbolic is given"
This reverts commit 9d35710419 to unbreak CI.
2023-12-04 16:07:56 +09:00
Rui Ueyama 159960c72e Fix errors in the help message; this change was made using ChatGPT 2023-12-04 15:34:56 +09:00
Rui Ueyama 9d35710419 Set DF_SYMBOLIC if -Bsymbolic is given
I don't think this would make any difference, but the ELF spec says
that the flag is set if symbols are bound locally.
2023-12-04 15:10:01 +09:00
Rui Ueyama bdcf448605 Emit TLS common symbols in .tls_common
Section names are not significant in executables or DSOs, so this is
a purely aesthetic change.
2023-12-04 13:13:33 +09:00
Rui Ueyama 72eb180028 Upgrade OneTBB to version 2021.11.0 2023-12-02 12:34:16 +09:00
Rui Ueyama fe427bfe7a Do not compute per-InputSection address-taken bit for -z rewrite-endbr
We now compute per-Symbol address-taken bit in rewrite_endbr,
so this step is not necessary anymore.
2023-12-02 12:34:16 +09:00
Rui Ueyama 348f5c7086 Merge pull request #1160 from tzussman/ci_fix 2023-12-02 07:52:41 +09:00
Tal Zussman e09b877146 Fix typos in ci.yml 2023-12-01 10:01:25 -05:00
Rui Ueyama aeb7ba4731 Add asserts 2023-12-01 21:03:15 +09:00
Rui Ueyama 421cd1c3ca Revert "Attempt to fix CI"
This reverts commit 5e8729bd6f.
2023-12-01 10:26:10 +09:00
Rui Ueyama 5e8729bd6f Attempt to fix CI 2023-12-01 10:19:48 +09:00
Rui Ueyama 76d057a418 Archive entire build directory when CI fails 2023-11-30 19:34:08 +09:00
Rui Ueyama ea9864bbd5 Do not try to demangle C++ symbols as Rust ones
Previously, we always tried to demangle a symbol name as a Rust
symbol first and then attempted to demangle it as a C++ symbol.
This resulted in an incorrect demangled result, as the Rust legacy
mangling scheme is not distinguishable from C++.

This patch fix the issue by adding the "is_rust_obj" flag to the
ObjectFile. We try to demangle a symbol as a Rust one before as a C++
only if the flag is true.

Fixes https://github.com/rui314/mold/issues/1159
2023-11-30 13:53:23 +09:00
Rui Ueyama 3d9b4d5c05 Bump mold version to 2.4.0 2023-11-29 17:58:00 +09:00
Rui Ueyama d06bfe0ac3 Update GitHub sponsor list 2023-11-29 17:48:11 +09:00
Rui Ueyama 6540294a81 Fix CI 2023-11-29 17:15:39 +09:00
Rui Ueyama 02a7640047 Fix build artifact pathnames 2023-11-29 16:59:23 +09:00
Rui Ueyama f4c5a8a42e Allow multiple .eh_frame sections in a single object file
A `.eh_frame` section contains data for exception handling. Usually,
an object file contains only one `.eh_frame` section, which explains
how to handle exceptions for all text sections in the same object file.

However, it appears that, in rare cases, we need to handle object
files containing multiple `.eh_frame` sections. An example of this is
the `/usr/lib/clang/17/lib/x86_64-redhat-linux-gnu/clang_rt.crtbegin.o`
file, which is provided by the `compiler-rt` package of Fedora 39.
Specifically, I'm using the `quay.io/fedora/fedora:39` Docker image.
The file contains two `.eh_frame` sections.

One `.eh_frame` in the file is of type `STT_X86_64_UNWIND` and the
other is of `STT_PROGBITS`. It's possible that the file was created
with `ld -r`, and the linker failed to merge the two incoming
`.eh_frame` sections into one output section due to the difference in
section types.

We did not expect such inputs and consequently produced corrupted
output files.

This commit improves our linker so that mold can handle multiple
`.eh_frame` sections in a single object file.

Fixes https://github.com/rui314/mold/issues/1157
2023-11-29 16:10:36 +09:00
Rui Ueyama 0fdbace9b2 Improve compatibility of precedences in version script patterns
Previously, symbol names or wildcard patterns in version script files
were processed strictly from top to bottom. When a single symbol
matches two or more patterns, the first one was given precedence.

However, GNU ld appears to treat exact matches differently, assigning
them higher precedence over wildcard patterns. This discrepancy led to
programs linked with Qt 6.6.1 using mold failing to launch.

Fixes https://github.com/rui314/mold/issues/1158
2023-11-28 15:43:48 +09:00
Rui Ueyama cab6014154 Merge pull request #1156 from ywgrit/main
Remove assertions to make errors exposed in a customized way
2023-11-26 18:55:40 +09:00
Rui Ueyama 000ce0ee52 Handle LLVM-generated TLSDESC code sequence
It had been assumed that the TLSDESC code seqeunce looks like this:

  lea    0(%rip), %rax
      R_X86_64_GOTPC32_TLSDESC    foo
  call   *(%rax)
      R_X86_64_TLSDESC_CALL       foo

However, LLVM seems to also emit something like this:

  lea    0(%rip), %reg
      R_X86_64_GOTPC32_TLSDESC    foo
  ...
  mov    %reg, %rax
  ...
  call   *(%rax)
      R_X86_64_TLSDESC_CALL       foo

That means when we rewrite the LEA instruction to relax the code
sequence, we need to handle destination registers other than %rax.

The wrong assumption caused a program crash as reported as
https://bugs.gentoo.org/914849.
2023-11-26 18:49:20 +09:00
ywgrit d720a2011c Remove assertions to make errors exposed in a customized way 2023-11-26 17:04:28 +08:00
Rui Ueyama c91055271b Simplify 2023-11-24 16:15:37 +09:00
Rui Ueyama 1478acd551 Do not save strings if not necessary 2023-11-24 11:48:19 +09:00
Rui Ueyama b3404c07d7 Add a timer prober 2023-11-24 10:44:18 +09:00
Rui Ueyama 94767dc0e7 Fix a crash bug 2023-11-24 10:14:00 +09:00
Rui Ueyama f957acfe11 Add an entry for Amazon Linux 2023-11-24 09:30:56 +09:00
Rui Ueyama 7fc43ccc3a Add comments 2023-11-24 08:40:57 +09:00
Rui Ueyama dc5b9508d9 Simplify 2023-11-24 06:39:27 +09:00
Rui Ueyama ef056d8ed1 Refactor 2023-11-24 06:38:29 +09:00
Rui Ueyama 6a63671ef5 Simplify 2023-11-23 12:22:14 +09:00
Rui Ueyama d3867766af Remove redundant check
`is_ld("ld")` returns true
2023-11-23 11:47:33 +09:00
Rui Ueyama 1ae4b9571b Merge pull request #1154 from andreas-schwab/main
mold-wrapper: also wrap posix_spawnp
2023-11-23 11:39:07 +09:00
Andreas Schwab 3fd1cec20e mold-wrapper: also wrap posix_spawnp
Fixes issue 1153.

Signed-off-by: Andreas Schwab <[email protected]>
2023-11-22 14:59:11 +01:00
Rui Ueyama 28b16eea19 Rename classes 2023-11-22 20:56:21 +09:00
Rui Ueyama 37f32a9008 Simplify 2023-11-22 14:12:37 +09:00
Rui Ueyama 8415252322 Do not use std::aligned_alloc
Fixes https://github.com/rui314/mold/issues/1152
2023-11-22 11:52:33 +09:00
Rui Ueyama b3984c9580 Simplify 2023-11-21 21:23:47 +09:00
Rui Ueyama 6616995804 Refactor 2023-11-21 12:23:49 +09:00
Rui Ueyama de7d37e1fc Do not count .tbss into account when creating PT_GNU_RELRO
Fixes https://github.com/rui314/mold/issues/1151
2023-11-21 11:44:52 +09:00
Rui Ueyama 3cb8a528a5 Make -z rewrite-endbr to work without -ffunction-sections
Now we can rewrite an endbr64 instruction even if it is not at the
beginning of a section.
2023-11-20 17:36:23 +09:00
Rui Ueyama 8bb01e1a0e Fix CI 2023-11-20 14:25:03 +09:00
Rui Ueyama 0416d7ed80 Add --nmagic
Fixes https://github.com/rui314/mold/issues/1144
2023-11-20 13:35:04 +09:00
Rui Ueyama c02c04f08a Improve dist.sh 2023-11-20 11:55:14 +09:00
Rui Ueyama efb952ef12 Use the release version of setup-mold GitHub action 2023-11-19 10:32:51 +09:00
Rui Ueyama 04b145d795 Add comments and fix SHA256 digest 2023-11-19 09:36:04 +09:00
Rui Ueyama 1830fa1d84 Pin docker images with sha256 digests for additional security 2023-11-18 12:25:37 +09:00
Rui Ueyama a2b300b863 Fix CI 2023-11-17 19:12:19 +09:00
Rui Ueyama 2d8297a562 Fix CI 2023-11-17 18:22:16 +09:00
Rui Ueyama deb7728b46 Fix CI 2023-11-17 18:08:13 +09:00
Rui Ueyama bbd6d86af4 Fix CI 2023-11-17 17:57:59 +09:00
Rui Ueyama b6361b8cad Refactor 2023-11-17 17:51:25 +09:00
Rui Ueyama 04fdae124f Refactor 2023-11-17 17:41:24 +09:00
Rui Ueyama 29df7093a8 Refactor 2023-11-17 17:18:53 +09:00
Rui Ueyama 18212a21ab Refactor 2023-11-17 17:04:43 +09:00
Rui Ueyama e13d28bfe6 Create non-x86 binaries on daily basis
Building non-native binaries using Qemu is extremely heavy.
It takes ~2 hours on a GitHub Actions runner. We don't want to
run it on each push.
2023-11-17 15:45:39 +09:00
Rui Ueyama 667204ac7c Make dist.sh to work on macOS 2023-11-17 15:09:31 +09:00
Rui Ueyama 76ea83e791 Create binary tarballs for non-x86-46 targets 2023-11-17 14:15:04 +09:00
Rui Ueyama 55daf7385d Cache Docker images for GitHub Actions 2023-11-17 13:42:54 +09:00
Rui Ueyama 0e66e4b7e9 Create distribution tarballs for each commit 2023-11-16 22:54:38 +09:00
Rui Ueyama fe485db9b4 Refactor 2023-11-16 18:30:31 +09:00
Rui Ueyama b3dc4879fd Remove a global variable 2023-11-16 18:00:41 +09:00
Rui Ueyama 25ce3738b9 Update workflow 2023-11-16 16:50:33 +09:00
Rui Ueyama 22b8ac8470 Update mold.1 2023-11-16 07:16:13 +00:00
Rui Ueyama 6a4e128ef8 Document --spare-program-headers 2023-11-16 16:15:28 +09:00
Rui Ueyama 66d68c8a98 Auto-generate docs/mold.1 2023-11-16 16:15:28 +09:00
Rui Ueyama 76867af090 Regenerate mold.1
This file is created by `ronn` command.
2023-11-16 12:54:49 +09:00
Rui Ueyama 5d02248a0b Sort entries and fix typos 2023-11-16 12:54:38 +09:00
Rui Ueyama eb6c213f2a Add --spare-program-headers
This is a new experimental flag to make room at the end of PHDR
so that post-processing tools can add more entries as needed.

Fixes https://github.com/rui314/mold/issues/1148
2023-11-16 12:07:13 +09:00
Rui Ueyama efdac9afdd Merge pull request #1147 from Saldivarcher/add-trace-symbol-help-msg 2023-11-16 05:45:29 +09:00
Miguel Saldivar c6bfff2a04 Add --trace-symbol to the help message 2023-11-14 14:24:41 -06:00
Rui Ueyama 49066ea329 Bump mold version to 2.3.3 2023-11-14 14:41:42 +09:00
Rui Ueyama 25ceab07f7 Build mold on Debian 8 (Jessie)
Debian 8 was released in April 2015, which is old enough for
binary distribution. Previously, we used to use Debian 10 (Bullseye),
which was released in July 2019.
2023-11-14 12:44:02 +09:00
Rui Ueyama 6e97393740 Fix tests 2023-11-14 12:44:02 +09:00
Rui Ueyama ff3d54d26f Fix a crash bug in --defsym
Fixes https://github.com/rui314/mold/issues/1108
2023-11-13 20:09:25 +09:00
Rui Ueyama 25c9cf3976 Refactor 2023-11-13 19:57:50 +09:00
Rui Ueyama 5f2fb08cfd Make dist.sh reproducible
dist.sh script should now produce bit-by-bit identical output files now.

Fixes https://github.com/rui314/mold/issues/1146
2023-11-13 17:14:37 +09:00
Rui Ueyama 60bc56848f Fix tests for Debian 9 2023-11-13 13:37:35 +09:00
Rui Ueyama 600ca381fd Reduce the size of Symbol by 2 bytes 2023-11-12 13:39:44 +09:00
Rui Ueyama da3f5dd4ec Fix --dynamic-list for DSOs
--dynamic-list, --export-dynamic-symbol and --export-dynamic-symbol-list
have different semantics for executables and DSOs. If the output is an
executable, they specify a list of symbols that are to be exported.
If the output is a shared object, they specify the list of symbols that
are to be interposable.

mold havne't implemented the latter semantics. This commit fixes that
issue.

Fixes https://github.com/rui314/mold/issues/1071
2023-11-12 13:00:24 +09:00
Rui Ueyama b59911b0c1 Refactor 2023-11-11 15:09:51 +09:00
Rui Ueyama 8131528305 Rename long .rodata section names 2023-11-10 15:07:19 +09:00
Rui Ueyama 6a71e7dd4b Refactor 2023-11-09 18:57:13 +09:00
Rui Ueyama a63b2f70b2 Fix CI 2023-11-09 15:47:25 +09:00
Rui Ueyama 3f88964527 Map .ctors/.dtors into .init_array/.fini_array
.init_array/.fini_array haven't completely replace .ctors/.dtors, so
we need to convert .ctors/.dtors to .init_array/.fini_array.

Fixes https://github.com/rui314/mold/issues/1113
2023-11-09 12:43:58 +09:00
Rui Ueyama e18dc70af0 Refactor 2023-11-08 22:04:14 +09:00
Rui Ueyama 0c6daad215 Add more tests 2023-11-07 15:20:31 +09:00
Rui Ueyama 8c35c80bb7 Enable qemu tests by default 2023-11-07 13:55:56 +09:00
Rui Ueyama d42ba3bae4 Fix CI 2023-11-07 13:48:48 +09:00
Rui Ueyama 8c337b25df Run power10 tests on qemu only if qemu and cross GCC suports power10 2023-11-07 12:04:22 +09:00
Rui Ueyama 8d1c08bd03 Simplify 2023-11-07 11:25:03 +09:00
Rui Ueyama 5599a6f24f Skip test only on qemu 2023-11-07 11:06:13 +09:00
Rui Ueyama ef9a610dd1 Run tests as long as qemu and cross compiler are available
So that we can catch bugs like e11d64b5c7
earlier.
2023-11-07 11:00:26 +09:00
Rui Ueyama 31c3b5397b [POWER10] Emit dynamic relocation for ifunc
Previously, we didn't emit a dynamic relocation for a statically-
initialized function pointer pointing to an ifunc on POWER10, e.g.

  int fn() __attribute__((ifunc("resolve_fn")));
  void *ptr = fn;

Fixes https://github.com/rui314/mold/issues/1142
2023-11-06 13:27:05 +09:00
Rui Ueyama e11d64b5c7 Do not run tests under qemu-i386 on i686 native host
Fixes https://github.com/rui314/mold/issues/1140
2023-11-06 12:44:28 +09:00
Rui Ueyama 9d91a2bc23 Revert "Do not crash if defsym'ed symbol didn't exist"
This reverts commit 5c7a75b3e4 and
8c41f21d3c because they broke CI.
2023-11-06 12:43:20 +09:00
Rui Ueyama 8c41f21d3c Fix CI 2023-11-05 22:30:43 +09:00
Rui Ueyama 5c7a75b3e4 Do not crash if defsym'ed symbol didn't exist
Fixes https://github.com/rui314/mold/issues/1108
2023-11-05 16:37:09 +09:00
Rui Ueyama 0804fbd095 Refactor 2023-11-05 16:11:27 +09:00
Rui Ueyama 0f78fa9c43 Attempt to fix tests on 32-bit x86
Fixes https://github.com/rui314/mold/issues/1140
2023-11-05 11:01:31 +09:00
Rui Ueyama d30e970eb8 Remove useless function call 2023-11-05 10:57:25 +09:00
Rui Ueyama edc2f852a1 Bump mold version to 2.3.2 2023-11-04 15:44:32 +09:00
Rui Ueyama 348e44a9c4 Reorganize tests 2023-11-04 14:43:47 +09:00
Rui Ueyama 42f663cac0 Silence TSAN errors that I believe false 2023-11-04 09:07:28 +09:00
Rui Ueyama 4dd5d2f8cb Propagate mergeable sections' sh_entsize and sh_addralign attributes
For --relocatable output, we need to pass through these attributes
for correctness. With this change, we'll have more .rodata sections
such as .rodata.str1.1, rodata.str1.4, etc. in the final executable,
but that should be fine because the runtime doesn't care about
section tables at all. The table isn't even loaded to memory at runtime.
2023-11-03 21:34:17 +09:00
Rui Ueyama 4cdfc7e72c Do not emit text relocations for IFUNC symbols in PDEs
IFUNC symbols are resolved at process startup by executing the function
that the symbol points to. This is used to select the "best" function at
runtime; for instance, the runtime may choose a faster version of memcpy
that uses SIMD instructions if they are available on the current system.

Thus, an IFUNC symbol has two addresses: the initial address (or the
resolver's address) and the resolved address, which is the return value of
the resolver.

In position-independent executables (PIEs), function pointers are loaded
from the GOT indirectly, and symbols are not directly referenced. In such
executables, the initial value of the GOT slot for an IFUNC symbol
contains the resolver address, and this is overwritten at runtime to the
resolved address upon process startup. When user code takes a pointer to
an IFUNC, it always reads the resolved address from GOT.

In contrast, position-dependent executables (PDEs) may have instructions
that directly refer to an IFUNC symbol, such as movabs on x86-64. The GOT
entry for an IFUNC holds the resolved address, so any direct reference
must also produce the resolved address to maintain pointer equality.
(C/C++ standards require that two pointers must be equal if and only if
they are taken for the same symbol.)

Previously, we emitted text relocations to modify instruction operands.
However, text relocations are undesirable and not always reliable. For
example, on ARM64, multiple instructions are used to materialize a
symbol's address, and it's not feasible to issue a dynamic relocation to
alter those instructions since the dynamic loader generally can only
modify 32-bit or 64-bit words.

In this commit, I have adopted a different strategy. An IFUNC symbol now
occupies two consecutive GOT slots in a PDE. The first slot holds the
symbol's PLT address, and the second slot holds the resolved address. The
PLT address is consistently used as the symbol's address throughout the
process, while the second slot is used only by the PLT entry to jump to
the resolved address.

This method ensures pointer equality without the need to emit text
relocations for IFUNC symbols in PDEs.
2023-11-02 12:27:55 +09:00
Rui Ueyama 9516da1751 Simplify 2023-10-31 21:14:48 +09:00
Rui Ueyama f3de82b2a2 Do not add the same set of tests twice 2023-10-31 19:32:46 +09:00
Rui Ueyama c4c506c1cb Make LoongArch range extension thunks shorter 2023-10-31 16:19:20 +09:00
Rui Ueyama 0c62a91ded Enable loongarch64 tests on loongarch64 hosts 2023-10-31 16:15:14 +09:00
Rui Ueyama 2fd0a4c60a Remove a warning because it's a bit too verbose 2023-10-31 16:10:42 +09:00
Rui Ueyama d3188e39df [LoongArch] Implement a workaround for R_LARCH_PCALA_LO12
It seems R_LARCH_PCALA_LO12 is sometimes used against JIRL even though
such use case is incorrect as per the psABI.

At least, `/usr/lib/loongarch64-linux-gnu/libc_nonshared.a(atexit.oS)`
on `cfarm400.cfarm.net` contains such relocation.

We need this patch to self-host mold on that cfarm machine.
2023-10-31 14:11:43 +09:00
Rui Ueyama 3229b5b7e3 Fix test 2023-10-31 12:22:39 +09:00
Rui Ueyama d9ede96aca Fix an incorrect assertion 2023-10-30 13:31:22 +09:00
Rui Ueyama 4b4219fc33 Fix tests for ARM32-on-ARM64 systems 2023-10-30 13:02:36 +09:00
Rui Ueyama 02ead29989 Fix build issue for ARM32-on-ARM64 systems 2023-10-30 13:02:35 +09:00
Rui Ueyama 37919009ab Do not report incompatibe relocation table as an error
Specifically, .llvm.call-graph-profile is always REL even on x86-64.
We can safely ignore the relocation table because it contains only
R_NONE relocations.

Fixes https://github.com/rui314/mold/issues/653
2023-10-28 19:12:20 +09:00
Rui Ueyama 782ff4f582 Fix test 2023-10-27 13:40:09 +09:00
Rui Ueyama 3c468c71a4 Merge pull request #1136 from sicherha/fix_aarch64_variant-pcs_test
Fix `aarch64_variant-pcs.sh` test on Linux
2023-10-27 11:38:54 +09:00
Christoph Erhardt a31679cf04 Fix aarch64_variant-pcs.sh test on Linux
The test expects the output format given by `llvm-readelf`:
```
5: 0000000000010698     0 FUNC    GLOBAL DEFAULT [VARIANT_PCS]   13 foo
```

However, in GNU's `readelf` implementation the symbol name comes first:
```
5: 0000000000010698     0 FUNC    GLOBAL DEFAULT   13 foo  [VARIANT_PCS]
```

Replace the regular expression with two `grep` calls piped together to
support both output formats.

Signed-off-by: Christoph Erhardt <[email protected]>
2023-10-26 23:59:24 +02:00
Rui Ueyama 9cd65ed152 Emit ARM32 mapping symbols for .plt and .plt.got 2023-10-26 13:20:24 +09:00
Rui Ueyama 79ad405319 Emit ARM32 mapping symbol strings only once 2023-10-26 13:20:24 +09:00
Rui Ueyama b60a164fcc Honor the --chroot option when handling --Map or --dependency-file 2023-10-24 12:34:24 +09:00
Rui Ueyama 2d4ba3ac74 Skip a test if musl
musl's tlsdesc implementation for arm32 is buggy.

Fixes https://github.com/rui314/mold/issues/1135
2023-10-23 23:47:13 +09:00
Rui Ueyama 42eabf9f71 Run a test for all targets 2023-10-23 18:39:53 +09:00
Rui Ueyama aa4b3f7d01 Attemp to fix a test
https://github.com/rui314/mold/issues/1134
2023-10-23 17:54:36 +09:00
Rui Ueyama 2d121b8d6d Inline larger relro segments 2023-10-23 16:33:10 +09:00
Rui Ueyama c86a59a511 Fill gaps in executable segments with trap or nop instructions 2023-10-23 12:26:56 +09:00
Rui Ueyama f7dea3a21b Revert "Do not create a PLT for an IFUNC unless necessary"
This reverts commit 651ae8a2a8 because
it broke CI.
2023-10-22 22:35:49 +09:00
Rui Ueyama 651ae8a2a8 Do not create a PLT for an IFUNC unless necessary 2023-10-22 20:31:36 +09:00
Rui Ueyama 5f7aca6276 Revert "Make container interruptible with Ctrl-C"
This reverts commit 5c4955763b because
it broke CI.
2023-10-22 15:53:50 +09:00
Rui Ueyama 39cdf61695 Create a lockfile in $XDG_RUNTIME_DIR instead of $HOME
https://github.com/rui314/mold/issues/117
2023-10-22 13:28:13 +09:00
Rui Ueyama 5c4955763b Make container interruptible with Ctrl-C 2023-10-22 13:04:56 +09:00
Rui Ueyama dae070283b Do not depend on the current path 2023-10-22 12:56:48 +09:00
Rui Ueyama 403655904b Merge two scripts into one 2023-10-21 23:30:12 +09:00
Rui Ueyama 44942b638b Do not copy mold and mold-wrapper.so to the top source directory 2023-10-21 20:49:43 +09:00
Rui Ueyama ceffd4679b Simplify 2023-10-21 17:50:36 +09:00
Rui Ueyama 6fa742be67 Improve data locality
It looks like this change makes the linker slightly faster.
2023-10-21 16:52:38 +09:00
Rui Ueyama 484e357971 Simplify 2023-10-21 13:13:56 +09:00
Rui Ueyama 53a5a37370 Refactor 2023-10-20 22:33:39 +09:00
Rui Ueyama 41579888b6 Add a timer prober 2023-10-20 20:25:07 +09:00
Rui Ueyama 1e2d84038e Simplify 2023-10-20 18:50:10 +09:00
Rui Ueyama 6c7700b051 Update the manual 2023-10-20 16:45:48 +09:00
Rui Ueyama 34c53777fb Bump mold version to 2.3.1 2023-10-20 13:15:31 +09:00
Rui Ueyama 7be1b66791 Fix range extension thunks
Fixes https://github.com/rui314/mold/issues/1132
2023-10-20 10:33:57 +09:00
Rui Ueyama 4bd80ec21c [LoongArch] Remove relocation overflow checks
These relocations may overflow with -mcmodel=extreme.
2023-10-19 20:44:23 +09:00
Rui Ueyama a9ab0ff452 [LoongArch] Fix -mcmodel=extreme
Based on MQ-mengqing's patch.

Fixes https://github.com/rui314/mold/issues/1131
2023-10-19 19:46:32 +09:00
Rui Ueyama 206bf65c50 Fix test
Fixes https://github.com/rui314/mold/issues/1130
2023-10-19 17:36:37 +09:00
Rui Ueyama 2b3e8eec05 Merge pull request #1129 from vihu/rg/artix 2023-10-19 15:08:51 +09:00
Rahul Garg 9eac818254 Add support for artix
Summary
----
This PR adds support for [Artix OS](https://artixlinux.org/).
2023-10-18 23:56:42 -06:00
Rui Ueyama 6fe0cadfa1 Enable building of RV64 distribution file 2023-10-19 14:12:54 +09:00
Rui Ueyama 1a2baee096 Fix test
`test_cflags` uses $CC to test if a given flag is supported, so
we should use $CC instead of $GCC for the rest of the file.

Fixes https://github.com/rui314/mold/issues/1128
2023-10-19 11:44:41 +09:00
Rui Ueyama 728b265cbd Fix -Wc++11-narrowing on 32-bit machines
Fixes https://github.com/rui314/mold/issues/1127
2023-10-19 11:33:54 +09:00
Rui Ueyama 9fa61b9298 Update third-party/rust-demangle
Updated to 4283d46e4064a7e1c54bc9918a07b066cb43fca3.

Fixed https://github.com/rui314/mold/issues/1127
2023-10-19 11:33:50 +09:00
Rui Ueyama 6ad942cb27 Bump mold version to 2.3.0 2023-10-18 19:24:17 +09:00
Rui Ueyama eed4496af2 Fix test
Older versions of GNU assembler don't know `.variant_pcs` directive.
2023-10-18 19:24:02 +09:00
Rui Ueyama 17c292c2b4 Fix CI
It looks like older versions of gdb falls into an infinite loop
if the gdb hash table is full.
2023-10-18 15:52:14 +09:00
Rui Ueyama ab1ab78f8a Fix gdb-index hash computation 2023-10-18 09:56:32 +09:00
Rui Ueyama 8506065fd2 Refactor 2023-10-17 20:19:07 +09:00
Rui Ueyama a291d0d448 Refactor 2023-10-17 18:41:10 +09:00
Rui Ueyama 690fefb97d Read .debug_gnu_{pubnames,pubtypes} correctly 2023-10-17 17:25:10 +09:00
Rui Ueyama c7c1779ad7 Fix CI 2023-10-17 17:04:53 +09:00
Rui Ueyama ec095e7513 Do not emit address areas for eliminated sections 2023-10-17 16:39:32 +09:00
Rui Ueyama 69a91e8aa0 --gdb-index: Fix address table 2023-10-17 15:53:55 +09:00
Rui Ueyama af46000645 Support DWARF64 for --gdb_index
Fixes https://github.com/rui314/mold/issues/1048
2023-10-17 15:19:35 +09:00
Rui Ueyama b1658c4702 Refactor 2023-10-17 15:19:35 +09:00
Rui Ueyama 9f85267b44 Optimize 2023-10-17 12:01:15 +09:00
Rui Ueyama f8d20cd3ce Fix CI 2023-10-17 10:40:21 +09:00
Rui Ueyama a396fa400f Re-implement --gdb-index
This change reduces the size of the .gdb_index section. It also fixes
an issue with handling of clang-generated object files.
2023-10-17 10:27:30 +09:00
Rui Ueyama d8a4f14fd0 Fix CI 2023-10-16 13:55:54 +09:00
Rui Ueyama c8b5fae2d0 Refactor 2023-10-16 13:15:00 +09:00
Rui Ueyama 0ce32d36d5 Allow <4GB input sections
Fixes https://github.com/rui314/mold/issues/1126
2023-10-16 12:40:52 +09:00
Rui Ueyama 01cd5d1a32 Revert "Do not write to an atomic variable too often"
This reverts commit 39a25e2394.
2023-10-13 15:08:27 +09:00
Rui Ueyama 39a25e2394 Do not write to an atomic variable too often 2023-10-13 14:28:56 +09:00
Rui Ueyama bfdd75ed38 Refactor 2023-10-13 14:24:35 +09:00
Rui Ueyama 5411f4216e Fix CI 2023-10-13 14:18:30 +09:00
Rui Ueyama 3cf00e30d5 Refactor 2023-10-13 13:14:01 +09:00
Rui Ueyama 0f714710f0 Fix relocations for POWER10
With this change, all tests now pass on an actual POWER10 machine
(gcc120.fsffrance.org).
2023-10-13 10:11:52 +09:00
Rui Ueyama 83ec409426 Support R_PPC64_TPREL34 2023-10-13 08:24:34 +09:00
Rui Ueyama e6ae83fbf9 Fix POWER10 issues 2023-10-12 21:04:27 +09:00
Rui Ueyama 00702773f4 Format 2023-10-12 12:04:08 +09:00
Rui Ueyama 1739cfbfb4 Refactor 2023-10-10 12:01:08 +09:00
Rui Ueyama ff689a1253 Allow nested response files
Fixes https://github.com/rui314/mold/issues/1124
2023-10-09 19:12:14 +09:00
Rui Ueyama ae427d133e Refactor 2023-10-07 16:50:00 +09:00
Rui Ueyama d92af2456d Refactor 2023-10-07 16:39:46 +09:00
Rui Ueyama b3e1092879 Refactor 2023-10-07 14:01:24 +09:00
Rui Ueyama 46ef71eb75 Fix CI 2023-10-05 20:00:27 +09:00
Rui Ueyama 871ef8cf14 Refactor 2023-10-05 19:06:33 +09:00
Rui Ueyama c1b1caa854 Fix address-taken bit 2023-10-05 14:10:38 +09:00
Rui Ueyama dcab76697e Refactor 2023-10-05 11:47:00 +09:00
Rui Ueyama cf11efb147 Revert "Fix TLSDESC on musl-libc ARM32 systems"
This reverts commit 967006479f because
it made the linker to crash. TLSDESC doesn't seem to work even with
GNU ld on ARM32 musl systems, so I'll disable the test.

Fixes https://github.com/rui314/mold/issues/1116
2023-10-05 11:45:15 +09:00
Rui Ueyama a688b73f8e Merge pull request #1123 from ishitatsuyuki/main-mono-reland
[ELF] Reland "Move main() and redo_main() into a separate compile unit."
2023-10-04 19:48:55 +09:00
Tatsuyuki Ishi 9bb50ae7a5 [ELF] Move main() and redo_main() into a separate compile unit.
Despite the extern template items Clang 14 seems to insist on instantiating
elf_main(), with the hilarious consequence of the function being duplicated
quadratically to the number of archs.

Move this to a different CU so that the compiler cannot possibly
instantiate it more than once. This significantly speeds up compilation
related to main.cc.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2023-10-04 19:09:26 +09:00
Rui Ueyama ead6235470 Emit an endbr64 only for a canonical PLT 2023-10-04 17:17:07 +09:00
Rui Ueyama 967006479f Fix TLSDESC on musl-libc ARM32 systems
Fixes https://github.com/rui314/mold/issues/1116
2023-10-04 14:54:55 +09:00
Rui Ueyama f843daee9b Revert "[ELF] Move main() and redo_main() into a separate compile unit."
This reverts commit 1d3706285e.

Fixes https://github.com/rui314/mold/issues/1122
2023-10-04 13:07:06 +09:00
Rui Ueyama c7129916ee Merge pull request #1121 from ishitatsuyuki/main-mono
[ELF] Move main() and redo_main() into a separate compile unit.
2023-10-03 19:01:43 +09:00
Rui Ueyama e234ce25b6 Fix CI 2023-10-03 18:58:01 +09:00
Rui Ueyama 02e1b9de10 Remove a useless variable 2023-10-03 18:53:35 +09:00
Rui Ueyama effde5ffa9 Merge pull request #1119 from sicherha/improvement_strict_compiler_warnings
Enable strict compiler warnings by default
2023-10-03 18:50:52 +09:00
Tatsuyuki Ishi 1d3706285e [ELF] Move main() and redo_main() into a separate compile unit.
Despite the extern template items Clang 14 seems to insist on instantiating
elf_main(), with the hilarious consequence of the function being duplicated
quadratically to the number of archs.

Move this to a different CU so that the compiler cannot possibly
instantiate it more than once. This significantly speeds up compilation
related to main.cc.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2023-10-03 17:48:57 +09:00
Rui Ueyama 085a1148fd Report a duplicate symbol error for archives with --whole-archive
Fixes https://github.com/rui314/mold/issues/1120
2023-10-03 17:36:45 +09:00
Christoph Erhardt 5cf3e53ab9 Enable strict compiler warnings
Compiler warnings have the potential to uncover real bugs before they
make it into a commit. For example, the accidental fallthrough
introduced by commit 713d81947a and fixed
by commit 49f38828d1 could have been
detected by GCC.

Remove `-Wunused-variable` since it is implied by `-Wall`.
Add `-Wno-unused-parameter` to suppress warning spam regarding unused
parameters.

Signed-off-by: Christoph Erhardt <[email protected]>
2023-10-03 08:50:44 +02:00
Christoph Erhardt a5aa387cb4 Add cast to ternary-operator expression
This fixes the following compiler warning:
> enumerated and non-enumerated type in conditional expression [-Wextra]

Signed-off-by: Christoph Erhardt <[email protected]>
2023-10-03 08:50:44 +02:00
Christoph Erhardt f99cb33c2d Remove unused parameters
Signed-off-by: Christoph Erhardt <[email protected]>
2023-10-03 08:50:44 +02:00
Rui Ueyama e55703405b Do not call compute_address_significance twice 2023-10-03 14:30:45 +09:00
Rui Ueyama 4c71174d5d Fix CI 2023-10-02 20:03:24 +09:00
Rui Ueyama 2ea08ac4b3 Revert "Enable to download build artifacts"
This reverts commit 82ace062db.
2023-10-02 19:58:37 +09:00
Rui Ueyama 82ace062db Enable to download build artifacts 2023-10-02 19:11:55 +09:00
Rui Ueyama 17f0d85efb Add an experimental -z rewrite-endbr option
endbr64 is a relatively new x86 instruction to mark a location to which an
indirect jump instruction can transfer control. If the control-flow
integrity is turned on (i.e., endbr64 is effective), an indirect jump can
only target an endbr64 or raise a runtime exception. This mechanism makes
some types of control hijacking attacks, such as ROP or JOP, very hard
because an attacker can no longer jump to an arbitrary location.

If `-fcf-protection` is given, GCC emits an endbr64 at the beginning of
each global function conservatively because the address of that function
might be used by other translation units.

In reality, most function addresses aren't taken, so the conservative
assumption ends up emitting lots of unnecessary endbr64 instructions.
This not only bloats the code but also weakens security because an
attacker would have more locations to attack.

The new linker option, `-z rewrite-endbr`, is designed to mitigate this
situation. The linker is in a position to conduct whole-program analysis
on the input files and determine functions whose addresses have never been
taken. If `-z rewrite-endbr` is given, mold performs that analysis and
rewrites the leading endbr64 with a nop if the function's address wasn't
taken.

For evaluation, I built the mold executable itself both with and without
this option. Before using the `-z rewrite-endbr` option, the mold
executable contained 25,994 endbr64 instructions. With the option, the
number becomes 18,035, a 30% reduction.

The new option is exprerimental; we may remove it in a future versions of
the mold linker.
2023-10-02 17:53:03 +09:00
Rui Ueyama a994d71fa1 Use relocations to identify address-taken functions 2023-10-02 17:05:38 +09:00
Rui Ueyama 0eea8f4015 Refactor 2023-09-30 12:04:20 +09:00
Rui Ueyama 2e3b56ee3f Emit DT_AARCH64_VARIANT_PCS if required
Fixes https://github.com/rui314/mold/issues/1115
2023-09-28 20:57:54 +09:00
Rui Ueyama b8bcb8a2a3 Refactor 2023-09-27 18:17:24 +09:00
Rui Ueyama ac3ee91cbd [RISC-V] Support GP-relative relocations
These relocations are use for embedded programming and are probably
not useful for mold, but we want them for the sake of completeness.
2023-09-26 11:30:02 +09:00
Rui Ueyama 18df821625 Install a required package 2023-09-24 17:26:11 +09:00
Rui Ueyama 79b3fc4b6a Bump mold version to 2.2.0 2023-09-24 12:28:19 +09:00
Rui Ueyama 9e09e74db3 Refactor 2023-09-20 16:58:37 +09:00
Rui Ueyama 9ee10ba4bd Fix test
Fixes https://github.com/rui314/mold/issues/1107
2023-09-18 15:03:41 +09:00
Rui Ueyama fe7c8c26b7 Fix for big-endian hosts 2023-09-17 15:28:35 +09:00
Rui Ueyama 23576b6e48 Refactor 2023-09-17 11:16:39 +09:00
Rui Ueyama cfa9e404d1 Keep the entry symbol when doing LTO
Fixes https://github.com/rui314/mold/issues/1105
2023-09-16 14:43:04 +09:00
Rui Ueyama 641360b0aa Update comments 2023-09-16 14:28:39 +09:00
Rui Ueyama 4ccc9eb89a Fix RISC-V's shrink_section()
r_delta is not available when we are shrinking sections.

Address the post review comment
https://github.com/rui314/mold/commit/742cdeec666ea015c26af4f30d01f2fb08fcb7b7#r127431639
2023-09-16 14:01:57 +09:00
Rui Ueyama a801dde186 Use ld for RV64 and lw for RV32 2023-09-14 14:00:55 +09:00
Rui Ueyama e2d53f26e2 Refactor 2023-09-14 14:00:54 +09:00
Rui Ueyama 742cdeec66 Refactor 2023-09-14 14:00:53 +09:00
Rui Ueyama c2116aa7ca Merge pull request #1041 from ishitatsuyuki/rv-tlsdesc
RISC-V TLSDESC support
2023-09-14 12:54:11 +09:00
Tatsuyuki Ishi fed950837a [ELF][RISCV] Add TLSDESC relaxation.
Signed-off-by: Tatsuyuki Ishi <[email protected]>
2023-09-14 02:18:15 +09:00
Tatsuyuki Ishi 508890d33d [ELF][RISCV] Fix finding paired relocations with zero distance.
For example, when the leader's instruction is removed and a follower is right
next to it, the follower's relocation can point to the follower's address
itself. In this case the leader's relocation may lie before or after the
follower, so just search for both.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2023-09-13 13:38:46 +09:00
Tatsuyuki Ishi 141556db44 [ELF] Support RISC-V TLSDESC relocations.
Signed-off-by: Tatsuyuki Ishi <[email protected]>
2023-09-13 13:38:42 +09:00
Tatsuyuki Ishi 8589403fe0 [ELF][RISCV] Move the list of "leader" paired reloc into a helper.
Signed-off-by: Tatsuyuki Ishi <[email protected]>
2023-09-13 13:37:15 +09:00
Tatsuyuki Ishi cd2224742f [ELF] Support RISC-V TLSDESC GOT generation.
Signed-off-by: Tatsuyuki Ishi <[email protected]>
2023-09-13 13:36:55 +09:00
Tatsuyuki Ishi 0b1d11ed01 [ELF] Add RISC-V TLSDESC relocation constants.
Signed-off-by: Tatsuyuki Ishi <[email protected]>
2023-09-13 13:36:16 +09:00
Rui Ueyama 22443b1490 Reduce the number of atomic memory operations 2023-09-08 18:48:25 +09:00
Rui Ueyama a3a53e9a0c Refactor 2023-09-08 17:44:24 +09:00
Rui Ueyama dd3d045396 Discard local symbols in discarded sections 2023-09-06 17:16:22 +09:00
Rui Ueyama 673d790372 Attempt to fix CI 2023-09-06 14:48:10 +09:00
Rui Ueyama 6cac0aba6a Fix CI 2023-09-06 13:59:48 +09:00
Rui Ueyama 1a13c5076e Avoid cache-line false sharing
This change improves the performance of our concurrent hash map on
a multicore machine.
2023-09-06 13:26:49 +09:00
Rui Ueyama c504911bf6 Add a missing #include 2023-09-05 15:39:44 +09:00
Rui Ueyama db5fa8a8cd Remove incomplete MIPS support
I made a fair amount of effort to try to support MIPS, but it turned out
that it is much harder than expected. I punted it instead of making
further efforts.

The problem is the MIPS ABI is hostile to the linker in the modern
environment. MIPS object files are still compiled for the small code
model in which GOT entries and data in the small data area are expected
to be accessible with a single machine instruction with a 16-bit
displacement. In other words, .got/.sdata/.sbss are expected to be
smaller than 64 KiB. This might have been a reasonable assumption in the
90s, but it's not suitable for modern applications that can be 1000x
larger than the binaries in the 90s.

MIPS requires the linker to implement tons of workarounds for its legacy
ABI assumptions. Our incomplete MIPS support can build binaries that
pass all our unit tests. However, it needed more effort to support
real-world programs that are larger than our test cases.

At this point, I don't think it is productive to implement workarounds
for the old ABI that is stuck in the 90s. It is honestly annoying to
think about workarounds for the code that is intentionally compiled to
be hostile to the linker. The situation is unfortunate, but if the
Open Source community is still serious about MIPS, they should improve
the ABI and the compiler instead of asking us to implement the legacy
ABI.

Closes https://github.com/rui314/mold/issues/1040
2023-09-04 13:12:03 +09:00
Rui Ueyama c03400303f Fix --relocatable
Fixes https://github.com/rui314/mold/issues/1096
2023-09-03 20:15:32 +09:00
Rui Ueyama 7f91a134ef Refactor 2023-09-03 12:31:22 +09:00
Rui Ueyama d4891d5ff1 Improve PC-relative relocation relaxation
Absolute symbols are rare, but their PC-relative addresses are known
at link-time if we are creating a position-dependent executable.
2023-09-03 10:50:52 +09:00
Rui Ueyama bdc2336265 Refactor 2023-09-03 10:50:52 +09:00
Rui Ueyama 2a0f65084e Refactor 2023-09-01 17:24:32 +09:00
Rui Ueyama db146cfc37 Fix i386 TLSDESC 2023-09-01 15:30:38 +09:00
Rui Ueyama 49f38828d1 Add a missing break
This error resulted in creating an unnecessary GOT entry.
2023-09-01 13:58:09 +09:00
Rui Ueyama 0c972cf59d Fix a minor bug in R_X86_64_GOT32 handling 2023-09-01 13:54:39 +09:00
Rui Ueyama f057fdadba Fix TLSGD/TLSDDESC to Initial Exec relaxation 2023-09-01 12:39:10 +09:00
Rui Ueyama 3fb2571255 Refactor 2023-09-01 11:13:01 +09:00
Rui Ueyama 619f741ca9 Fix linker script "local" and "global" label handling
Fixes https://github.com/rui314/mold/issues/1098
2023-09-01 10:10:51 +09:00
Rui Ueyama 713d81947a Refactor 2023-09-01 09:57:20 +09:00
Rui Ueyama f76d3e0d0c Fix a unit test
Recent versions of GCC report a compile error if an extension
name is not recognizable.

Fixes https://github.com/rui314/mold/issues/1097
2023-08-31 18:16:32 +09:00
Rui Ueyama 488cd5d933 Add comments 2023-08-29 17:23:21 +09:00
Rui Ueyama 55bcb72be7 Fix a minor relaxation error 2023-08-29 16:12:57 +09:00
Rui Ueyama 7f8872b2f1 Do not update auto-generated files' timestamp on cmake
Fixes https://github.com/rui314/mold/issues/1094
2023-08-28 12:36:44 +09:00
Rui Ueyama 139807080b Refactor 2023-08-27 13:35:15 +09:00
Rui Ueyama 86b37b112f Add comments 2023-08-27 11:51:43 +09:00
Rui Ueyama d56f528c27 Relax TLSDESC to Initial Exec 2023-08-26 20:47:02 +09:00
Rui Ueyama a1b81b249f Add a rule for Asahi Linux 2023-08-26 14:37:48 +09:00
Rui Ueyama fa0de2f03b Make the PLT header a little bit compact 2023-08-25 11:26:43 +09:00
Rui Ueyama a357445654 Refactor 2023-08-24 19:08:10 +09:00
Rui Ueyama 8f5c49c655 Play the code-golf with our s390x PLT header 2023-08-23 22:41:41 +09:00
Rui Ueyama 03b5ce7c6f Reduce the size of PLT entry on s390 2023-08-23 21:45:58 +09:00
Rui Ueyama 63df2a3c8b Add a script to install cross toolchains 2023-08-23 19:45:28 +09:00
Rui Ueyama 9a09ead865 Reduce the size of range extension thunk for ARM 2023-08-23 16:40:48 +09:00
Rui Ueyama c2380ff7bc Do not run the compiler in sudo 2023-08-23 14:38:50 +09:00
Rui Ueyama c49a8b5b07 Merge pull request #1092 from david-perez/main
Update `README.md` installation instructions for CMake 3.14
2023-08-23 14:37:07 +09:00
Rui Ueyama 51fec5f1ff Avoid reading data from .plt 2023-08-23 14:02:03 +09:00
Rui Ueyama ac20d8729b Avoid reading data from .plt
With `--execute-only`, the text segment may not be readable.

Fixes https://github.com/rui314/mold/issues/1087
2023-08-23 12:53:27 +09:00
Rui Ueyama 7e9fedd203 Align range extension thunk entry points to 16 byte boundaries
Quote from Arm Cortex-A75 Software Optimization Guide
(PJDOC-466751330-205) p.59:

  Consider aligning subroutine entry points and branch targets to
  16-byte boundaries, within the bounds of the code-density requirements
  of the program. This ensures that the subsequent fetch can maximize
  bandwidth following the taken branch by bringing in all useful
  instructions.
2023-08-22 16:20:12 +09:00
Rui Ueyama 576cd86ecb Refactor 2023-08-22 15:47:34 +09:00
david-perez bb1db6cf17 Update README.md installation instructions for CMake 3.14
`CMakeLists.txt` declares a minimum CMake dependency on 3.14.

```
cmake_minimum_required(VERSION 3.13)
```

But the `--install` switch is only available since CMake 3.15, see
<https://stackoverflow.com/a/56457739>.

This commit updates the installation instructions in `README.md` so that
they work with CMake 3.14.
2023-08-21 18:52:35 +02:00
Rui Ueyama 3529a2fcc6 Refactor 2023-08-21 12:30:18 +09:00
Rui Ueyama e842bee049 Fix R_RISCV_HI20 relaxation 2023-08-20 17:30:44 +09:00
Rui Ueyama 3c8684c528 Fix R_RISCV_HI20 2023-08-20 17:03:38 +09:00
Rui Ueyama 108815dbe1 Implement LUI -> C.LUI relaxation 2023-08-20 14:29:02 +09:00
Rui Ueyama d75386b545 Bump the required CMake version to 3.14
Because CREATE_LINK requires CMake 3.14.

Fixes https://github.com/rui314/mold/issues/1091
2023-08-20 08:33:41 +09:00
Rui Ueyama bb1934bb9f Refactor 2023-08-19 17:34:38 +09:00
Rui Ueyama f01817f39e Statically link more libraies if -DMOLD_MOSTLY_STATIC=1 2023-08-19 14:08:26 +09:00
Rui Ueyama fad4c1b56c Disable tests in the bundled zlib 2023-08-19 13:55:03 +09:00
Rui Ueyama 3c8868280d Remove unnecessary build dependencies 2023-08-19 13:38:11 +09:00
Rui Ueyama a665ca766d Upgrade bundled zlib to v1.3 2023-08-19 13:30:22 +09:00
Rui Ueyama 0f85278c73 Upgrade bundled zstd to v1.5.5 2023-08-19 13:29:24 +09:00
Rui Ueyama 085727234a Refactor 2023-08-19 13:21:32 +09:00
Rui Ueyama 83fe073e97 Refactor 2023-08-18 17:14:04 +09:00
Rui Ueyama 8a25c1bfc1 Refactor 2023-08-17 18:50:15 +09:00
Rui Ueyama a94cd68ce1 Refactor 2023-08-17 17:45:48 +09:00
Rui Ueyama 68ac03d19c Refactor 2023-08-17 14:48:57 +09:00
Rui Ueyama b79bc35fd9 Fix CI 2023-08-17 12:40:02 +09:00
Rui Ueyama 90839d747f Refactor 2023-08-17 12:18:55 +09:00
Rui Ueyama 1b1ab744e5 Copy RELRO symbols to .copyrel.rel.ro instead of to .copyrel
So that readonly data wouldn't become writable by copy relocations.
2023-08-17 11:55:05 +09:00
Rui Ueyama f02db0fa0f Do not link libraries that are not directly used by the output file
If an as-needed DSO is referenced only by other DSOs and not by
the output file we are creating, we won't mark it as "needed".

Fixes https://github.com/rui314/mold/issues/1036
2023-08-17 11:03:12 +09:00
Rui Ueyama fbcee0b716 Refactor 2023-08-17 10:16:19 +09:00
Rui Ueyama c105cfd35a Fix CI 2023-08-16 23:13:07 +09:00
Rui Ueyama bb402480a5 Refactor 2023-08-16 22:57:16 +09:00
Rui Ueyama c983321fed Upgrade the bundled OneTBB to v2021.10.0 2023-08-16 21:06:41 +09:00
Rui Ueyama 43ebc96bfe Refactor 2023-08-16 20:46:25 +09:00
Rui Ueyama 8ae1ad57a4 Merge pull request #1090 from Romain-Geissler-1A/remove-openssl-mentions
Removing remaining openssl mentions following the move to Blake3.
2023-08-16 20:45:00 +09:00
Romain Geissler bd39bfdc5b Removing remaining openssl mentions following the move to Blake3. 2023-08-16 10:19:38 +00:00
Rui Ueyama a11566795d Update comments 2023-08-16 16:36:26 +09:00
Rui Ueyama 3676c596df Remove CI badge as well
We can see the CI status on the same GitHub homepage.
2023-08-16 14:27:21 +09:00
Rui Ueyama 0947836a44 Refactor 2023-08-16 14:27:09 +09:00
Rui Ueyama 2383e42a5c Merge pull request #1089 from marxin/drop-obs-badge
drop openSUSE OBS badge as the package is unmaintained
2023-08-16 14:26:58 +09:00
Martin Liska 049dbb73fe drop openSUSE OBS badge as the package is unmaintained 2023-08-16 07:19:27 +02:00
Rui Ueyama 95894ef2e2 Attempt to fix Windows CI 2023-08-16 13:36:30 +09:00
Rui Ueyama 7f7a744ebb Use BLAKE3 instead of SHA256 for cryptographic hash computation
Closes https://github.com/rui314/mold/issues/1088
2023-08-16 12:18:10 +09:00
Rui Ueyama 3833a4a457 Add BLAKE3 to third-party/
Since BLAKE3 is available under CC0, we don't need to add its license
terms (or the lack thereof) to our LICENSE.third-party file.
2023-08-16 12:13:53 +09:00
Rui Ueyama a0516a371f Refactor 2023-08-16 10:27:21 +09:00
Rui Ueyama 29491df6f2 Refactor 2023-08-15 18:19:39 +09:00
Rui Ueyama 599ed1dde0 Refactor 2023-08-15 16:56:59 +09:00
Rui Ueyama 143111ae5a Fix CI 2023-08-15 16:45:09 +09:00
Rui Ueyama d753ea5bdb Fix CI 2023-08-15 16:10:35 +09:00
Rui Ueyama b205eb7fa6 Refactor 2023-08-15 15:58:09 +09:00
Rui Ueyama d8baee9605 Refactor 2023-08-15 15:33:28 +09:00
Rui Ueyama 6dacc5192a Refactor 2023-08-15 15:08:34 +09:00
Rui Ueyama 4f5f88258c Fix TLSDESC relocation
Although we do not support TLSDESC on any target on which
ctx.tls_begin != ctx.dtp_addr, my understanding is that the origin
of the TLSDESC base relocation is tls_begin.
2023-08-14 19:55:39 +09:00
Rui Ueyama f5abedad01 Fix _TLS_MODULE_BASE_ address
Since the module base address obtained with `_TLS_MODULE_BASE_` will
be used with foo@dtpoff relocations, it should be the same as the DTP
address.
2023-08-14 19:39:50 +09:00
Rui Ueyama 02aee3b43e Do not put local symbols into .dynsym for TLSDESC
Placing local symbols into .dynsym is not technically incorrect, but
doing so is just a waste of space.
2023-08-14 19:06:35 +09:00
Rui Ueyama c1406860fa Fix -Wunused-variable
Fixes https://github.com/rui314/mold/issues/1086
2023-08-14 11:39:44 +09:00
Rui Ueyama 53759731cf Fix relocation overflow check 2023-08-14 08:39:13 +09:00
Rui Ueyama b018baec8a Refactor 2023-08-13 19:11:38 +09:00
Rui Ueyama 28ddea5371 Revert "Do not create copy relocations for PIE"
This reverts commit 82989a8b7c because
it broke our CI.
2023-08-13 17:55:44 +09:00
Rui Ueyama 82989a8b7c Do not create copy relocations for PIE
Object files have to be compiled with `-fPIE` or `-fPIC` for a
position-independent executable, and such object files shouldn't
contain relocations that directly refers to data objects without
GOT.
2023-08-13 17:02:45 +09:00
Rui Ueyama d78b748696 Bump mold version to 2.1.0 2023-08-13 13:35:43 +09:00
Rui Ueyama 77968a7fc1 Make --pack-dyn-relocs=relr as a synonym for -z pack-relative-relocs 2023-08-13 10:47:50 +09:00
Rui Ueyama 00a68c5fcf Format 2023-08-12 17:47:51 +09:00
Rui Ueyama 6f9752a1bf Remove a useless timer 2023-08-12 16:58:51 +09:00
Rui Ueyama 6a32828dd8 Improve error messages 2023-08-12 14:36:42 +09:00
Rui Ueyama b5e0d7a7c9 Refactor 2023-08-12 13:41:46 +09:00
Rui Ueyama 3b0b28ff97 Update comments 2023-08-12 13:19:11 +09:00
Rui Ueyama 6ce3730083 Use the same error message for s390x 2023-08-11 17:07:10 +09:00
Rui Ueyama d3e7d88753 Remove error checks
We do not have these error checks for other targets.
We want to be consistent across targets.
2023-08-11 16:55:44 +09:00
Rui Ueyama 9dee80eb4f Simplify 2023-08-11 16:55:16 +09:00
Rui Ueyama eb99c87f75 Use PCALAU12I instead of PCADDU12I in PLT
So that the PLT code is more in line with compiler-generated code.
2023-08-11 16:32:55 +09:00
Rui Ueyama e45f2a8efb Fix CMakeLists.txt 2023-08-11 15:07:09 +09:00
Rui Ueyama 86ab3890d6 Upgrade RV32 toolchain in CI 2023-08-11 15:05:51 +09:00
Rui Ueyama 3b5ccb9342 Implement range extension thunks for LoongArch 2023-08-11 10:54:19 +09:00
Rui Ueyama 9441170d39 Refactor 2023-08-11 01:30:43 +09:00
Rui Ueyama ffb83247f4 Fix CI 2023-08-10 17:59:40 +09:00
Rui Ueyama 13f42071b9 Update comments 2023-08-10 17:49:47 +09:00
Rui Ueyama 032931fa3b Enable LoongArch tests on CI 2023-08-10 16:41:08 +09:00
Rui Ueyama 472b325349 Improve Loongarch support 2023-08-10 15:42:54 +09:00
Rui Ueyama b852d925c2 Revert "Fix TLSLD"
This reverts commit 56cdba50cf.
2023-08-10 13:48:12 +09:00
Rui Ueyama 56cdba50cf Fix TLSLD 2023-08-10 13:25:36 +09:00
Rui Ueyama cfec68e054 Refactor 2023-08-10 11:27:11 +09:00
Rui Ueyama d9f850b032 Fix instruction bitmask 2023-08-10 10:36:06 +09:00
Rui Ueyama 1f012337c0 Refactor 2023-08-10 10:09:49 +09:00
Rui Ueyama 90cf642ca7 Fix high 32 bits computation
I believe the correct expression is this one.
2023-08-10 09:56:06 +09:00
Rui Ueyama d12c48ce63 Refactor 2023-08-10 09:56:06 +09:00
Rui Ueyama 67b9d6cb8d Remove unnecessary function 2023-08-10 08:45:24 +09:00
Rui Ueyama 2e12e635a0 Refactor 2023-08-10 08:30:07 +09:00
Rui Ueyama 1b5631990c Simplify 2023-08-10 08:26:24 +09:00
Rui Ueyama acf846acc0 Assume little endian on LooongArch 2023-08-09 21:30:55 +09:00
Rui Ueyama e1347d8f7d Refactor 2023-08-09 21:29:53 +09:00
Rui Ueyama 6d809b56e6 Refactor 2023-08-09 21:13:00 +09:00
Rui Ueyama 4528507155 Handle obsolete relocations as unknown ones
A "unknown relocation" message should be enough to show that the
relocation is not supported by mold.
2023-08-09 20:57:45 +09:00
Rui Ueyama da07871416 Move LoongArch tests behind MOLD_ENABLE_QEMU_TESTS_LOONGARCH 2023-08-09 20:54:29 +09:00
Rui Ueyama 354d0254ee Update comments 2023-08-09 20:53:39 +09:00
Rui Ueyama b711bf2009 Merge pull request #1081 from MQ-mengqing/main
Add loongarch basic support
2023-08-09 20:53:22 +09:00
Rui Ueyama 94e2a71866 Refactor 2023-08-09 17:16:11 +09:00
Rui Ueyama f467ad1add Create a symbol version dependency to GLIBC_ABI_DT_RELR
Fixes https://github.com/rui314/mold/issues/653
2023-08-09 12:02:06 +09:00
Rui Ueyama f631477a68 Set e_flags and .MIPS.abiflags 2023-08-08 19:20:59 +09:00
Rui Ueyama 56479e724f Improve an error message 2023-08-08 18:14:26 +09:00
Rui Ueyama d752bac24a Do not handle --strip-debug as a synonym for --strip-all
Fixes https://github.com/rui314/mold/issues/1080
2023-08-08 17:46:45 +09:00
Rui Ueyama a50258fdf8 Refactor 2023-08-08 11:37:36 +09:00
Rui Ueyama 710dfd01d6 Fix ODR violation
Fixes https://github.com/rui314/mold/issues/1082
2023-08-07 19:15:31 +09:00
Jinyang He 03b1a1cc68 Add loongarch basic support
link: https://reviews.llvm.org/D138135
link: https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html
2023-08-07 10:17:29 +08:00
Rui Ueyama 1c73fd57fc Fix CI 2023-08-06 17:32:36 +09:00
Rui Ueyama 24078a4395 Merge .mips_got sections 2023-08-06 15:09:25 +09:00
Rui Ueyama 270cbf42df Attempt to fix CI 2023-08-06 15:01:42 +09:00
Rui Ueyama ea75dae8ec Refactor 2023-08-06 14:01:11 +09:00
Rui Ueyama 6d290babe2 Refactor 2023-08-06 13:48:29 +09:00
Rui Ueyama 428faa75b2 Create multiple GOT sections for MIPS 2023-08-06 13:36:14 +09:00
Rui Ueyama 829c9a980e Refactor 2023-08-06 13:29:34 +09:00
Rui Ueyama 76af9907fd Fix CI 2023-08-05 18:24:49 +09:00
Rui Ueyama 9893bb331f Update comments 2023-08-05 18:08:34 +09:00
Rui Ueyama 6108e60936 Attempt to fix CI 2023-08-05 17:27:06 +09:00
Rui Ueyama 9e2e376f5a Add MIPS arch string to the -V message 2023-08-05 15:31:04 +09:00
Rui Ueyama 2db8b3fa48 Enable MIPS tests on CI 2023-08-05 15:28:03 +09:00
Rui Ueyama e2c6f0c171 Refactor 2023-08-05 14:46:21 +09:00
Rui Ueyama eba7cdade2 Improve MIPS support
All tests now pass for MIPS64LE and MIPS64BE.
2023-08-05 13:07:37 +09:00
Rui Ueyama ca88e45bf3 Disable tests for MIPS 2023-08-05 09:00:57 +09:00
Rui Ueyama 19776686ec Enable MIPS tests if -DMOLD_ENABLE_QEMU_TESTS_MIPS64=ON
m68k tests are disabled by default because they are broken with
recent updates to Ubuntu 22.04.
2023-08-05 08:42:40 +09:00
Rui Ueyama e0a150a22c Refactor 2023-08-04 19:36:18 +09:00
Rui Ueyama 0df6063d8a Improve MIPS support 2023-08-04 18:48:52 +09:00
Rui Ueyama 5199414933 Refactor 2023-08-03 17:03:52 +09:00
Rui Ueyama 85f1dec81d Improve MIPS support 2023-08-03 16:30:48 +09:00
Rui Ueyama 97c937a56d Refactor 2023-08-02 20:21:11 +09:00
Rui Ueyama f1113f7c76 Refactor 2023-08-02 10:24:26 +09:00
Rui Ueyama 0ced83597f Refactor 2023-08-01 16:27:44 +09:00
Rui Ueyama 1f5fbb808b Do not create dynamic relocations for R_AARCH64_MOVW_UABS_G3 2023-08-01 16:09:40 +09:00
Rui Ueyama 5fb6091fb7 Handle R_RISCV_PCREL_HI20 as a PLT-generating reloc 2023-08-01 15:44:27 +09:00
Rui Ueyama e764557007 Handle R_AARCH64_MOVW_UABS_G3 as a PLT-generating reloc
ARM64's crt1.o may refer to `main` with the following four instructions
instead of with the usual `R_AARCH64_ABS64` relocation:

  18:   d2e00000        movz    x0, #0x0, lsl #48
                        18: R_AARCH64_MOVW_UABS_G3      main
  1c:   f2c00000        movk    x0, #0x0, lsl #32
                        1c: R_AARCH64_MOVW_UABS_G2_NC   main
  20:   f2a00000        movk    x0, #0x0, lsl #16
                        20: R_AARCH64_MOVW_UABS_G1_NC   main
  24:   f2800000        movk    x0, #0x0
                        24: R_AARCH64_MOVW_UABS_G0_NC   main
  28:   d2e00003        movz    x3, #0x0, lsl #48

So we need to create a PLT if a symbol is referred to by this way.

Fixes https://github.com/rui314/mold/issues/1074
2023-08-01 15:02:30 +09:00
Rui Ueyama 961cc10e0d Refactor 2023-08-01 11:04:03 +09:00
Rui Ueyama 49fc7da32e Refactor 2023-08-01 00:39:25 +09:00
Rui Ueyama dd56734fda Fix symbol table for very large section indices 2023-07-31 19:38:04 +09:00
Rui Ueyama 2015347b0c Report an error for incompatible relocation types 2023-07-31 15:44:29 +09:00
Rui Ueyama 4daa9aad36 Do not write special symbol values to .symtab_shndx 2023-07-31 15:10:30 +09:00
Rui Ueyama 084ca55a36 Support -z nosectionheader 2023-07-31 13:50:50 +09:00
Rui Ueyama e06d886252 Report an error if a non-PIC object file is given for an PIC output 2023-07-31 12:44:27 +09:00
Rui Ueyama 9fe3d750cc Fix test
Fixes https://github.com/rui314/mold/issues/1073
2023-07-31 09:26:00 +09:00
Rui Ueyama 13bb00bfa2 Refactor 2023-07-31 09:05:19 +09:00
Rui Ueyama 79a72011b7 Refactor 2023-07-30 23:47:42 +09:00
Rui Ueyama f2b278ce10 Attempt to fix a test for Alt Linux
Fixes https://github.com/rui314/mold/issues/1073
2023-07-30 22:01:31 +09:00
Rui Ueyama ec10452b67 Run tests on ppc64le machines 2023-07-30 13:12:44 +09:00
Rui Ueyama ba3fd65bcc Refactor
Thanks to small string optimization, storing a short string to std::string
is usually more efficient than referring it from std::string_view.
2023-07-30 12:03:58 +09:00
Rui Ueyama f816c45b88 Extend comments 2023-07-30 11:55:06 +09:00
Rui Ueyama ca14cdf9b6 Do not create a PT_RISCV_ATTRIBUTES segment if .riscv.attributes is missing 2023-07-30 11:36:35 +09:00
Rui Ueyama 6d667fad45 Fix CI 2023-07-30 11:25:18 +09:00
Rui Ueyama aa644914fe Merge .riscv.attributes input sections 2023-07-30 00:56:47 +09:00
Rui Ueyama 1cbe4d44ae Fix style 2023-07-29 21:13:50 +09:00
Rui Ueyama 91805d1e26 Add Emerge Tools as our sponsor 2023-07-29 21:07:44 +09:00
Rui Ueyama 9212f2ebd7 Refactor 2023-07-29 12:08:24 +09:00
Rui Ueyama 784fd27e9e Refactor 2023-07-28 17:33:46 +09:00
Rui Ueyama b78f237a68 Fix -Wunused-variable
Fixes https://github.com/rui314/mold/issues/1063
2023-07-28 16:55:18 +09:00
Rui Ueyama 1582b720d5 Weak undefs should not keep DSOs alive
Fixes https://github.com/rui314/mold/issues/1067
2023-07-28 15:12:52 +09:00
Rui Ueyama 710127977e Make --repro output readable by busybox's tar command 2023-07-28 15:12:45 +09:00
Rui Ueyama 8e07496e08 Refactor 2023-07-28 12:55:31 +09:00
Rui Ueyama 163f5db0d1 Simplify 2023-07-28 10:58:28 +09:00
Rui Ueyama be2e1b17cd Skip test if grep is not a "real" grep 2023-07-27 21:48:53 +09:00
Rui Ueyama 5f5e73360b Add build dependencies for Alpine Linux 2023-07-27 21:48:53 +09:00
Rui Ueyama b0b015bc2e Merge pull request #1066 from aloisklink/install-LICENSE.third-party 2023-07-27 14:49:00 +09:00
Rui Ueyama 7f66689e21 Merge pull request #1068 from pcc/adrp 2023-07-27 14:42:12 +09:00
Peter Collingbourne 17a5c3e0ab Support R_AARCH64_ADR_PREL_PG_HI21_NC 2023-07-26 21:33:26 -07:00
Alois Klink 3ed5b8ddf7 Install LICENSE.third-party when using CMake 2023-07-27 01:10:22 +01:00
Rui Ueyama de991b519a Bump mold version to 2.0 2023-07-26 19:40:11 +09:00
Rui Ueyama a066fe25c6 Change the license to the MIT license 2023-07-26 14:49:42 +09:00
Rui Ueyama 6e8a9dfec1 Merge pull request #1058 from andreas-schwab/main 2023-07-24 19:09:17 +09:00
Rui Ueyama 31eeb44d4f Format 2023-07-23 13:23:36 +09:00
Rui Ueyama 44b15cbb35 Update the bundled xxhash to v0.8.2 2023-07-21 19:28:46 +09:00
Rui Ueyama b5b3ffa6fe Merge pull request #1062 from Expander/replace-pow 2023-07-20 19:54:41 +09:00
Rui Ueyama 83a924ddac Fix CI 2023-07-20 17:41:08 +09:00
Rui Ueyama 2e8bd0b7a6 Handle an output relocatable object file with a large number of sections
Fixes https://github.com/rui314/mold/issues/1061
2023-07-20 16:38:54 +09:00
Alexander Voigt b685f3cab7 replace pow(2,x) by ldexp(1.0,x) for performance 2023-07-20 09:28:35 +02:00
Rui Ueyama 2d25a93126 Handle -undefined as a synonym for --undefined instead of -u ndefined
Fixes https://github.com/rui314/mold/discussions/1059
2023-07-18 16:59:44 +09:00
Rui Ueyama a8eb52f61a Format 2023-07-17 16:00:39 +09:00
Rui Ueyama 761c341c19 Improve MIPS64 support 2023-07-17 11:45:55 +09:00
Rui Ueyama 000e395c07 Improve MIPS64 support 2023-07-16 08:01:42 +09:00
Rui Ueyama 4b06f1e9f6 Refactor 2023-07-15 15:01:03 +09:00
Rui Ueyama 29dc0cf53f Initial MIPS64 support
Although incomplete, this implementation is capable of passing the
following tests:

  TRIPLE=mips64el-linux-gnuabi64 bash -x ../test/elf/hello-dynamic.sh
  TRIPLE=mips64-linux-gnuabi64 bash -x ../test/elf/hello-dynamic.sh
2023-07-14 15:11:53 +09:00
Rui Ueyama f8b55680f8 Revert "Merge .alpha_got with .got"
This reverts commit 72671df483.
2023-07-14 14:12:45 +09:00
Rui Ueyama cb08466693 Attempt to fix CI 2023-07-14 10:41:36 +09:00
Rui Ueyama 72671df483 Merge .alpha_got with .got
It's not only Alpha but MIPS relocations also need dynamic symbols
with addends, so we want to use this code not only for Alpha.
2023-07-14 10:06:18 +09:00
Rui Ueyama 83524e3690 Update comments 2023-07-09 11:25:02 +09:00
Rui Ueyama 0125d9c254 Refactor 2023-07-06 17:33:41 +09:00
Andreas Schwab 1ac5fe7c1e Fix support for R_RISCV_SET_ULEB128 and R_RISCV_SUB_ULEB128
Handle allocated sections and write the full value into the location.

Signed-off-by: Andreas Schwab <[email protected]>
2023-07-06 10:23:38 +02:00
Rui Ueyama 4b42f38257 Handle embedded default version strings in LTO symbols
Fixes https://github.com/rui314/mold/issues/1056
2023-07-05 19:07:52 +09:00
Rui Ueyama d2b153c522 Refactor 2023-07-05 18:43:07 +09:00
Rui Ueyama ab126ad1d9 Make sure to import versioned symbols
Undefined versioned symbols are handled specially; they are resolved
at the very end of name resolution stage. When they are resolved, we
need to make sure that they are marked as imported symbols.

Fixes https://github.com/rui314/mold/issues/1057
2023-07-05 11:34:33 +09:00
Rui Ueyama b04aba89d3 Add -z stack-size
https://github.com/rui314/mold/issues/917
2023-06-29 15:58:00 +09:00
Rui Ueyama 2cb41d8a2b Upgrade bundled mimalloc to v2.1.2 2023-06-29 12:23:39 +09:00
Rui Ueyama 1b1a142a89 Upgrade bundled OneTBB to version 2021.9.0 2023-06-29 12:21:58 +09:00
Rui Ueyama dcfe76bc80 Format 2023-06-29 12:17:21 +09:00
Rui Ueyama d4d93d7fb7 Format 2023-06-19 12:35:20 +09:00
Rui Ueyama ebd780e8ba Support R_PPC64_REL32
Fixes https://github.com/rui314/mold/issues/1049
2023-06-17 19:00:55 +09:00
Rui Ueyama 65bd36ba40 Generate a PT_OPENBSD_RANDOMIZE segment 2023-06-14 14:08:40 +09:00
Rui Ueyama bc86ab514f Add -nopie as an alias for -no-pie
OpenBSD seems to be using an alternative spelling for this option.
2023-06-14 09:55:55 +08:00
Rui Ueyama 8ee7773260 Do not use mimalloc on OpenBSD
It seems like mimalloc doesn't work on OpenBSD at all.
2023-06-13 11:10:04 +08:00
Rui Ueyama e011889436 Fix build on systems without ucontext.h in libc
Upstream patch:
https://github.com/oneapi-src/oneTBB/commit/ea4e6156a2cde839fc01b21b76cd9b5743ec0cef
2023-06-05 11:52:56 +09:00
Rui Ueyama 16e22ec067 Handle "amd64" as a synonym for "x86_64"
OpenBSD's `uname` returns `amd64` instead of `x86_64`.
2023-06-04 15:28:44 +09:00
Rui Ueyama d2ee47a4ac Print out a hint about older versions of litbb
https://github.com/rui314/mold/issues/1031
2023-06-04 15:28:44 +09:00
Rui Ueyama dce8ebe526 Merge pull request #1033 from ishitatsuyuki/wrap-mold
mold-wrapper: Wrap ld.mold as well.
2023-04-19 20:10:36 +09:00
Tatsuyuki Ishi 23de4be59f mold-wrapper: Wrap ld.mold as well.
Convenient if you have configured to use mold for a particular project but want
to test a new local build.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2023-04-19 19:35:29 +09:00
Rui Ueyama 76e3f87775 Merge pull request #1034 from ishitatsuyuki/errno 2023-04-19 19:26:54 +09:00
Tatsuyuki Ishi fca6fad720 MappedFile: Fail on open() errors other than ENOENT.
open() can fail with transient reasons, such as running out of file descriptor
limit. Previously, this was treated the same as file not being found, which
caused confusing error messages [1].

With this change anything but ENOENT will be treated as a fatal error. This will
also include e.g. permission errors, but if there's something within the search
path that is not accessible, it's likely better to tell the user instead of
silently skipping it.

[1]: https://github.com/rui314/mold/issues/1026

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2023-04-19 17:29:37 +09:00
Rui Ueyama ceffcfcadd Fix test
Fixes https://github.com/rui314/mold/issues/1030
2023-04-18 16:47:16 +09:00
Rui Ueyama 1ad19a4ce1 Simplify 2023-04-16 14:57:47 +09:00
Rui Ueyama 67a58c01d0 Update comments 2023-04-16 14:41:10 +09:00
Rui Ueyama 186ac191c4 Update comments 2023-04-15 15:15:18 +09:00
Rui Ueyama 34bf04bc41 Improve tests 2023-04-15 12:53:43 +09:00
Rui Ueyama e6db53fadb Do not set STT_GNU_IFUNC to non-exported symbols
STT_GNU_IFUNC is significant only for exported symbols. Setting
non-exported symbol type to STT_GNU_IFUNC actually causes an issue
if the symbol is used as a canonical PLT because the runtime would
try to run the canonical PLT as an IFUNC.

Fixes https://github.com/rui314/mold/issues/1028
2023-04-15 12:32:21 +09:00
Rui Ueyama 461001328b Simplify 2023-04-02 09:09:04 +08:00
Rui Ueyama 4bffe26bc0 Support R_RISCV_SET_ULEB128 and R_RISCV_SUB_ULEB128
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/361
2023-03-31 10:26:50 +08:00
Rui Ueyama 290b4eaa46 Refactor 2023-03-28 17:30:44 +08:00
Rui Ueyama 0f1b828e6a Refactor 2023-03-28 16:57:57 +08:00
Rui Ueyama 46288758a0 Improve README with ChatGPT 2023-03-22 16:48:14 +08:00
Rui Ueyama e8789c71a4 Format 2023-03-22 16:35:22 +08:00
Rui Ueyama f54203d76c Update the auto-generated manpage 2023-03-22 12:55:52 +08:00
Rui Ueyama a5634794b3 Improve the man page
I made this change by asking GPT-4-based ChatGPT to improve this
document with an additional note that this document was written by a
non-native English speaker and may have wrong or unnatural phrases.
2023-03-22 12:40:35 +08:00
Rui Ueyama b403b811cd Report a possible ODR violation
https://github.com/rui314/mold/issues/1019
2023-03-18 16:32:04 +08:00
Rui Ueyama 36fc065548 Add a feature to not run mold simultaneously
https://github.com/rui314/mold/issues/117
2023-03-17 14:58:27 +08:00
Rui Ueyama 39b4548a2a Simplify 2023-03-17 13:58:11 +08:00
Rui Ueyama 52f0c4a06f Fix typos 2023-03-17 13:49:59 +08:00
Rui Ueyama c74fe12dd5 Fix test 2023-03-16 18:24:25 +08:00
Rui Ueyama fe11565110 Improve comments 2023-03-16 18:08:44 +08:00
Rui Ueyama cca255e6be Bump mold version to 1.11.0 2023-03-16 14:01:09 +08:00
Rui Ueyama 325d12d169 Upload test artifacts only on test failure 2023-03-15 08:32:51 +08:00
Rui Ueyama 2a26a0db64 Fix CI 2023-03-15 08:32:51 +08:00
Rui Ueyama 72c9425ae3 Merge pull request #1016 from marxin/fix-Wunused-but-set-variable
Fix warning: variable ‘check’ set but not used [-Wunused-but-set-variable]
2023-03-14 21:44:48 +09:00
Rui Ueyama ff46c33d3f Merge pull request #1015 from marxin/fix-Wint-in-bool-context
fix thunks.cc:81:32: warning: enum constant in boolean context [-Wint…
2023-03-14 21:44:33 +09:00
Martin Liska c59b3f5fa5 Fix warning: variable ‘check’ set but not used [-Wunused-but-set-variable]
Signed-off-by: Martin Liska <[email protected]>
2023-03-14 13:28:45 +01:00
Martin Liska 84a5509da2 fix thunks.cc:81:32: warning: enum constant in boolean context [-Wint-in-bool-context]
Fixes the following error:
/elf/thunks.cc:81:32: warning: enum constant in boolean context [-Wint-in-bool-context]
  return ty == R_PPC64_REL24 || R_PPC64_REL24_NOTOC;

Signed-off-by: Martin Liska <[email protected]>
2023-03-14 13:25:05 +01:00
Rui Ueyama 305153b9c7 Archive test results 2023-03-14 19:22:56 +08:00
Rui Ueyama 1adde7aa51 Make undefined symbol in a DSO to keep other DSOs alive
Fixes https://github.com/rui314/mold/issues/1014
2023-03-14 18:52:03 +08:00
Rui Ueyama 4fa2bc17b8 Allow empty mergeable sections
Fixes https://github.com/rui314/mold/issues/1012
2023-03-14 07:14:18 +08:00
Rui Ueyama 294a467116 Rename files 2023-03-13 16:23:36 +08:00
Rui Ueyama 67eb3069b3 Fix build failure
Fixes https://github.com/rui314/mold/issues/1008
2023-03-07 18:34:59 +08:00
Rui Ueyama ad2694445c Import changes from sold 2023-03-07 15:57:28 +08:00
Rui Ueyama 6a1713e440 Merge pull request #1004 from ishitatsuyuki/lto-eh-frame 2023-03-07 12:01:54 +09:00
Tatsuyuki Ishi 62d65371d7 [ELF] Kill .eh_frame sections after symbol resolution.
Handle .eh_frame in a similar way as mergeable sections.

This seems to be required for GCC CRT compiled with LTO.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2023-03-06 13:22:06 +08:00
Rui Ueyama c4722fe5ae Build Linux binaries on GitHub Actions 2023-03-05 14:46:32 +08:00
Tatsuyuki Ishi 13472be059 [ELF] Resolve .eh_frame symbols renamed by GCC LTO.
When LTO is enabled for CRT it seems symbols like __EH_FRAME_BEGIN__.lto_priv.0
can be created. Treat it as the same as the non-LTO variant.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2023-03-05 13:59:40 +08:00
Rui Ueyama 6d2dbd42a6 Preparation to support Apple ld64's -w option 2023-03-05 08:48:09 +08:00
Rui Ueyama d2970e096d Support R_X86_64_GOTOFF64 in non-memory-allocated sections
Fixes https://github.com/rui314/mold/issues/1003
2023-03-05 08:07:24 +08:00
Rui Ueyama 77c4795139 Workaround for an old GCC issue
Fixes https://github.com/rui314/mold/issues/1003
2023-03-04 17:10:49 +08:00
Rui Ueyama 5434babdf3 Fix typo 2023-03-04 16:53:02 +08:00
Rui Ueyama 530b3ebd88 Enable tests for Power10 if MOLD_ENABLE_QEMU_TESTS_POWER10 is true 2023-03-04 16:13:57 +08:00
Rui Ueyama 33172a7b61 Update comments 2023-03-04 11:01:25 +08:00
Rui Ueyama 5065547c4e Support the Power10 ABI 2023-03-04 09:43:42 +08:00
Rui Ueyama 0870078ed2 Merge pull request #997 from ksco/fix_rv64_test 2023-02-22 18:27:57 +09:00
Yang Liu 992ad0fc08 [RISCV] Fix riscv64_obj-compatible 2023-02-22 16:40:42 +08:00
Rui Ueyama 5ae8ec9669 Merge pull request #993 from ksco/riscv_compatibility 2023-02-21 14:03:08 +09:00
Rui Ueyama 0bd5adde7e Refactor 2023-02-20 18:06:33 +08:00
Yang Liu 7e8a9f230c [RISCV] Add an obj ABI incompatibility tests
Signed-off-by: Yang Liu <[email protected]>
2023-02-19 19:59:29 +08:00
Yang Liu f7bc901c2d [RISCV] Check object files' compatibility
Signed-off-by: Yang Liu <[email protected]>
2023-02-19 19:58:13 +08:00
Rui Ueyama e1a7590db3 Fix LTO symbol resolution instability
Previously, we clear liveness bits for all input files after compiling
IR object files to real object files so that we can do name resolution
completely from scratch. However, that can result in inconsistent name
resolution results before and after LTO.

Consider a weak defined symbol X in an object file. A weak undef doesn't
pull files out of an archive file. However, if symbol X is transformed
to an undefined symbol as a result of LTO, it could pull out a file from
an archive. That can have cascading effects and result in a link failure.

With this fix, all object files that are alive at the time when LTO kicks
in are guaranteed to be kept after LTO.

Fixes https://github.com/rui314/mold/issues/991
2023-02-19 16:26:46 +08:00
Rui Ueyama f592b6e167 Refactor 2023-02-16 15:18:25 +08:00
Rui Ueyama 8c0f455b97 Refactor 2023-02-16 08:58:47 +08:00
Rui Ueyama 0d08c52258 Refactor 2023-02-15 20:46:50 +08:00
Rui Ueyama a42626b975 Skip if ppc64
Fixes https://github.com/rui314/mold/issues/989
2023-02-15 15:51:35 +08:00
Rui Ueyama ec728d0cef Simplify 2023-02-13 10:17:37 +08:00
Rui Ueyama 20bddc75cf Avoid inline assembly 2023-02-12 11:58:47 +08:00
Rui Ueyama 45bece4bd9 Handle ppc64 as a synonym for powerpc64
Fixes https://github.com/rui314/mold/issues/986
2023-02-12 09:06:10 +08:00
Rui Ueyama 445a23fbc0 Merge pull request #985 from ksco/fix_ci_warnings
[CI] Use clang++-12 to suppress warnings
2023-02-12 08:11:18 +09:00
Rui Ueyama 6952a2efa5 Merge pull request #984 from ksco/weak_undef4
Add an another weak undef test
2023-02-12 08:09:44 +09:00
Yang Liu 8c2ccd2f55 [CI] Use clang++-12 to suppress warnings 2023-02-11 15:00:08 +08:00
Yang Liu 9ce963b480 Add an another weak undef test
This test ensures that mold does not extract archive members to resolve
undefined weak symbols.

Signed-off-by: Yang Liu <[email protected]>
2023-02-11 14:51:30 +08:00
Rui Ueyama 35794cfc66 Merge pull request #983 from ksco/weak_undef3 2023-02-11 13:24:06 +09:00
Yang Liu e300c6d9b2 [RISCV] Add a weak undef symbol test case
Signed-off-by: Yang Liu <[email protected]>
2023-02-11 11:43:02 +08:00
Rui Ueyama 8660db16a8 Update man page 2023-02-11 08:51:20 +08:00
Rui Ueyama 25b4f0b054 Merge pull request #980 from ksco/fix_undef_weak
[RISCV] Fix R_RISCV_PCREL_HI20
2023-02-10 10:28:53 +09:00
Yang Liu fc809c6c73 [RISCV] Fix R_RISCV_PCREL_HI20 2023-02-09 14:15:56 +08:00
Rui Ueyama 51845ac5fe Support R_RISCV_PLT32
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/363
2023-02-06 12:48:56 +08:00
Rui Ueyama 8e50fad6b9 Update man page 2023-02-06 12:48:56 +08:00
Rui Ueyama 3e818cd350 Simplify 2023-02-06 08:24:33 +08:00
Rui Ueyama 4327d4547e Fix typo 2023-02-06 08:10:45 +08:00
Rui Ueyama abba8b5864 Update man page 2023-02-05 21:10:39 +08:00
Rui Ueyama 8ede25fa42 Write man page in Markdown instead of mandoc
mandoc is hard to read and hard to write. With `ronn` command, we can
write a man page in Markdown and convert it to roff.
2023-02-05 16:46:46 +08:00
Rui Ueyama 50d4bc04ab Update README 2023-02-05 12:10:09 +08:00
Rui Ueyama 128f8b3b8d Remove mentions to mold/macOS
Fixes https://github.com/rui314/mold/issues/978
2023-02-05 12:04:07 +08:00
Rui Ueyama 5140010a6e Attempt to fix R_ARM_PLT32
https://github.com/rui314/mold/issues/974
2023-02-05 08:06:13 +08:00
Rui Ueyama 24c21d7ed2 Simplify
is_imported and is_exported are computed and overwritten by
compute_import_export(), so these early assignments are redundant.
2023-02-05 07:52:37 +08:00
Rui Ueyama e50590043c Support R_AARCH64_PLT32 2023-02-01 11:36:06 +08:00
Rui Ueyama fdc592b169 Warn on shared object files in archives
https://github.com/rui314/mold/issues/976
2023-01-30 09:38:44 +08:00
Rui Ueyama 82731d62f9 Add a new sponsor name 2023-01-28 09:34:28 +08:00
Rui Ueyama 912a863b13 Refactor 2023-01-28 09:03:24 +08:00
Rui Ueyama 627bf7c8ef Do not relax GOTPCRELX reloc if it's unreachable
Fixes https://github.com/rui314/mold/issues/975
2023-01-27 20:12:40 +08:00
Rui Ueyama beddabe64d Import changes for the sold linker 2023-01-26 08:34:04 +08:00
Rui Ueyama 339b1b4704 Merge pull request #973 from ganta/patch-1
Adjust the image ratio and fix the alt attribute.
2023-01-24 12:47:55 +09:00
Hideki Igarashi 8dff18db0e Adjust the image ratio and fix the alt attribute.
Signed-off-by: Hideki Igarashi <[email protected]>
2023-01-24 12:40:26 +09:00
Rui Ueyama ebb9b6aff8 Add commas 2023-01-23 21:45:23 +08:00
Rui Ueyama 22af2ff328 Add Cybozu as a corporate-tier sponsor 2023-01-23 17:02:23 +08:00
Rui Ueyama d755793345 Remove unused struct member 2023-01-23 09:35:38 +08:00
Rui Ueyama ec756333cb Support --hash-style=none to cancel --hash-style=[sysv|gnu|both]
https://github.com/rui314/mold/issues/971
2023-01-22 20:29:15 +08:00
Rui Ueyama ce3aa9a752 Update an include file path
Pointed out by https://github.com/rui314/mold/pull/972/files
2023-01-22 19:35:45 +08:00
Rui Ueyama e48b90f941 Make Atomic copyable and copy-constructible 2023-01-22 16:25:25 +08:00
Rui Ueyama 7f407fb1ae Refactor 2023-01-22 12:44:59 +08:00
Rui Ueyama ac212c3d00 Improve range extension insertion algorithm
Now the algorithm matches with the code comment.
2023-01-22 12:29:33 +08:00
Rui Ueyama 040180f933 Bump mold version to 1.10.1 2023-01-22 09:57:00 +08:00
Rui Ueyama 7e6554677f Fix out-of-bound memory access
Fixes https://github.com/rui314/mold/issues/969
2023-01-21 12:06:10 +08:00
Rui Ueyama dbeb10c0d2 Recognize ld64.sold as a command name 2023-01-20 16:21:18 +08:00
Rui Ueyama c935d6387a Bump mold version to 1.10.0 2023-01-20 15:03:58 +08:00
Rui Ueyama acdd92e741 Refactor 2023-01-20 15:02:32 +08:00
Rui Ueyama 62660bc02a Refactor 2023-01-20 12:07:03 +08:00
Rui Ueyama 90d9fd06ae Refactor 2023-01-19 20:34:00 +08:00
Rui Ueyama 82d412cbff Report an error for a TLS access model mismatch 2023-01-19 16:59:06 +08:00
Rui Ueyama 85efa3796a Set DF_STATIC_TLS to DSOs that cannot be loaded with dlopen() 2023-01-19 16:37:03 +08:00
Rui Ueyama 3f672919c2 Refactor 2023-01-19 15:01:22 +08:00
Rui Ueyama a2e8f13ddd Refactor 2023-01-19 14:54:48 +08:00
Rui Ueyama 821fb07083 Also fix R_390_{PC,PLT}12DBL 2023-01-19 14:16:22 +08:00
Rui Ueyama b9bd71ecfc Fix R_390_{12,GOT12,GOTPLT12}
When writing a 12 bit value, we need to preserve the most significant 4 bits.
2023-01-19 14:01:05 +08:00
Rui Ueyama 9df4d6e479 Fix test/elf/compressed-debug-info.sh for SH-4 2023-01-19 12:51:51 +08:00
Rui Ueyama 29eb97fda5 Rename a file 2023-01-19 11:43:29 +08:00
Rui Ueyama 67c6255c9a Refactor 2023-01-19 10:31:21 +08:00
Rui Ueyama 2d68cbbfd2 Save 8 byte of memory for each global symbol 2023-01-19 08:54:16 +08:00
Rui Ueyama f98e0ef92a Refactor 2023-01-18 20:57:24 +08:00
Rui Ueyama 83303995c7 Refactor 2023-01-18 20:40:26 +08:00
Rui Ueyama 7d369dd9e8 Refactor 2023-01-18 17:29:17 +08:00
Rui Ueyama 9f66ea7026 Build the native binary by default 2023-01-18 16:29:25 +08:00
Rui Ueyama 67a96ae8e1 Refactor 2023-01-18 16:20:20 +08:00
Rui Ueyama 8936194ba7 Report all undefined symbols correctly
Previously, we failed to report an undefined error if we have two
undefined symbols, a strong and a weak one, for the same symbol.

It is an undefined symbol error if an undefined symbol is resolved
to a weak undefined symbol.

Fixes https://github.com/rui314/mold/issues/967
2023-01-18 16:01:36 +08:00
Rui Ueyama 00af084416 Remove an unnecessary dependency 2023-01-18 12:45:08 +08:00
Rui Ueyama 3829372a42 Refactor 2023-01-18 11:24:15 +08:00
Rui Ueyama 54ab1ec4b4 Silence -Werror=format-truncation
Ideally we wanted to use __builtin_assume() or [[assume]], but the former
is available only in clang and the latter is in C++23.

Fixes https://github.com/rui314/mold/issues/966
2023-01-18 11:00:59 +08:00
Rui Ueyama f4b0596b3a Update the man page 2023-01-18 09:02:55 +08:00
Rui Ueyama 71f6b0bc32 Refactor 2023-01-17 21:05:26 +08:00
Rui Ueyama fb8e63e498 Make some tests faster 2023-01-17 09:19:09 +08:00
Rui Ueyama 1a133a4df5 Upgrade the bundled mimalloc from 2.0.7 to 2.0.9 2023-01-17 08:53:56 +08:00
Rui Ueyama 60fc036bd6 Enabling logging is [[unlikely]] 2023-01-17 07:25:18 +08:00
Rui Ueyama 3d96596485 Add a newline after a comment for --print-dependencies 2023-01-16 18:08:52 +08:00
Rui Ueyama 0a8e90bd84 Rename a file 2023-01-16 16:22:30 +08:00
Rui Ueyama 1e961000e6 Move more files under common/ 2023-01-16 15:35:24 +08:00
Rui Ueyama 3539487471 Remove an unnecessary file 2023-01-16 15:31:33 +08:00
Rui Ueyama 6caf0867b0 Reorganize files 2023-01-16 15:27:10 +08:00
Rui Ueyama 28a6c0e4f0 Update references 2023-01-16 12:34:36 +08:00
Rui Ueyama a4349df0a5 [PPC64v1] Support a PLT section containing more than 32767 entries. 2023-01-16 11:06:34 +08:00
Rui Ueyama d2335707de [x86] Always relax TLSGD/TLSLD if -static 2023-01-14 15:27:28 +08:00
Rui Ueyama 1d2b08ade7 [x86] Always relax GOTX relocations 2023-01-14 15:19:27 +08:00
Rui Ueyama dd93988dc6 Simplify 2023-01-14 13:14:07 +08:00
Rui Ueyama 06ec355e88 Improve instal-build-deps script
voidlinux/voidlinux Docker image doesn't contain bash, so we should
eliminate the dependency to bash from this script.
2023-01-14 12:00:49 +08:00
Rui Ueyama c10f36c71c Merge pull request #963 from mystuffs/main
Add: build deps when compiling mold on Void Linux
2023-01-14 12:37:56 +09:00
Rui Ueyama f32ce333dd [s390x] Implement TLSGD to TLSIE relaxation 2023-01-14 11:33:58 +08:00
rilysh d48c52cc2f Merge branch 'rui314:main' into main 2023-01-14 08:49:54 +05:30
Rui Ueyama 25d02bb261 [x86-64] Implement TLSGD to TLSIE relaxation
If we know that the .so file we are creating will not be dlopen'ed,
we can relax __tls_get_addr function calls to GOT loads.
2023-01-14 10:22:06 +08:00
rilysh fda7657eab add: build deps for Void Linux
Install build dependencies when compiling mold on Void Linux

Signed-off-by: rilysh <[email protected]>
2023-01-14 01:06:06 +00:00
Rui Ueyama 983fe0f10f Refactor 2023-01-13 21:07:30 +08:00
Rui Ueyama 8437097305 Refactor 2023-01-13 20:46:19 +08:00
Rui Ueyama 5a9341659c Remove an unnecessary log message 2023-01-13 17:43:08 +08:00
Rui Ueyama 125af4c855 Refactor 2023-01-13 16:34:50 +08:00
Rui Ueyama fa1db07ec8 Optimize section fragment liveness management 2023-01-13 15:23:09 +08:00
Rui Ueyama f09bf0615b Simplify 2023-01-13 11:36:02 +08:00
Rui Ueyama 534cd392db Do not run if -static is not supported
Fixes https://github.com/rui314/mold/issues/961
2023-01-13 08:48:09 +08:00
Rui Ueyama 5dee5ea49d Refactor 2023-01-12 17:11:18 +08:00
Rui Ueyama 957eaf0f18 Optimize DynamicSection::finalize
Parallelizing this loop makes sense if we have hundreds of thousands
of dynamic symbols.
2023-01-12 13:44:02 +08:00
Rui Ueyama 12fad60eb4 Reduce the number of dynamic symbols for TLS symbols 2023-01-12 11:52:10 +08:00
Rui Ueyama 404077e330 Refactor 2023-01-12 10:49:20 +08:00
Rui Ueyama 73947c56e1 Create section symbols for non-ALLOC sections
Previously, we created section symbols only for memory-allocated secitons.
That resulted in symbols with invalid section indices for the --relocatable
output.

https://github.com/rui314/mold/issues/957
2023-01-12 09:57:24 +08:00
Rui Ueyama 63fae64e77 Refactor 2023-01-12 09:55:53 +08:00
Rui Ueyama 7f27b180ac Optimize 2023-01-11 17:29:39 +08:00
Rui Ueyama 6f4ba44946 Avoid sequentially consistent memory access 2023-01-11 14:16:41 +08:00
Rui Ueyama dcc58e4f7a Refactor 2023-01-11 10:45:45 +08:00
Rui Ueyama a68dfdb2d3 Reduce the sizes of Symbol and Relocation for needs_thunk targets
Since the maximum size of RangeExtensionThunk is 100 KiB, it can't contain
too many entries, so the contents is addressable with a 16-bit value.

We don't create more than 32768 range extension thunks (unless the output
is hundreds gibibytes in size), so we can also use i16 to specify the
index of RangeExtensionThunk.
2023-01-10 17:39:17 +08:00
Rui Ueyama 277dd7710a Refactor 2023-01-10 17:27:35 +08:00
Rui Ueyama d03c9a1654 Fix data race
The iterator obtained by `find()` may be invalidated by other writes
happening concurrently, so we shouldn't release the mutex while we
are using it.
2023-01-10 15:22:07 +08:00
Rui Ueyama 19bb456721 Merge pull request #954 from MehdiChinoune/fix-mingw-w64 2023-01-10 15:34:05 +09:00
مهدي شينون (Mehdi Chinoune) 4e26d7b237 Fix building on MinGW-w64
Signed-off-by: Mehdi Chinoune <[email protected]>
2023-01-10 06:41:46 +01:00
Rui Ueyama 6a797a4fbc Fix CI 2023-01-10 13:41:31 +08:00
Rui Ueyama 14784bbc4e Fix CI 2023-01-10 13:04:12 +08:00
Rui Ueyama 6fd47dbab4 Document the --print-dependencies option
We used to have `--print-dependencies` and `--print-dependencies=full`
options. I think this distinction is necesssary. Now, `=full` is renamed
`--print-dependencies`.
2023-01-10 12:54:00 +08:00
Rui Ueyama e31801f22f Refactor 2023-01-10 12:37:25 +08:00
Rui Ueyama 58e81bb0a0 Cache more results 2023-01-09 20:32:51 +08:00
Rui Ueyama d2cdce4410 Implement another algorithm to optimize create_output_sections
https://github.com/rui314/mold/issues/937
2023-01-09 19:31:22 +08:00
Rui Ueyama 7132822cc7 Mitigate lock contention
This change speeds up the `create_output_sections` pass.

https://github.com/rui314/mold/issues/937
2023-01-09 18:05:18 +08:00
Rui Ueyama ca98fe843d Fix -Werror=implicit-fallthrough
These aren't bug, but I decided to repeat the same code instead of
adding [[fallthrough]] because the code duplication is very small.

Fixes https://github.com/rui314/mold/issues/952
2023-01-09 17:04:51 +08:00
Rui Ueyama bbfed9af3f Do not access uninitialized memory 2023-01-09 16:38:10 +08:00
Rui Ueyama 707ddaa630 Avoid unnecessary memory initializations 2023-01-09 14:44:02 +08:00
Rui Ueyama d127583c86 Refactor 2023-01-09 13:59:35 +08:00
Rui Ueyama 7128ee371d Skip if ARM64 too
https://github.com/rui314/mold/issues/951
2023-01-09 13:21:35 +08:00
Rui Ueyama 321158b99f Skip test if musl libc
Fixes https://github.com/rui314/mold/issues/951
2023-01-09 13:03:49 +08:00
Rui Ueyama d71a672089 Fix an option name
LLVM lld does not accept `-gdb-index` as an option
2023-01-09 12:46:15 +08:00
Rui Ueyama e17d7daee8 Fix a crash bug in --emit-relocs
Fixes https://github.com/rui314/mold/issues/950
2023-01-09 09:31:27 +08:00
Rui Ueyama d4e40a31c1 Do not R_AARCH64_ADR_GOT_PAGE if it refers an IFUNC 2023-01-09 08:56:48 +08:00
Rui Ueyama 915cd23b2f Skip if GNU IFUNC is not supported
Even on x86-64, non-GNU libc may not support the IFUNC.

Fixes https://github.com/rui314/mold/issues/949
2023-01-09 08:26:36 +08:00
Rui Ueyama 994f800f8f Add a missing relocation overflow check 2023-01-09 08:15:18 +08:00
Rui Ueyama 2b3a684869 Refactor 2023-01-09 08:15:03 +08:00
Rui Ueyama 68b2b35148 Refactor 2023-01-08 21:15:53 +08:00
Rui Ueyama da6dd7c0ac [ARM64] Relax R_AARCH64_ADR_PREL_PG_HI21 2023-01-08 20:47:49 +08:00
Rui Ueyama f2311b1efa [ARM64] Relax GOT-loading ADRP+LDR to ADRP+ADD 2023-01-08 16:43:23 +08:00
Rui Ueyama b8bb78fde7 Update comments 2023-01-08 13:58:41 +08:00
Rui Ueyama e4a1a57318 Update comments 2023-01-08 13:21:36 +08:00
Rui Ueyama 1ebaa27fc4 Refactor 2023-01-08 12:46:51 +08:00
Rui Ueyama d6db850121 Refactor 2023-01-08 12:02:40 +08:00
Rui Ueyama ebf732fca9 Update comments 2023-01-08 11:26:21 +08:00
Rui Ueyama eba86d5312 Document TLS 2023-01-08 09:38:55 +08:00
Rui Ueyama 648fcc60ca Refactor 2023-01-08 07:35:14 +08:00
Rui Ueyama 9f5b7e278f Enable -gdb-index when building mold 2023-01-07 17:26:08 +08:00
Rui Ueyama 14fe1ba070 Fix typo 2023-01-07 17:21:14 +08:00
Rui Ueyama 9d3cfd5c7d Refactor 2023-01-07 16:39:13 +08:00
Rui Ueyama c2d5f602e7 Refactor 2023-01-07 15:00:03 +08:00
Rui Ueyama ed42ce0d36 Do not install LICENSE file if it does not exist 2023-01-07 14:28:08 +08:00
Rui Ueyama 8201d0ed2a Add const 2023-01-07 11:59:18 +08:00
Rui Ueyama 779a404950 [RISC-V] Fix wrong R_RISCV_LO12_{I,S} relaxation 2023-01-07 11:27:13 +08:00
Rui Ueyama 52a0638dd2 Simplify
We used to try to avoid using identifiers such as S, A or P more than
once because they were defined as macros expaneded to function calls.
Now they are just variables, so we can use them as many times as we
want without any performance penalty.
2023-01-07 11:09:47 +08:00
Rui Ueyama 73034f94fe Do not trigger undefined behavior for unknown relocations
Unknown relocations will be reported by scan_relocations(). We don't
want to execute unreachable() statement in get_addend() because it
triggers undefined behavior.

https://github.com/rui314/mold/issues/947
2023-01-07 10:23:07 +08:00
Rui Ueyama ad0b6d0ac6 Bump mold version to 1.9.0 2023-01-06 16:13:10 +08:00
Rui Ueyama 6e918eda31 Fix CI 2023-01-06 12:04:47 +08:00
Rui Ueyama 3c968289f8 Fix crash bug for when --gdb-index and -gsplit-dwarf are used together
Fixes https://github.com/rui314/mold/issues/940
2023-01-06 11:09:12 +08:00
Rui Ueyama cb204decf4 Fix R_RISCV_HI20 relaxation
If we compile a program for high address, this code would accidentally
clear high 20 bits.
2023-01-06 10:22:20 +08:00
Rui Ueyama f9fe3d621f Refactor 2023-01-05 21:48:03 +08:00
Rui Ueyama b51d5baae6 Handle R_ARM_PLT32 as an alias for R_ARM_JUMP24 instead of R_ARM_CALL
It looks like R_ARM_PLT32 can be applied to non-BL/non-BLX instructions,
so we can't handle it as an alias for R_ARM_CALL.

https://github.com/rui314/mold/issues/934
2023-01-05 18:07:52 +08:00
Rui Ueyama 747ba1d41e Add a missing relocation type
https://github.com/rui314/mold/issues/934
2023-01-05 17:20:56 +08:00
Rui Ueyama 5c4ed9259e Enable more tests for arm32 2023-01-05 15:20:52 +08:00
Rui Ueyama d3e0ffe0b9 Refactor 2023-01-05 09:49:28 +08:00
Rui Ueyama 17a24cdd7e Fix "error: enumerated and non-enumerated type in conditional expression" warning
Fixes https://github.com/rui314/mold/issues/945
2023-01-04 09:02:16 +08:00
Rui Ueyama 4a66d7a573 Revert "Bit permutation"
This reverts commit cbd88ed3f3.
It was a nice abstraction but wasn't worth its complexity unless we
use it in various places. The original simple code is more in line
with other parts of mold.

Fixes https://github.com/rui314/mold/issues/946
2023-01-04 08:51:20 +08:00
Rui Ueyama cbd88ed3f3 Bit permutation 2023-01-03 18:05:15 +08:00
Rui Ueyama 9157414cae Make ElfRel trivial type
Fixes https://github.com/rui314/mold/issues/944
2023-01-03 16:47:24 +08:00
Rui Ueyama 6663adb700 Refactor 2023-01-03 16:47:16 +08:00
Rui Ueyama 7c64f67499 Merge pull request #943 from marxin/fix-Wunused-variable 2023-01-03 17:35:24 +09:00
Martin Liska 7539c3fd15 Fix warning: unused variable 'G' [-Wunused-variable]
elf/arch-i386.cc:425:9: warning: unused variable 'G' [-Wunused-variable]

Signed-off-by: Martin Liska <[email protected]>
2023-01-03 09:31:28 +01:00
Rui Ueyama 83f6bc18e1 Refactor 2023-01-02 20:52:43 +08:00
Rui Ueyama ea4cb40131 Fix CI 2023-01-02 20:44:45 +08:00
Rui Ueyama bdc3d71a23 Refactor 2023-01-02 19:53:05 +08:00
Rui Ueyama b15ce5203d Refactor 2023-01-02 16:31:14 +08:00
Rui Ueyama 4507e6e51d Do not create thunks for all symbols 2023-01-02 16:13:16 +08:00
Rui Ueyama c86689b227 Do not use C macros
We used to use C macros as a poor-man's way to inline Symbol::get_addr(),
but it looks like inlining that member function isn't an overall win.
This change removes `inline` from that member function and depends on the
compiler's optimizations to optimize function calls.
2023-01-02 15:44:11 +08:00
Rui Ueyama 89156f3fcc Simplify 2023-01-02 09:53:15 +08:00
Rui Ueyama d0abdf3bbe Refactor 2023-01-02 05:43:16 +08:00
Rui Ueyama 9615b8b962 Do not bother to clear existing bits when applying relocations
We were inconsistent as to when to clear existing values when applying
relocations. mold was broken from the point of view that bits must be
cleared before applying relcoations. But at the same time, we had code
to clear bits for some types of relocations.

This patch removes all bit clear code for the sake of simplicity.
2023-01-02 05:17:15 +08:00
Rui Ueyama 608b328cbf Reduce symbol size 2023-01-01 12:12:34 +08:00
Rui Ueyama cbc71ac363 Clear existing values when applying relocations 2023-01-01 12:12:22 +08:00
Rui Ueyama df9e997cc3 Refactor 2023-01-01 07:40:55 +08:00
Rui Ueyama abe7943c06 Refactor 2023-01-01 07:11:23 +08:00
Rui Ueyama 764f802180 Fix CI 2022-12-31 20:28:01 +08:00
Rui Ueyama 651adad5f2 Support 32-bit PowerPC ABI 2022-12-31 17:56:37 +08:00
Rui Ueyama 34bfbc0983 Rename inttypes.h integers.h
`inttypes.h` unintentionally collided with the system's `inttypes.h`.

Fixes https://github.com/rui314/mold/issues/936
2022-12-30 21:46:05 +08:00
Rui Ueyama 9c355b7765 Treat R_ARM_PLT32 as a synonym for R_ARM_CALL
According to the ARM psABI document, R_ARM_PLT32 is deprecated.
It looks like old compilers emit it for function calls.

Fixes https://github.com/rui314/mold/issues/934
2022-12-30 18:14:49 +08:00
Rui Ueyama ccd47db916 Set a correct value to __iplt_start for statically-linked binaries
Fixes https://github.com/rui314/mold/issues/930
2022-12-30 12:26:19 +08:00
Rui Ueyama ad30db1102 Refactor 2022-12-30 12:05:07 +08:00
Rui Ueyama b3db6c9976 Revert "Eliminate uses of <bit>"
This reverts commit 33af22848f.

https://github.com/rui314/mold/issues/936
2022-12-30 11:09:50 +08:00
Rui Ueyama 02ca6cc643 Do not mention --ld-path because -fuse-ld works both for clang and gcc 2022-12-30 10:53:10 +08:00
Rui Ueyama d5a1c7a1b3 Merge pull request #938 from arbipher/patch-2
Add explanation for `-fuse-ld-mold` in README
2022-12-30 11:44:44 +09:00
Weng Shiwei 翁士伟 13a4cf9994 Update README.md 2022-12-29 21:40:07 -05:00
Weng Shiwei 翁士伟 e63bf01704 Update README.md 2022-12-29 21:33:30 -05:00
Rui Ueyama f23c1c9b69 Fix CI 2022-12-30 10:14:24 +08:00
Weng Shiwei 翁士伟 e454d54a8a Update README.md 2022-12-29 20:53:44 -05:00
Rui Ueyama 33af22848f Eliminate uses of <bit>
Some old C++ compilers don't provide that header.

Fixes https://github.com/rui314/mold/issues/936
2022-12-30 09:16:38 +08:00
Rui Ueyama 610d90fa69 Simplify 2022-12-29 17:52:47 +08:00
Rui Ueyama 9c62c55a2c Rename a file 2022-12-29 17:39:39 +08:00
Rui Ueyama 34ca952a9b Refactor 2022-12-29 16:59:08 +08:00
Rui Ueyama 487ef64336 Remove dead code 2022-12-29 16:46:36 +08:00
Rui Ueyama f33968c782 Refactor 2022-12-29 16:20:40 +08:00
Rui Ueyama 7c03f5e4c0 Refactor 2022-12-29 15:49:12 +08:00
Rui Ueyama 6ff6084ab8 Refactor 2022-12-29 11:35:53 +08:00
Rui Ueyama 326e2c6ba1 Copy st_other from input symbols to output symbols 2022-12-29 11:35:53 +08:00
Rui Ueyama efe117d946 Merge pull request #933 from marxin/support-fno-use-linker-plugin
support correctly -fno-use-linker-plugin
2022-12-29 12:35:38 +09:00
Rui Ueyama b39ee6a985 Refactor 2022-12-29 09:30:59 +08:00
Martin Liska 5f99006de3 support correctly -fno-use-linker-plugin
Right now, mold linker does not work with -fno-use-linker-plugin
and thus use assembly for GCC FAT LTO objects. I noticed that
when running GCC test-suite with mold.

Fixes: 804b843983

Signed-off-by: Martin Liska <[email protected]>
2022-12-28 19:46:08 +01:00
Rui Ueyama 033d5f3406 Refactor 2022-12-28 22:35:26 +08:00
Rui Ueyama d96c9b8236 Do not set an undefined value to dynrel 2022-12-28 22:23:50 +08:00
Rui Ueyama a45f97b474 Refactor 2022-12-28 17:53:58 +08:00
Rui Ueyama 10a1ca0d8e Refactor 2022-12-28 17:44:57 +08:00
Rui Ueyama 4362727cc8 Refactor 2022-12-28 17:25:25 +08:00
Rui Ueyama 40ddfa533b Refactor 2022-12-28 15:11:05 +08:00
Rui Ueyama 447bb8b036 Update a comment 2022-12-28 14:05:39 +08:00
Rui Ueyama 6231510794 Support DEC Alpha 2022-12-28 13:57:00 +08:00
Rui Ueyama 352c086047 Refactor 2022-12-28 12:52:41 +08:00
Rui Ueyama fb1ca49d9b Update comments 2022-12-27 22:36:45 +08:00
Rui Ueyama 1b0979c795 Refactor 2022-12-27 21:26:57 +08:00
Rui Ueyama 5a38f70a37 Refactor 2022-12-27 18:16:31 +08:00
Rui Ueyama 4da942723e Refactor 2022-12-27 14:09:30 +08:00
Rui Ueyama e26ea4ba05 Refactor 2022-12-27 12:08:52 +08:00
Rui Ueyama 8cfa64944e Update comments 2022-12-27 11:25:06 +08:00
Rui Ueyama 21855a194c Attempt to fix CI 2022-12-27 10:46:29 +08:00
Rui Ueyama 3411e17d8b [ELF] Support SH-4 ISA 2022-12-27 10:34:20 +08:00
Rui Ueyama e1f587eafb Merge pull request #926 from ZhongRuoyu/test-permission
`warn-symbol-type.sh`: fix file permission
2022-12-26 19:16:55 +09:00
Ruoyu Zhong 215f351dcd warn-symbol-type.sh: fix file permission
Also, end this file with a newline.

Signed-off-by: Ruoyu Zhong <[email protected]>
2022-12-26 16:21:41 +08:00
Rui Ueyama a49a201695 Bump mold version to 1.8.0 2022-12-25 19:55:07 +08:00
Rui Ueyama e7d80bcf33 Remove a redundant if condition 2022-12-25 18:12:14 +08:00
Rui Ueyama feaf2632c5 Fix typo in command line parameter
There's no such option as `-z nodefs` in any linker. The correct option
ame is `-z undefs`.
2022-12-25 16:43:23 +08:00
Rui Ueyama b510588677 Support -z nopack-relative-relocs 2022-12-25 16:39:16 +08:00
Rui Ueyama aa51aea245 Merge pull request #925 from ishitatsuyuki/type-warn
[ELF] Warn on symbol type mismatches.
2022-12-25 16:22:32 +09:00
Tatsuyuki Ishi b70211ec08 [ELF] Warn on symbol type mismatches.
Linking symbols with differing types will almost always lead to a crash; warn to
make it easier for the user to figure out the cause.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-12-25 14:18:41 +08:00
Tatsuyuki Ishi 30f79a0d62 [ELF] Add formatter for st_type.
Will be used to print symbol type mismatch warnings.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-12-25 14:18:41 +08:00
Rui Ueyama a3a98ac5f5 Fix build failure on some targets
Fixes https://github.com/rui314/mold/issues/924
2022-12-25 11:47:31 +08:00
Rui Ueyama ed235f3db6 Add -z [no]dynamic-undefined-weak 2022-12-25 11:46:13 +08:00
Rui Ueyama ad79674ec5 Refactor 2022-12-25 08:31:33 +08:00
Rui Ueyama 2ab4175ac1 Delete an unused variable 2022-12-25 08:31:33 +08:00
Rui Ueyama 408bdc1e87 Refactor 2022-12-24 14:40:10 +08:00
Rui Ueyama 86e6fa17a5 Refactor 2022-12-24 12:30:05 +08:00
Rui Ueyama 57c5b9ea27 Refactor 2022-12-23 20:40:37 +08:00
Rui Ueyama 23fff53e94 Do not crash if there's a SHF_MERGE section with entsize == 0
It looks like the OCaml compiler creates such broken sections.
2022-12-23 20:40:37 +08:00
Rui Ueyama c829aed2df Merge pull request #923 from marxin/badges
Add badges to README.md
2022-12-23 17:27:44 +09:00
Martin Liska e53df1deda Add badges to README.md
Include GitHub CI and openSUSE OBS badges.

Fixes: #922

Signed-off-by: Martin Liska <[email protected]>
2022-12-23 09:23:56 +01:00
Rui Ueyama 1283061d2b Remove CI logging 2022-12-23 14:38:42 +08:00
Rui Ueyama 5e976dbf97 Add logging to CI 2022-12-23 11:36:45 +08:00
Rui Ueyama a86d94cee7 [ELF] Relax sequencial consistency memory stores 2022-12-23 11:22:48 +08:00
Rui Ueyama 365779fbe4 Refactor 2022-12-23 10:54:47 +08:00
Rui Ueyama 0c456efebb [ELF] Fix the --help message
Pointed out by justanotheranonymoususer

https://github.com/rui314/mold/commit/e2d7353213004f5eac0eeda372dac7cbbdb1cb28
2022-12-21 16:12:14 +08:00
Rui Ueyama e2d7353213 [ELF] Support --[no-]undefined-version
Fixes https://github.com/rui314/mold/issues/921
2022-12-21 12:50:45 +08:00
Rui Ueyama 864f9a0490 Deduplicate the help message
Fixes https://github.com/rui314/mold/issues/920
2022-12-20 16:12:27 +08:00
Rui Ueyama 262bf67b20 Make OutputFile::close faster 2022-12-17 12:13:00 +08:00
Rui Ueyama bffc887dae Merge pull request #918 from marxin/fix-typo 2022-12-16 05:59:28 -08:00
Martin Liska 262ef21f32 fix copy&pasted typo in elf/lto-unix.cc
Signed-off-by: Martin Liska <[email protected]>
2022-12-16 13:57:00 +01:00
Rui Ueyama 07d89116a8 [ELF] Make --wrap work with LTO
Fixes https://github.com/rui314/mold/issues/916
2022-12-16 13:06:00 +08:00
Rui Ueyama cc3e5fd1a8 Refactor 2022-12-16 10:38:01 +08:00
Rui Ueyama b2858d2680 [ELF] Allow to initialize a global variable with an ifunc function pointer
This is a tricky case, but if you initialize a global variable with a
pointer to an ifunc function like this:

  int bar() __attribute__((ifunc("resolve_bar")));
  void *bar2 = bar;

then we need to emit two dynamic relocations, one for `bar()` and the other
for `bar2`. This results in calling `resolve_bar` twice at runtime, but
there's no other way to initialize the function and the variable correctly.

Fixes https://github.com/rui314/mold/issues/915
2022-12-15 16:46:44 +08:00
Rui Ueyama 293a4ca425 Refactor 2022-12-15 16:46:24 +08:00
Rui Ueyama 22c9ec8cb6 [ELF] Ignore -z start-stop-visibility=hidden
https://github.com/rui314/mold/issues/826
2022-12-14 17:20:18 +08:00
Rui Ueyama a260630f48 Merge pull request #913 from ZhongRuoyu/openssl-libdir 2022-12-12 20:12:19 -08:00
Rui Ueyama 86d37b4720 Merge pull request #911 from ZhongRuoyu/ld-symlink 2022-12-12 18:19:24 -08:00
Rui Ueyama 099663aaae Merge pull request #912 from marxin/ignore-max-cache-size 2022-12-12 18:18:20 -08:00
Ruoyu Zhong 678ef917cc Dockerfile: fix OpenSSL libdir
In the current version of Docker image, OpenSSL libraries are installed
to `/usr/local/lib64`. It is not present in the default dynamic linker
search path, and thus results in the following error when libcrypto is
not statically-linked:

  mold: error while loading shared libraries: libcrypto.so.3: cannot
  open shared object file: No such file or directory

Fix that by overriding `libdir`, as suggested in
https://github.com/openssl/openssl/blob/master/INSTALL.md#libdir. Also,
run `ldconfig` to update dynamic linker cache.

Signed-off-by: Ruoyu Zhong <[email protected]>
2022-12-12 23:40:02 +08:00
Martin Liska d05e83e40b ignore BFD linker argument --max-cache-size=size
Signed-off-by: Martin Liska <[email protected]>
2022-12-12 15:10:14 +01:00
Ruoyu Zhong a18fe8bccf Install ld64.sold symlink
Signed-off-by: Ruoyu Zhong <[email protected]>
2022-12-12 21:27:25 +08:00
Ruoyu Zhong 56c56cc450 Fix ld.sold symlink installation
Fixes #910.

Signed-off-by: Ruoyu Zhong <[email protected]>
2022-12-12 21:25:32 +08:00
Rui Ueyama 998c7afb67 Do not run tests on macOS 2022-12-12 17:33:23 +08:00
Rui Ueyama a90e7ac782 Remove mold/macOS
mold/macOS will be available at https://github.com/bluewhalesystems/sold
as a source-available commercial product.
2022-12-12 17:05:09 +08:00
Rui Ueyama bd584ac05e Automatically detect if mold is sold 2022-12-12 16:00:59 +08:00
Rui Ueyama 30aecda799 Change the version string for commercial version of mold
Since many programs recognizes `^mold` as a check if a linker is mold,
we want to always print out "mold" as a product name.
2022-12-12 15:19:59 +08:00
Rui Ueyama 05ff76f361 [ELF][ARM32] Support R_ARM_GOTOFF32
Fixes https://github.com/rui314/mold/issues/909
2022-12-12 11:51:08 +08:00
Rui Ueyama 83d8189c51 Refactor 2022-12-11 18:04:16 +08:00
Rui Ueyama 7c56dddc8c [ELF] Cache DJB hash
We used to compute DJB hash twice.
2022-12-11 16:14:16 +08:00
Rui Ueyama ba8a4d9b98 Refactor 2022-12-11 13:44:29 +08:00
Rui Ueyama afe01a1367 Improve a comment 2022-12-10 18:13:47 +08:00
Rui Ueyama bcc74d68ee Simplify 2022-12-10 17:27:00 +08:00
Rui Ueyama a6c4530e43 Fix -Wunused-function 2022-12-10 16:03:25 +08:00
Rui Ueyama f83581880d Upgrade to mimalloc 2.0.7 2022-12-10 15:41:48 +08:00
Rui Ueyama 0d4193f564 Optimize our concurrent map 2022-12-10 14:24:21 +08:00
Rui Ueyama 88b4c1eb81 [ELF] Optimize scan_relocations 2022-12-10 14:06:08 +08:00
Rui Ueyama cd4fb9f26e Update man page
`-preload` has been removed.

https://github.com/rui314/mold/issues/414
2022-12-10 10:31:36 +08:00
Rui Ueyama 3e23192256 [Mach-O] Fix crash bug 2022-12-09 15:47:29 +08:00
Rui Ueyama 589cb55516 Do not create __objc_stubs etc. sections if they already exist 2022-12-09 15:30:24 +08:00
Rui Ueyama b14727149b [ELF] Allow a section symbol as a comdat group name
A symbol with `STT_SECTION` doesn't have name (i.e. its `st_name` is zero.)
If such symbol is used as a comdat group name, we need to use a section name
instead of a symbol name as a group name.
2022-12-09 13:53:26 +08:00
Rui Ueyama df8e2d859c Refactor 2022-12-09 13:04:21 +08:00
Rui Ueyama faa71c6f1c Merge pull request #908 from marxin/i386-plt-use-int3
[ELF][i386] Use int3 as padding in .plt and .plt.got entires
2022-12-08 19:38:47 -08:00
Martin Liska 3486f69fcf [ELF][i386] Use int3 as padding in .plt and .plt.got entires
Similarly to x86_64, use int3 (0xcc) as padding at the end of plt
and pltgot entries in order to increase security.

Signed-off-by: Martin Liska <[email protected]>
2022-12-08 15:01:47 +01:00
Rui Ueyama 0f36a40a44 [Mach-O] Create __objc_{methname,selrefs,stubs} sections
Recent versions of Xcode started creating `_objc_msgSend$foo` symbols,
and we need to synthesize the symbols and place them into `__objc_stubs`
section.
2022-12-08 17:33:37 +08:00
Rui Ueyama 73f32940ab [ELF] Parallelize HashSection::copy_buf and GnuHashSection::copy_buf
If there are lots of exported symbols, their performances matter.
2022-12-08 15:13:44 +08:00
Rui Ueyama 3d255b2cdf Merge pull request #907 from ishitatsuyuki/defsym-lto
[ELF] Keep a reference to the defsym target.
2022-12-07 22:02:55 -08:00
Tatsuyuki Ishi 27b543a725 [ELF] Keep a reference to the defsym target.
Add an undefined symbol to keep a reference to the defsym target. This prevents
elimination by e.g. LTO or gc-sections. A test is added for the case of LTO
dead-code elimination.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-12-08 12:05:09 +08:00
Tatsuyuki Ishi 79483332b7 [ELF] Only assign "owned" synthetic symbols to output section.
In preparation for introducing undefined symbols that references external object
files (and should not get the output section overridden).

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-12-08 11:57:42 +08:00
Rui Ueyama b09be697b5 Revert "Link against libc++ instead of libstdc++ if -DMOLD_MOSTLY_STATIC"
This reverts commit 94122f4ffd.

Fixes https://github.com/rui314/mold/issues/905
2022-12-07 14:39:20 +08:00
Rui Ueyama b7439b5efc [ELF] Do not remove SHF_LINK_ORDER bit
SHF_LINK_ORDER bit doesn't matter in an executable, but it looks like
the `strip` command in binutils 2.35 or earlier on ARM32 complains about
`.ARM.exidx` if we do not preserve that bit.

Fixes https://github.com/rui314/mold/issues/889
2022-12-06 13:52:38 +08:00
Rui Ueyama 8c87f16592 [ELF] Make --dynamic-list to search in -L locations
Fixes https://github.com/rui314/mold/issues/904
2022-12-06 13:35:16 +08:00
Rui Ueyama e16328e790 Refactor 2022-12-03 16:03:00 +08:00
Rui Ueyama bb5d96be6e Allow negative values for R_AARCH64_TLSLE_MOVW_TPREL_G[012] relocs 2022-12-03 11:44:52 +08:00
Rui Ueyama 3c1a0550da Search version script from library search paths
Fixes https://github.com/rui314/mold/issues/822
2022-12-03 10:34:37 +08:00
Rui Ueyama dd90ade29d Fix CI 2022-12-02 16:25:19 +08:00
Rui Ueyama 5866c9e95a [ELF] Do not create copy relocations if dynamic relocations suffice
We used to create copy relocations if we are creating a non-PIC executable
and there's a direct reference to imported data. That works for most
programs but not for GHC (Glasgow Haskell Compiler). GHC places function
machine code and its supplimental data next to each other in the .text
section. If we create a copy relocation for such function, the resulting
executable won't work because (1) copy-relocated data is not executable
and (2) it may separate the function code from its supplemental data.

In this patch, I made a change so that mold creates dynamic relocations
instead of copy relocations if possible.
2022-12-02 16:08:34 +08:00
Rui Ueyama 372f34300e Fix CI 2022-12-02 16:08:23 +08:00
Rui Ueyama 6cb5b53d5d [ELF] Handle escape character in response file
GHC uses backslash escapes instead of double-quoted strings in response files
2022-12-02 15:46:50 +08:00
Rui Ueyama 1d4b2071ca [ELF] Implement R_AARCH64_TLSLE_MOVW_TPREL relocations
Fixes https://github.com/rui314/mold/issues/901
2022-12-02 12:23:31 +08:00
Rui Ueyama f0774d4e24 Merge pull request #893 from ishitatsuyuki/tls
[ELF] TLS alignment fix
2022-11-30 01:16:06 -08:00
Rui Ueyama f007127ad3 Merge pull request #899 from marxin/fix-typos-v2
fix typos in comments and help string
2022-11-30 01:12:27 -08:00
Rui Ueyama 38c1211dba [ELF] Optimize scan_relocations 2022-11-30 17:02:55 +08:00
Tatsuyuki Ishi bd46edf3f0 [ELF] Align the first TLS section with largest required TLS alignment.
TLS chunks alignments are special: in addition to having their virtual
addresses aligned, they also have to be aligned when the region of
tls_begin is copied to a new thread's storage area. In other words, their
offset against tls_begin also has to be aligned.

A good way to achieve this is to take the largest alignment requirement of
all TLS sections and make tls_begin also aligned to that.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-11-30 16:12:49 +08:00
Rui Ueyama 48b2c0f8a3 Make test less verbose 2022-11-29 14:36:57 +08:00
Rui Ueyama 8975fc2ed2 Allow a double-quoted filename 2022-11-29 14:34:31 +08:00
Rui Ueyama 594beb67a2 Merge pull request #900 from marxin/gcc-fat-lto-objects
support -ffat-lto-objects for GCC compiler
2022-11-28 17:53:01 -08:00
Martin Liska 804b843983 support -ffat-lto-objects for GCC compiler
FAT LTO objects are objects that contain both native assembly
and LTO bytecode. Identify such files as GCC_LTO_OBJ.

Signed-off-by: Martin Liska <[email protected]>
2022-11-28 17:00:13 +01:00
Martin Liska 032a44626f fix typos in comments and help string
Signed-off-by: Martin Liska <[email protected]>
2022-11-28 15:24:27 +01:00
Rui Ueyama d2cfffc24d Add a test 2022-11-28 17:39:13 +08:00
Rui Ueyama c2a0ae1c96 Add --relocatable-merge-sections 2022-11-28 17:35:06 +08:00
Rui Ueyama cf8cce6d17 -r: Infer machine type even if all input files are given via linker script 2022-11-28 17:35:06 +08:00
Rui Ueyama 0420a527c0 Add a workaround for a bad GHC output 2022-11-28 14:22:07 +08:00
Rui Ueyama 54e45746cc Merge pull request #896 from hack3ric/main 2022-11-27 04:42:09 -08:00
Eric Long c0c863ff8b Fix atomic checks
Signed-off-by: Eric Long <[email protected]>
2022-11-27 18:13:22 +08:00
Rui Ueyama e08efab1e7 Refactor 2022-11-27 12:39:47 +08:00
Rui Ueyama 41bc68e26d -r: Set SHF_INFO_LINK to relocation sections 2022-11-27 12:31:46 +08:00
Rui Ueyama 8f682da608 Refactor 2022-11-27 12:07:56 +08:00
Rui Ueyama 72ac3f200d Refactor 2022-11-27 12:04:48 +08:00
Rui Ueyama 32dcda5aa9 -r: fix relocation addends for section fragments 2022-11-27 12:04:48 +08:00
Rui Ueyama 26e3203e9a Merge pull request #895 from justanotheranonymoususer/patch-1
Fix typos in execstack.md
2022-11-26 04:26:16 -08:00
Rui Ueyama 1969b52569 Refactor 2022-11-26 20:10:26 +08:00
justanotheranonymoususer 53a84a182c Fix typos in execstack.md 2022-11-26 13:48:17 +02:00
Rui Ueyama c1b57d9977 -r: Do not strip .note.GNU-stack 2022-11-26 16:40:16 +08:00
Rui Ueyama 556a5cabf9 -r: Do not emit .eh_frame if there's no input .eh_frame 2022-11-26 16:33:32 +08:00
Rui Ueyama 3a4166a066 Avoid creating two sections with the same name 2022-11-26 13:43:23 +08:00
Rui Ueyama 85c3467147 Optimize 2022-11-26 12:54:22 +08:00
Rui Ueyama 7f124d4271 Optimize 2022-11-26 12:23:52 +08:00
Rui Ueyama 8d2ddf7038 Optimize 2022-11-26 12:15:34 +08:00
Rui Ueyama 3d0bd4dacf Silence TSAN error 2022-11-26 12:03:12 +08:00
Rui Ueyama d5bbe347a1 Accept -perf with -r 2022-11-26 11:29:39 +08:00
Rui Ueyama f9c721f9a9 Handle an output file with more than 65535 sections
Executables and shared libraries usually don't have too many sections,
but relocatable object files may. So we need this for --relocatable.
2022-11-25 19:38:09 +08:00
Rui Ueyama fc16eb4e34 Remove dead code 2022-11-25 16:45:07 +08:00
Rui Ueyama 683583a8c4 Fix CI 2022-11-25 15:47:39 +08:00
Rui Ueyama 6524389621 Generalize a test 2022-11-25 15:30:19 +08:00
Rui Ueyama 75e059af5b Optimize create_output_sections
It turned out that tbb::concurrent_hash_map is much slower than
std::unordered_map with a reader-writer lock for this function.
2022-11-25 15:17:47 +08:00
Rui Ueyama ecd61a4fed [ELF] Create output sections lazily
Previously, we create output sections when input sections are instantiated.
That is not ideal because input sections may be removed, and if that's the
case, any work that has done for the removed section is wasted.
2022-11-25 13:46:38 +08:00
Rui Ueyama 8614fbbaff Refactor 2022-11-25 11:06:18 +08:00
Rui Ueyama e1445e7a84 Merge pull request #892 from marxin/fix-typos-in-man 2022-11-24 17:22:04 -08:00
Martin Liska be01de4b45 man: fixes a couple of typos
Signed-off-by: Martin Liska <[email protected]>
2022-11-24 15:01:40 +01:00
Rui Ueyama 968a8cf0be Merge pull request #891 from marxin/comment-note.gnu.property
Document unsupported .note.gnu.property properties
2022-11-24 05:24:25 -08:00
Martin Liska e5e3925d5b Document unsupported .note.gnu.property properties
Mention 2 properties that are not suported right now.

Signed-off-by: Martin Liska <[email protected]>
2022-11-24 13:54:13 +01:00
Rui Ueyama 57b09ccfb7 [ELF] Merge .note.gnu.property if --relocatable is given 2022-11-24 17:24:38 +08:00
Rui Ueyama 50d0cc6959 Refactor 2022-11-24 17:16:33 +08:00
Rui Ueyama f43c0fde26 Fix CI 2022-11-24 17:08:45 +08:00
Rui Ueyama 3c4dd61710 Make NotePropertySection::update_shdr idempotent 2022-11-24 16:58:47 +08:00
Rui Ueyama ed8580f86a Refactor 2022-11-24 16:49:39 +08:00
Rui Ueyama b2f44b07fc Refactor 2022-11-24 15:12:18 +08:00
Rui Ueyama 1ccf1f8ffb Relocatable output file shouldn't have an executable bit 2022-11-24 15:06:52 +08:00
Rui Ueyama 2e3e177a6d Refactor 2022-11-24 15:02:02 +08:00
Rui Ueyama 5e345b0f82 Fix CI 2022-11-24 14:36:37 +08:00
Rui Ueyama 6fd2c69926 Add comments 2022-11-24 14:24:50 +08:00
Rui Ueyama f8e7bace50 Fix CI 2022-11-24 14:00:49 +08:00
Rui Ueyama 46def3b49f 80 columns 2022-11-24 13:35:10 +08:00
Rui Ueyama c9a7ae733c [ELF] Re-implement --relocatable
This is an initial patch to reimplement --relocatable. Unlike the previous
implementation, the new one aims to be on par with GNU ld in terms of the
behavior. Previously, we didn't for example merge input sections at all.
Now we do it in the new implementation.

The previous implementation was slow. We also want to fix it in the new one.

The new --relocation feature is not complete yet; there are many rough edges.
But I think this patch is good enough to be submitted.

This work is funded by Mercury (https://mercury.com).
2022-11-24 12:24:57 +08:00
Rui Ueyama 9d437dfd6f Merge pull request #885 from marxin/fix-psabi-link
Add i386-psabi.pdf to arch-x86-64
2022-11-21 22:09:53 -08:00
Rui Ueyama 5d277c1b90 Merge pull request #887 from ZhongRuoyu/cmake-CMP0077
Work around CMake CMP0077 warning
2022-11-21 22:02:31 -08:00
Rui Ueyama a8b070bc56 Update README 2022-11-22 13:06:35 +08:00
Rui Ueyama 6eb6a93ced Merge pull request #886 from CraneDancingShape/pr_nim.md
Add README.md "If you are using Nim" & Fix "If you are using Rust" mi…
2022-11-21 21:05:28 -08:00
Zhong Ruoyu 89ebf2179c Work around CMake CMP0077 warning
As documented by CMake [^1], prior to CMake 3.13, entries set by
`option()` can override a non-cached old value. The `CMakeLists.txt` in
the bundled mimalloc specifies a minimum CMake version of 3.0, so that
old behaviour is expected. That means no matter whatever value of
`MI_BUILD_STATIC` we set in `mold_add_mimalloc` does not really take
effect (this can be seen by adding some debug messages). That didn't
trouble us because it's on by default anyway.

While the documented solution is to set `CMAKE_POLICY_DEFAULT_CMP0077`
to `NEW`, we could actually also work around this by making them cache
variables. This is fine and valid because their values are not meant to
be changed anyway. (And this workaround is already being used in
`mold_add_tbb`, so by doing this, we are also eliminating some
inconcistency.)

Fixes #874.

[^1]: See `cmake --help-policy CMP0077` or
https://cmake.org/cmake/help/latest/policy/CMP0077.html

Signed-off-by: Zhong Ruoyu <[email protected]>
2022-11-22 01:03:08 +08:00
CraneDancingShape 22635e3716 Add README.md "If you are using Nim" & Fix "If you are using Rust" miss-spell. 2022-11-21 23:30:28 +09:00
Martin Liska 2ae49688e8 Add i386-psabi.pdf to arch-x86-64
Some parts (like .note.gnu.property section format)
of the ABI are defined in i386 manual.
2022-11-21 15:18:52 +01:00
Rui Ueyama 988241975f Merge pull request #877 from sicherha/fix_span_out_of_bounds
Fix out-of-bounds error on aarch64 with `_GLIBCXX_ASSERTIONS` enabled…
2022-11-19 20:31:19 -08:00
Rui Ueyama f5fb6b4abb Merge pull request #880 from ZhongRuoyu/dockerfile-cleanup
Dockerfile: perform cleanup at the end
2022-11-19 18:57:01 -08:00
Rui Ueyama ada8dec8da Fix -Wdangling-reference
Fixes https://github.com/rui314/mold/issues/882
2022-11-20 10:55:29 +08:00
Rui Ueyama a18316a83a Merge pull request #881 from tzussman/patch-1
Update CMakeLists.txt to use mold 1.7.1
2022-11-19 18:54:39 -08:00
Tal Zussman 3f81358b54 Update CMakeLists.txt to use mold 1.7.1 2022-11-19 12:55:20 -05:00
Zhong Ruoyu ce3ac5d2f4 Dockerfile: perform cleanup at the end
As recommended in Docker's documentation [^1]:

> In addition, when you clean up the apt cache by removing
> `/var/lib/apt/lists` it reduces the image size, since the apt cache
> is not stored in a layer.

This reduces the image size by ~0.5GiB.

[^1]: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#apt-get

Signed-off-by: Zhong Ruoyu <[email protected]>
2022-11-20 01:29:16 +08:00
Christoph Erhardt a2c7ad822b Fix out-of-bounds error on aarch64 with _GLIBCXX_ASSERTIONS enabled (again)
The square-bracket operator of `std::span` has undefined behaviour for
out-of-bounds element accesses. Resorting to iterators yields defined
behaviour.

This issue (originally described in #298) had been fixed in the past by
commit 03ba8f9325, but it has since
resurfaced with commit 193c245781.

Signed-off-by: Christoph Erhardt <[email protected]>
2022-11-19 14:01:52 +01:00
Rui Ueyama 72fffee54f Merge pull request #875 from Paulo-21/patch-1
Update "compile mold" command to use mold 1.7.1
2022-11-19 03:29:34 -08:00
Pmimo c77c41eaf8 Update compile mold command to 1.7.1 2022-11-19 11:27:50 +01:00
Rui Ueyama d1a0e2c2c5 Refactor 2022-11-19 17:57:12 +08:00
Rui Ueyama bbb03c9096 Update README 2022-11-19 12:27:49 +08:00
Rui Ueyama 0b9f4b0e45 Update README 2022-11-19 12:04:02 +08:00
Rui Ueyama f689d25798 Update sponsor list 2022-11-19 11:34:06 +08:00
Rui Ueyama dae1edc578 [ELF] Remove duplicate rpaths
Fixes https://github.com/rui314/mold/issues/873
2022-11-19 11:08:07 +08:00
Rui Ueyama df00fe8a58 Remove "commercial/free edition" from the version message
Commercial version will get a different brand name ("sold") and
maintained in a separate repository than this repo.
2022-11-18 17:21:46 +08:00
Rui Ueyama 428218ce30 Merge pull request #867 from ishitatsuyuki/property
[ELF] Add support for more .gnu.note.property variants.
2022-11-17 23:04:26 -08:00
Rui Ueyama 20eaa1d19c Revert "[ELF] Do not include non-memory-mapped sections into build-id computation"
This reverts commit e228abfd5a because
it makes the linker to produce different executables with the same
build-id.

Fixes https://github.com/rui314/mold/issues/872
2022-11-18 14:45:16 +08:00
Tatsuyuki Ishi d30d743cb0 [ELF] Add support for more .gnu.note.property variants.
This makes .gnu.note.property handling generic instead of hardcoded against the
GNU_PROPERTY_X86_FEATURE_1_AND value.
The behavior is based on specification inside GNU gold header comments;
unfortunately a formal document does not exist yet and the comments seem to be
the best reference that can be found.

The support for the actual properties in wild seems scarce; neither gcc nor
clang emits the correct property even when passed -march=x86-64-v3 and using
__builtin_popcnt, for example. Therefore, this does not include a test yet for
the new properties.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-11-18 11:18:13 +09:00
Tatsuyuki Ishi 14a6e2012d [ELF] Update .note.gnu.property constants.
Includes value required to handle the "ABI needed" and "ABI used" tags, but
doesn't include the feature values yet (because we don't have a use for it).

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-11-18 10:38:59 +09:00
Tatsuyuki Ishi 94fb470e29 [ELF] Workaround binutils injecting own .note.gnu.property section.
binutils has learned to inject some "x86 ISA needed/used" properties.
Try to disable their emission with -mx86-used-note=no if supported, since
now that mold is gaining support for these properties, they will cause an
mismatch with the expectations.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-11-18 10:38:59 +09:00
Rui Ueyama 968e970adb Merge pull request #868 from ZhongRuoyu/fix-empty-prefix
Fix symlinks when `CMAKE_INSTALL_PREFIX` is `/` or empty
2022-11-17 16:50:41 -08:00
Zhong Ruoyu 2d0a38436c Tweak symlink installation
This removes the extra slash in the symlink
installation output. It works because both
NEW_ABS and NEW_DIR are absolute paths, and
therefore always begin with a slash.

Signed-off-by: Zhong Ruoyu <[email protected]>
2022-11-18 00:42:00 +08:00
Zhong Ruoyu 9513f63a29 Fix symlinks when CMAKE_INSTALL_PREFIX is / or empty
As suggested by https://github.com/rui314/mold/pull/846#issuecomment-1318000326,
if `CMAKE_INSTALL_PREFIX` is set to `/` or empty,
then `mold_install_relative_symlink` would see an
empty `CMAKE_INSTALL_PREFIX` and fail. Appending
an additional slash takes care of that.

See #868.

Signed-off-by: Zhong Ruoyu <[email protected]>
2022-11-18 00:39:56 +08:00
Rui Ueyama 8b373d38ce Emit REL-type relocations for --emit-relocs no i386 and ARM32
Previously, we always emit RELA-type relocations for --emit-relocs.
Now, we emit relocation tables in the target's native relocation format.
2022-11-16 16:39:19 +08:00
Rui Ueyama 456d34bde3 Fix .eh_frame relocations we create for --emit-relocs 2022-11-16 14:22:51 +08:00
Rui Ueyama 622c2d479c [ELF] Make -emit-relocs to create a .rela.eh_frame section 2022-11-16 13:56:34 +08:00
Rui Ueyama d835d016e0 [ELF] Preserve SHF_MERGE and SHF_STRING bits
Even though section flags don't matter at runtime, we want to preserve
these flags for `-r`.
2022-11-16 11:53:39 +08:00
Rui Ueyama 700a475597 Refactor 2022-11-16 11:45:09 +08:00
Rui Ueyama c2a34cc1e3 Refactor 2022-11-15 15:36:15 +08:00
Rui Ueyama 1f67ccfa20 Show license information in the --help message 2022-11-13 20:25:14 +08:00
Rui Ueyama 2b7b45c8d1 Automatically download the latest repo files 2022-11-13 19:17:16 +08:00
Rui Ueyama c9803c8984 Merge pull request #859 from ZhongRuoyu/fix-test-permission
`test/elf/section-order.sh`: fix file permission
2022-11-13 01:24:44 -08:00
Zhong Ruoyu c55931dae5 test/elf/section-order.sh: fix file permission
Signed-off-by: Zhong Ruoyu <[email protected]>
2022-11-13 16:52:59 +08:00
Rui Ueyama 94122f4ffd Link against libc++ instead of libstdc++ if -DMOLD_MOSTLY_STATIC 2022-11-13 16:31:00 +08:00
Rui Ueyama 22f3b7ed24 Bump mold version to 1.7.0 2022-11-13 08:14:59 +08:00
Rui Ueyama a67e9f54f8 Attempt to unbreak CI 2022-11-12 13:51:48 +08:00
Rui Ueyama 63933a9221 Retry if pthread_create fails with spurious error
https://github.com/oneapi-src/oneTBB/commit/137c1a88b690acf3525e0f279720ac489ce66481
is not included in 2021.7.0, so we still need to apply it separately.
2022-11-10 17:54:25 +08:00
Rui Ueyama e25802f84f Upgrade vendored OneTBB to version 2021.7.0
Fixes https://github.com/rui314/mold/issues/666
2022-11-10 17:42:51 +08:00
Rui Ueyama 73a467a3c9 Simplify 2022-11-10 14:16:55 +08:00
Rui Ueyama 91378b9c2f Simplify 2022-11-10 14:05:34 +08:00
Rui Ueyama 7f2a2c4233 Merge pull request #854 from ZhongRuoyu/git-packed-refs
Allow `update-git-hash.cmake` to get packed refs
2022-11-09 04:49:26 -08:00
Zhong Ruoyu ddd5264abd Allow update-git-hash.cmake to get packed refs
`git pack-refs` (often called by `git gc`) may
move refs from `.git/refs` to
`.git/packed-refs`. If that is the case, a lookup
in `.git/refs` will fail.

Signed-off-by: Zhong Ruoyu <[email protected]>
2022-11-09 19:07:30 +08:00
Rui Ueyama 5797a59ab9 Merge pull request #853 from ishitatsuyuki/cpp-version-precedence
[ELF] Fix precedence with C++ version script rules.
2022-11-09 00:52:50 -08:00
Tatsuyuki Ishi 9875150677 [ELF] Fix precedence with C++ version script rules.
Earlier entries in a version scripts always get the precedence. Don't let a
non-C++ symbol rule override a preceding C++ symbol rule.

MultiGlob is modified to return the necessary rule index information to the
caller. Since the rule index might not always be contiguous within a
MultiGlob instance (e.g. interleaving ordinary/C++ rules), the meaning of
MultiGlob's `val` is changed so that the minimum `val` itself is returned,
instead of the `val` with minimum index (the earliest added one).

MultiGlob is also used for the macOS backend, but since it does not care
about order yet the code is left as-is.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-11-09 14:56:06 +09:00
Rui Ueyama c9ff2a21c5 Fix -Wdeprecated-declarations 2022-11-07 15:13:17 +08:00
Rui Ueyama bd555b33ab Do not run tests if ARM32
I don't know why, but ctests fail only on ARM32 on Docker.
2022-11-06 15:55:40 +08:00
Rui Ueyama 51427cd7d2 Do not use mimalloc on 32-bit targets 2022-11-06 15:55:23 +08:00
Rui Ueyama 0e0bd8a4f0 80 columns 2022-11-06 14:40:20 +08:00
Rui Ueyama a8321acb88 Do not try to run executables created with --section-order
We can create peculiar executables with --section-order, and some ELF
loaders don't like some of them. Since the flag is intended to be used
for embedded/kernel programming, we don't need to verify that the
executables work on regular Linux macines.

Fixes https://github.com/rui314/mold/issues/838
2022-11-06 13:05:56 +08:00
Rui Ueyama 3127508040 Refactor 2022-11-05 21:06:52 +08:00
Rui Ueyama 4fc877779b Allow to use ccache 2022-11-05 12:41:21 +08:00
Rui Ueyama dae7dca0b9 80 columns 2022-11-04 17:00:41 +08:00
Rui Ueyama b43b31eae8 [ELF] Add --execute-only 2022-11-03 14:00:06 +08:00
Rui Ueyama bedcb1bf56 Merge pull request #848 from ZhongRuoyu/cmake-absolute-prefix
Fix symlinks for absolute `CMAKE_INSTALL_*`
2022-11-02 21:02:51 -07:00
Zhong Ruoyu 9fdb09ae0e Emit a message on each symlink installation
Signed-off-by: Zhong Ruoyu <[email protected]>
2022-11-02 19:19:00 +08:00
Zhong Ruoyu f1b50695e5 Fix symlinks for absolute CMAKE_INSTALL_*
Related: #738 #846

Signed-off-by: Zhong Ruoyu <[email protected]>
2022-11-02 19:18:59 +08:00
Rui Ueyama 9fcd6e965d Merge pull request #846 from ZhongRuoyu/cmake-install
Respect prefix set by `cmake --install`
2022-11-01 19:28:37 -07:00
Rui Ueyama 228b7464bf Use OpenSSL 3.0.7
We are using OpenSSL only to compute SHA-256 hashes, so we are unaffeted
by CVE-2022-3786 and CVE-2022-3602. But I think we still want to use the
newer version of OpenSSL to avoid unnecessary confusion.
2022-11-02 07:28:37 +08:00
Zhong Ruoyu ce87053c78 Respect prefix set by cmake --install
Currently, `CMAKE_INSTALL_FULL_{LIBEXEC,BIN,MAN}DIR`
are used for symlink creation. The problem with
that is it only works when the prefix is not
overridden by `cmake --install <build-dir> --prefix <prefix>`,
because their values are evaluated and hard-coded
into `cmake_install.cmake` during configuration
time, rather than installation time.

While it would be nice if we can get their
overridden values during installation, only
`CMAKE_INSTALL_PREFIX` reflects the overriden
value. (See "INSTALL A PROJECT", cmake(1)).

Therefore, the logic for symlink creation is
rewritten and extracted into a function named
`mold_install_symlink`. Now only `CMAKE_INSTALL_PREFIX`
is used during installation.

A new problem with this change is, if environment
variable `DESTDIR` is not set and `CMAKE_INSTALL_PREFIX`
is set to a relative path (which is perfectly
valid), a slash `/` would be incorrectly
prepended. To avoid that, and maintain
consistency with CMake's behaviour, the install
prefix is first turned into absolute path, stored
in `PREFIX_ABS`.

By the way, it seems okay to use the
`MAKE_DIRECTORY` and `CREATE_LINK` subcommands
under command `file`. So, it shouldn't be needed
to invoke a subprocess.

Signed-off-by: Zhong Ruoyu <[email protected]>
2022-11-02 02:42:16 +08:00
Rui Ueyama 554caeeb34 Refactor 2022-11-01 14:09:34 +08:00
Rui Ueyama 3bddfc5fd2 Refactor 2022-11-01 14:06:09 +08:00
Rui Ueyama 127758047c Merge pull request #845 from ishitatsuyuki/icf-opt1
[ELF] ICF optimizations and simplifications
2022-10-31 19:43:09 -07:00
Tatsuyuki Ishi 8449ead2a7 [ELF] icf: Add counter for eliminated sections.
We can already print them, but a counter is more handy when the
executable is large and dumping everything would be too much.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-11-01 11:10:36 +09:00
Tatsuyuki Ishi aab34e52cf [ELF] icf: Simplify sweeping logic
This isn't perf intensive at all but sweeping through the sections seems
to be the more obvious way compared to going through the symbol
indirections.

Also, reword the comments and timing name to better reflect what it's
doing.

FWIW, it's slightly (5ms) faster.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-11-01 11:10:36 +09:00
Tatsuyuki Ishi 8186b8a242 [ELF] icf: Use a bitmap to skip converged nodes faster.
A node converges if its descendants contains no cycles and its hash has reached
all its descendants. Previously we checked for convergence on each iteration by
comparing hashes, but this could be tracked more cheaply through a separate
bitset.

This improves cache efficiency and results in a ~50ms speed up for Chromium out
of 310ms for the ICF pass.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-11-01 11:10:36 +09:00
Rui Ueyama bd77bcdab4 Update comments 2022-11-01 09:18:52 +08:00
Rui Ueyama f82c0c0f83 Merge pull request #844 from LinuxUserGD/patch-1 2022-10-31 16:13:29 -07:00
Linux User 7607e3cbc2 Update CMakeLists.txt 2022-10-31 18:50:50 +01:00
Rui Ueyama 00acf3d2f6 Test whether we need -latomic or not
Based on https://github.com/MariaDB/server/commit/7de110af8c25697855ac4925b2c91f757b356655

Fixes https://github.com/rui314/mold/issues/843
2022-10-31 21:21:46 +08:00
Rui Ueyama 2942ba83d4 Merge pull request #841 from glaubitz/m68k-atomic-fix 2022-10-30 12:45:33 -07:00
John Paul Adrian Glaubitz 30bd1c26c8 [ELF][m68k] Linking against libatomic is required on m68k
Signed-off-by: John Paul Adrian Glaubitz <[email protected]>
2022-10-30 18:33:46 +01:00
Rui Ueyama ba640ceac6 [ELF] Add ppc64 to the supported emulations list 2022-10-30 17:07:51 +08:00
Rui Ueyama 097b872536 Add a link to the psABI document 2022-10-30 15:16:07 +08:00
Rui Ueyama ab5d04b670 Update README 2022-10-30 11:52:39 +08:00
Rui Ueyama 5fe60e3b6d [ELF][m68k] Add initial m68k support 2022-10-30 11:10:14 +08:00
Rui Ueyama e0ff005333 Attempt to fix build for SuSE
https://github.com/rui314/mold/issues/838
2022-10-29 19:38:12 +08:00
Rui Ueyama 98df612168 [ELF][x86-64] Allow PC32 after TLSGD/TLSLD
It looks like SuSE Leap's gcc11 produces such relocation.
2022-10-29 15:02:00 +08:00
Rui Ueyama 15979f9a10 [ELF] Change default for --section-order 2022-10-29 14:49:09 +08:00
Rui Ueyama 5218f73773 [ELF] Make it possible to define symbols with --section-order 2022-10-29 14:27:21 +08:00
Rui Ueyama 064ab23511 [ELF] Make it possible to specify an alignment with --section-order 2022-10-29 12:56:32 +08:00
Rui Ueyama 774e5c3bb6 [ELF] Set p_vaddr to non-loadable segments
It looks like the runtime doesn't care the non-loadable segments'
p_addr values, but `strip` does. `strip` corrupts an executable if
no value is set to p_vaddr.

Fixes https://github.com/rui314/mold/issues/839
2022-10-29 12:55:12 +08:00
Rui Ueyama 28598c7703 Merge pull request #837 from marxin/remove-unused-var 2022-10-28 05:11:10 -07:00
Martin Liska 91bcc51e60 fix -Wunused-variable warning
Fixes:
elf/passes.cc:1516:9: warning: unused variable 'type' [-Wunused-variable]
2022-10-28 13:49:46 +02:00
Rui Ueyama b5a4d98ef2 [ELF] Try to keep segment's paddr to be equal to its vaddr 2022-10-28 18:15:09 +08:00
Rui Ueyama b365d6ba1a [ELF] Define -z pack-relative-relocs as an alias for --pack-dyn-relocs=relr
This is for compatibility with GNU ld.
2022-10-28 16:25:33 +08:00
Rui Ueyama 2e9a4ccd10 [ELF] Do not handle .multiboot specially
Now that we have --section-order, we need to handle .multiboot in a
special manner.
2022-10-28 16:25:06 +08:00
Rui Ueyama 2fbdf1f982 Improve --section-order 2022-10-28 16:25:06 +08:00
Rui Ueyama 20173ad233 Merge pull request #835 from hwti/elf-linker-script-relative-sysroot
[ELF] Fix absolute paths handling in linker scripts
2022-10-27 18:37:25 -07:00
Rui Ueyama 602f423241 [ELF] Make --section-roder to recognize #ehdr and #phdr special names 2022-10-28 08:50:36 +08:00
Rui Ueyama 460b443736 [ELF] Add --section-order
This is an experimental flag.

Context:
https://docs.google.com/document/d/1bVRrKsB6iMGmay1odsmS44PyUzPXgQBH83gYGMY6LWM
2022-10-27 21:14:39 +08:00
Rui Ueyama 99b886f9c4 [ELF] Add --start-stop
This is an experimental flag and may be deleted in the future.

If --start-stop is given, mold creates __start_/__stop_ symbols for
sections whose names are not in C identifier style.
2022-10-27 16:14:20 +08:00
Rui Ueyama feb9cd5859 [ELF] Define __phys_{start,stop} symbols if --physical-image-base is given 2022-10-27 11:08:55 +08:00
Rui Ueyama c921959b81 [ELF] Add --physical-image-base
This is an experimental option and may be removed in the future.

Context:
https://docs.google.com/document/d/1bVRrKsB6iMGmay1odsmS44PyUzPXgQBH83gYGMY6LWM
2022-10-27 09:42:16 +08:00
Rui Ueyama 7816fd8249 [ELF] --section-align: validate alignment value 2022-10-27 09:00:54 +08:00
Rui Ueyama 1483ed9ac6 [ELF] Allow a decimal number as an argument for --section-align 2022-10-27 08:52:22 +08:00
Rui Ueyama 0cc131c065 Simplify 2022-10-27 08:44:39 +08:00
Rui Ueyama 2e11c57a6e Simplify 2022-10-27 08:36:51 +08:00
Rui Ueyama 67738238be [ELF] Add --section-align=<sectname>=<value> option
This is an experimental option and may be removed in the future.

Context:
https://docs.google.com/document/d/1bVRrKsB6iMGmay1odsmS44PyUzPXgQBH83gYGMY6LWM
2022-10-27 08:30:35 +08:00
Loïc Yhuel 467b08a782 [ELF] Fix absolute paths handling in linker scripts
With toolchains using a relative sysroot, like crosstool-ng, gcc/clang will call the linker
with something like "--sysroot=/path/bin/../machine/sysroot".
The is_in_sysroot detection wasn't working in this case.

Since to_abs_path() uses lexically_normal() for relative paths, it seems consistent to do
the same for absolute paths instead of modifying is_in_sysroot().
2022-10-26 19:57:28 +02:00
Rui Ueyama 903fff7701 Merge pull request #834 from ishitatsuyuki/dso-output-esym 2022-10-26 03:07:19 -07:00
Tatsuyuki Ishi 430818b366 [ELF] Use to_output_esym for symtab entries from DSOs.
DSO symtab handling was relatively simple, but it led to wrong entries when
copyrel was used.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-10-26 18:03:14 +08:00
Rui Ueyama dda70ce920 Merge pull request #832 from JamesWidman/opt-find_subsection
[Mach-O] Use binary search in find_subsection()
2022-10-25 23:38:14 -07:00
Rui Ueyama f7876a9f2a Merge pull request #833 from ishitatsuyuki/sec-reloc
[ELF] Fix section relocations getting bogus r_type.
2022-10-25 21:59:47 -07:00
Tatsuyuki Ishi 303cba23b5 [ELF] Fix section relocations getting bogus r_type.
They should inherit the original type instead of using a value from the wrong
enum (which showed up as R_X86_64_GOT32).

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-10-26 12:48:28 +08:00
James Widman 13eda8051a [Mach-O] Use binary search in find_subsection()
When using ld64.mold to link clang for Mach-O, most of the time was
spent in the first call to find_subsection() from
parse_compact_unwind(). Changing its linear search to a binary search
cut an 18-second link time down to about 3 seconds.

Signed-off-by: James Widman <[email protected]>
2022-10-25 18:07:25 -07:00
Rui Ueyama 0763dd5639 Improve error check 2022-10-25 16:52:13 +08:00
Rui Ueyama 95276c98fe 80 columns 2022-10-25 16:41:59 +08:00
Rui Ueyama 5a0ad2aa59 Show a warning on an invalid multiboot section 2022-10-25 16:41:14 +08:00
Rui Ueyama 4db7574e84 Place "multiboot" section right after the ELF header
This is an experimental feature to support Multiboot specification.

https://github.com/rui314/mold/issues/563
2022-10-25 10:01:12 +08:00
Rui Ueyama 997e53472d Merge pull request #819 from ishitatsuyuki/tsan-disable
Remove lock from clear_symbols and add a justification for disabling TSan
2022-10-24 03:10:51 -07:00
Tatsuyuki Ishi 3a308270bd Remove lock from clear_symbols and add a justification for disabling TSan
Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-10-24 17:40:06 +08:00
Rui Ueyama af6475caa7 Do not use hexdump command
hexdump is not universally available, while od seems to be defined by POSIX.
2022-10-24 16:19:01 +08:00
Rui Ueyama d0210b85b9 Run tests before install 2022-10-24 16:19:01 +08:00
Rui Ueyama 73cdbb320d Merge pull request #818 from ishitatsuyuki/opt
Some trivial optimizations
2022-10-24 00:37:47 -07:00
Tatsuyuki Ishi 6088d954f6 [ELF] Remove redundant lock in mark_live_objects.
There are no writes to `sym` apart from the fast_mark which is already atomic.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-10-24 14:54:57 +08:00
Tatsuyuki Ishi 20ca4e38f4 Use relaxed for update_{minimum,maximum}.
We only need the RMW to be atomic and doesn't need the ordering guarantee wrt
other memory locations.
Might make ARM a little faster (no machine code change for x86).

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-10-24 14:54:13 +08:00
Rui Ueyama 616f8b2205 Update comments 2022-10-24 13:54:39 +08:00
Rui Ueyama 4379dc4afa Prepare to distribute binary packages for arm, ppc64le and s390x 2022-10-24 13:54:39 +08:00
Rui Ueyama c5106da010 Remove unused file 2022-10-24 11:46:27 +08:00
Rui Ueyama 0d6e373ffc Refactor 2022-10-24 11:33:58 +08:00
Rui Ueyama 6361875a15 Revert "[ELF] Add --start-stop"
This reverts commit 1cfa4a93ae because
it was committed by accident.
2022-10-24 07:29:17 +08:00
Rui Ueyama 9c7970f0af Add a test 2022-10-24 07:16:27 +08:00
Rui Ueyama 59ea52933d [ELF] Honor section alignment when creating copy relocations 2022-10-24 06:58:03 +08:00
Rui Ueyama 4fa41e1ad4 Fix -Wdeprecated-declarations
Fixes https://github.com/rui314/mold/issues/816
2022-10-24 06:28:13 +08:00
Rui Ueyama ce35e19c6d Merge pull request #815 from polluks/patch-1 2022-10-23 12:39:57 -07:00
Stefan 8643520464 Fixed typos 2022-10-23 20:31:29 +02:00
Rui Ueyama d01deafff0 Merge pull request #810 from ishitatsuyuki/comdat-early 2022-10-23 05:24:48 -07:00
Rui Ueyama 8f74e48dfb Merge pull request #814 from ishitatsuyuki/fast-mark
Add an optimized mark function for faster GC passes.
2022-10-23 04:18:35 -07:00
Tatsuyuki Ishi 59a713fb4c Add an optimized mark function for faster GC passes.
Atomic RMW operations can take hundreds of cycles and tends to be massively
slower than a fence-free alternative.

Add a fast_mark function that optimistically tests if the node is already
visited first, which allows avoiding the fence penalty if we can early exit.

When testing on Chromium, this roughly improved the associated pass's runtime
by 20--30%.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-10-23 18:19:32 +08:00
Rui Ueyama 626619a8b0 Enable transparent huge pages for output file if THP is available 2022-10-23 18:17:47 +08:00
Rui Ueyama 585eae2030 Fix CI 2022-10-23 17:29:57 +08:00
Tatsuyuki Ishi 730e970e79 [ELF] Run COMDAT elimination inside resolve_symbols.
We've long had a hack to de-prioritize GNU_UNIQUE symbols, due to an edge case
where these symbols could get higher resolution priority yet eliminated in the
later COMDAT elimination stage. But since GNU_UNIQUE symbols were supposed to
have a resolution as strong as GLOBAL symbols, it created unsoundness in the
resolution and could have cause false duplicate symbol errors in later stages.

The root cause is that COMDAT elimination, unlike ICF and SHF_MERGE, removes
symbols from the candidate pool and can actually affect resolution result. Hence
we ought to do the elimination before the final resolution.

Doing so requires fully wiping the resolution instead of just the ones from
eliminated archive members. This has a performance hit that we need to keep an
eye on.

On another note this wiping of resolution is actually justifiable. The old
algorithm did not handle the case of an archive member overriding a DSO symbol.
So wiping is the correct way even in absence of COMDAT elimination.

One caveat is that currently the symbol resolution stage doesn't actually care
about the is_alive flag which is how COMDAT symbols are killed. There are two
other users of this flag: mergeable sections, and eh_frame. The eh_frame section
is already handled with special logic, and we can treat it as if it had no
symbols to resolve. Mergeable sections needs a bit more careful handling, but a
good way is to just leave them unmerged and update the references in the same
later pass where merge happens. This has been done in a prior commit.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-10-23 14:27:26 +08:00
Tatsuyuki Ishi 26c503ad30 [ELF] Defer initialize_mergeable_sections.
To allow symbol resolution to skip !is_alive sections.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-10-23 14:18:28 +08:00
Tatsuyuki Ishi 1a99724eca [ELF] Split out 1st pass of symbol resolution as finalize_archive_extraction.
This pass is rather different in that it runs the resolve pass with lower
priority for archive symbols in order to determine extraction. Split it out to
better convey its difference.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-10-23 13:53:03 +08:00
Tatsuyuki Ishi 03dad9ba14 [ELF] Simplify do_resolve_symbols.
We can skip the is_alive condition by doing the compaction beforehand.

This also allows splitting this function into two phases clearly which will
happen later.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-10-23 13:05:38 +08:00
Tatsuyuki Ishi e7a7f9e39a [ELF] Ensure all symbols from LTO objects are cleared.
Make sure clear_symbols() are called on IR object files too, so that we'll never
have references to symbols inside IR object files after LTO. Can't really think
of an example that causes problem, but for sanity.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-10-23 13:00:44 +08:00
Rui Ueyama e228abfd5a git [ELF] Do not include non-memory-mapped sections into build-id computation 2022-10-23 12:41:59 +08:00
Rui Ueyama 61f28d270c Fix CI 2022-10-23 12:24:58 +08:00
Rui Ueyama 9535e080e9 Simplify 2022-10-23 09:31:19 +08:00
Rui Ueyama f9750d163d Merge pull request #809 from sicherha/fix_SHN_XINDEX_out_of_bounds
Fix name lookup for section symbols when `st_shndx == SHN_XINDEX`
2022-10-22 18:15:55 -07:00
Christoph Erhardt f8cb32e59a Fix name lookup for section symbols when st_shndx == SHN_XINDEX
When the section-header index has the escape value `SHN_XINDEX`, the
actual index must be looked up in the separate `SHT_SYMTAB_SHNDX` table.
Trying to use `SHN_XINDEX` (= 0xffff) as an index results in an
out-of-bounds read. The error can be observed when running the
`x86_64_many-sections.sh` test on RHEL 8 or 9 (but not on Fedora,
because there the assembler doesn't emit section symbols).

Instead of using `st_shndx` directly, call the pre-existing helper
method `get_shndx()` to get the correct behaviour.

Signed-off-by: Christoph Erhardt <[email protected]>
2022-10-22 14:41:42 +02:00
Rui Ueyama 4508d93d08 Merge pull request #808 from ishitatsuyuki/refactor 2022-10-22 05:21:16 -07:00
Tatsuyuki Ishi fb4b67ae18 [ELF] Move ElfSym memset to inside of loop.
Should eliminate redundant assignments and improve memory locality.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-10-22 20:16:54 +09:00
Rui Ueyama 1e98ec0b38 Merge pull request #807 from ishitatsuyuki/symtab-garbage
[ELF] Fix uninitialized ElfSym paddings
2022-10-22 03:58:07 -07:00
Tatsuyuki Ishi 0b50ebda47 [ELF] Fix uninitialized ElfSym paddings
Designated initializer doesn't initialize the padding; make sure we memset
them by ourselves.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-10-22 19:37:35 +09:00
Rui Ueyama 5469f5ac1b Revert "Always enable assert()"
Turned out that what I wrote as a commit message for
800fcdc5d4 is wrong. mold is 5% slower
for linking clang with assertions enabled.
2022-10-22 16:24:22 +08:00
Rui Ueyama 068ce4654f Add a CI for a non-assert build
Even if we always enable assert(), we want code to be able to compile
with assert() being expanded to a null statement. I.e., we should not
write code that has side effect in assert().

In order to add a test case for it, I added a cmake option to force
disable assert().
2022-10-22 16:03:45 +08:00
Rui Ueyama 800fcdc5d4 Always enable assert()
Our assertions are cheap, and the cost of branch instructions that
are never taken is almost free thanks to hardware branch prediction.
So I don't think it's worth to disable it for release builds.
2022-10-22 15:21:08 +08:00
Rui Ueyama 0d7a5a7284 Create config.h 2022-10-22 14:40:47 +08:00
Rui Ueyama 7db72a871c Remove Makefile
It's been deprecated for some time.
2022-10-22 14:40:47 +08:00
Rui Ueyama 9842388cd0 Do not halt even if there's a big input text section 2022-10-22 13:24:49 +08:00
Rui Ueyama 29c4403ec4 Refactor 2022-10-22 13:03:25 +08:00
Rui Ueyama 74124636dc [ELF] Make less number of range extension thunks 2022-10-22 12:32:32 +08:00
Rui Ueyama 193c245781 Refactor 2022-10-22 12:22:57 +08:00
Rui Ueyama 5cdc761746 Print out the number of bytes occupied by range extension thunks 2022-10-22 11:01:27 +08:00
Rui Ueyama d35d3922f0 Fix typo
We set a value to .ARM.exidx's sh_shlink to appease GNU binutil's
strip command (this value is not used by runtime), but even strip
doesn't care what value is set! We set a wrong value by accident.

Fixes https://github.com/rui314/mold/issues/804
2022-10-22 08:24:00 +08:00
Rui Ueyama c4850273c7 [ELF] Handle GNU-unique symbols as if they were weak
https://github.com/rui314/mold/issues/524
2022-10-21 20:58:17 +08:00
Rui Ueyama 86f3130e44 [ELF] Remove the special logic for STB_GNU_UNIQUE
We've been treating STB_GNU_UNIQUE symbols as if they were weak.
The rationale of doing is this:

1. GCC sometimes creates GNU-unique symbols instead of weak ones
   for comdats, and

2. after COMDAT de-duplication, we used to report a duplicate symbol
   error for GNU-unique symbols

However, (2) is no longer the case because we do not report a symbol
duplication error if its section is dead.

I'm not sure if this new logic will work for all programs, but I want
to give it a shot.

https://github.com/rui314/mold/issues/524
2022-10-21 17:15:51 +08:00
Rui Ueyama 2dc1fecb02 Update comments 2022-10-21 17:15:51 +08:00
Rui Ueyama 33e3a75a79 Merge pull request #802 from ZhongRuoyu/disable-subprocess-cc-on-macos 2022-10-20 23:14:45 -07:00
Zhong Ruoyu 3fe46175f3 Do not build subprocess.cc on macOS
Signed-off-by: Zhong Ruoyu <[email protected]>
2022-10-21 12:44:27 +08:00
Rui Ueyama 861bccce72 [ELF] Do not emit non-memory-allocated sections if --oformat=binary 2022-10-21 08:24:15 +08:00
Rui Ueyama 60a75d0549 Fix CI 2022-10-21 07:46:49 +08:00
Rui Ueyama 610042a8e9 [ELF] Set .ARM.exidx's sh_link to .text
GNU binutil's strip command doesn't like an .ARM.exidx section with
sh_link set to 0. arm-linux-gnueabihf-strip actually crashes on my
machine when the command is run on such a file.

https://github.com/rui314/mold/issues/801
2022-10-21 07:11:52 +08:00
Rui Ueyama 1cfa4a93ae [ELF] Add --start-stop 2022-10-21 07:11:52 +08:00
Rui Ueyama 23905bba19 Merge pull request #800 from ZhongRuoyu/fix-mold-run-output 2022-10-20 11:07:42 -07:00
Zhong Ruoyu eb391f99cf Fix mold -run output on unsupported platforms
Signed-off-by: Zhong Ruoyu <[email protected]>
2022-10-21 00:29:37 +08:00
Rui Ueyama 78713299e3 Merge pull request #799 from ksco/fix-findnull
Fix a bug in find_null
2022-10-20 06:37:06 -07:00
Yang Liu 1f32a6daf6 Fix a bug in find_null
Signed-off-by: Yang Liu <[email protected]>
2022-10-20 21:14:09 +08:00
Rui Ueyama 6b00a6c2ca Merge pull request #798 from ishitatsuyuki/emit-relocs
[ELF] Fix --emit-relocs r_sym indices.
2022-10-20 05:34:58 -07:00
Tatsuyuki Ishi f18af9e2f4 [ELF] Fix --emit-relocs r_sym indices.
536e0e7d ("[elf] Align .symtab's ELF attributes with .dynsym's.") fixed the
issue of .dynsym and .symtab disagreeing with each other, but in the
process introduced change to the symtab index. --emit-relocs was assuming
the old assignment logic, which caused mismatches as soon as any
global-to-local demotion happened.

Fix this to use the demotion-aware assignment logic by directly filling in
the indices as we assign them to symtab, and by making get_output_sym_idx
to test global/local using the new is_local() helper.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-10-20 20:43:29 +09:00
Rui Ueyama 288cd5b400 [ELF][i386] Fix assertion failure
https://github.com/rui314/mold/issues/794
2022-10-19 20:14:58 +08:00
Rui Ueyama 48dd520014 Clarify and simplify the sign-off guideline
The more we write to this file, the more it is unclear what exatly
a contributor is agreeing to.
2022-10-19 20:13:01 +08:00
Rui Ueyama 2aa24949c7 [ELF][i386] Allow R_386_PC32 after R_386_TLS_{GD,LDM}
I don't know why GCC sometimes creates a PC32 relocation instead of
PLT32 after a TLS_GD/TLS_LDM. I believe it's strictly speaking a
violation of the psABI. But we need to handle such input.

Fixes https://github.com/rui314/mold/issues/794
2022-10-19 19:33:18 +08:00
Rui Ueyama 323ad30e25 Bump mold version to 1.6.0 2022-10-19 14:58:59 +08:00
Rui Ueyama 96f7b664e9 Fix CI 2022-10-19 14:38:22 +08:00
Rui Ueyama a137bc4111 Avoid reading /proc/self/exe on FreeBSD
Fixes https://github.com/rui314/mold/issues/792
2022-10-19 13:48:46 +08:00
Rui Ueyama 0f6a03a9ba Merge pull request #791 from ksco/simplify 2022-10-18 13:43:11 -07:00
Yang Liu 17cb7d8dce Simplify
Signed-off-by: Yang Liu <[email protected]>
2022-10-18 21:26:42 +08:00
Rui Ueyama 0df3a2bf7b Fix CI 2022-10-18 18:11:05 +08:00
Rui Ueyama d5c59fc919 Use strerror() instead of its thread-safe versions
Since errno_string is not in a performance-critical path, it's ok for
that function to be a bit inefficient.

https://github.com/rui314/mold/issues/790
2022-10-18 17:59:07 +08:00
Rui Ueyama 0364934636 Fix -Wunused-result
Fixes https://github.com/rui314/mold/issues/790
2022-10-18 17:20:10 +08:00
Rui Ueyama edd10419dd [ELF] Save a little bit space for copy relocations 2022-10-18 17:16:00 +08:00
Rui Ueyama c1c6749940 [ELF] Ignore .note.gnu.build-id in input object files 2022-10-18 16:31:04 +08:00
Rui Ueyama 750d536401 Update comments 2022-10-18 16:30:55 +08:00
Rui Ueyama e56a3751bf [ELF][s390x] Do not allow misaligned R_390_*DBL relocs 2022-10-18 16:28:52 +08:00
Rui Ueyama ad87ac28b7 Simplify 2022-10-18 13:05:35 +08:00
Rui Ueyama 7cb97e153a [ELF] Fix -repro 2022-10-18 12:51:14 +08:00
Rui Ueyama db4bcd4138 Untabify 2022-10-18 12:41:11 +08:00
Rui Ueyama 1493a5cfd3 Merge pull request #788 from akien-mga/armv7-no-latomic 2022-10-17 14:20:47 -07:00
Rémi Verschelde 04033a1b52 CMake: Only add -latomic for armv6, not armv7
This matches what was done in `Makefile` in #561, but the check was extended
in the CMake port.

It builds fine without `-latomic` on Mageia 9 armv7hl nodes, fails with
explicit `-latomic`.

Signed-off-by: Rémi Verschelde <[email protected]>
2022-10-17 18:09:31 +02:00
Rui Ueyama d2b7b04be3 [ELF] Do not allow DSO to keep other DSO
Previously, an undefined symbol in a DSO can mark other DSO as "needed".
But that lead to mark more DSOs needed as necessary. It is also a bit
counter-intuitive.

The new behavior is still slightly different from GNU ld, but I believe
it's now compatible with LLVM lld.

Fixes https://github.com/rui314/mold/issues/786
2022-10-17 20:59:20 +08:00
Rui Ueyama bc22065684 Merge pull request #787 from ishitatsuyuki/pch
Add precompiled headers for CMake builds.
2022-10-17 03:09:26 -07:00
Tatsuyuki Ishi bf2d6bda28 workflows: Disable PCH for the default configuration.
As stated in the comment, have at least one permutation that checks for missing
(implicit) header includes.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-10-17 17:03:32 +08:00
Tatsuyuki Ishi d1cc5844c6 Add precompiled headers for CMake builds.
Since we're having lots of arch-generic permutations, headers seems to be a good
place where potential perf improvement are possible.

The feature is gated against CMake 3.16.0 or later, which is when it was
implemented.

Measured on 3990X, with this change it takes:
ninja  1166.22s user 34.45s system 5378% cpu 22.322 total
While before it took:
ninja  1776.81s user 51.30s system 7172% cpu 25.489 total

So a 10% improvement for workstation users and even more if you don't.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-10-17 16:58:42 +08:00
Rui Ueyama c5e9c30ce8 Fix CI 2022-10-17 14:25:25 +08:00
Rui Ueyama 2fb054d4a5 Refactor 2022-10-17 14:19:48 +08:00
Rui Ueyama 8fb6fb295b Rgefactor 2022-10-17 12:00:09 +08:00
Rui Ueyama 341705e4a2 Merge pull request #783 from ishitatsuyuki/icf-followup 2022-10-16 05:45:14 -07:00
Tatsuyuki Ishi 53848be39f [ELF] Replace killed_by_icf with is_killed_by_icf().
One less bit of state and should be clearer how the property is computed.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-10-16 10:06:13 +08:00
Rui Ueyama b3ed06aa39 Merge pull request #782 from ishitatsuyuki/icf-shndx
[ELF] Assign the correct SHNDX to symbols killed by ICF.
2022-10-15 04:42:29 -07:00
Tatsuyuki Ishi 207d8535f8 [ELF] Clarify ICF related struct fields.
Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-10-15 18:10:29 +08:00
Tatsuyuki Ishi 519595c0c3 [ELF] Assign the correct SHNDX to symbols killed by ICF.
We have been setting the symbol value and size correctly, but the SHNDX was
erroneously set to UND, potentially causing undefined symbol errors. Fix this by
forwarding the appropriate value from the `leader`.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-10-15 18:10:03 +08:00
Rui Ueyama 916f8b196a Merge pull request #781 from marxin/use-checkout-v3
fix Github Actions warning:
2022-10-15 02:07:03 -07:00
Martin Liska 38b2843f84 fix Github Actions warning:
Node.js 12 actions are deprecated. For more information see:
https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/
2022-10-15 10:24:18 +02:00
Rui Ueyama df371c392b [ELF] Add more relocation overflow checks 2022-10-15 14:07:21 +08:00
Rui Ueyama 5171c9164e Refactor 2022-10-14 19:49:41 +08:00
Rui Ueyama c74486172b Make compile faster 2022-10-14 19:25:50 +08:00
Rui Ueyama 8fb9cb8815 Refactor 2022-10-14 18:17:05 +08:00
Rui Ueyama dd4048b7c4 Simplify 2022-10-14 15:27:25 +08:00
Rui Ueyama d3dc5e31eb Fix CI 2022-10-14 15:10:07 +08:00
Rui Ueyama dcc0dff67d Encourage users to migrate to cmake 2022-10-14 14:36:25 +08:00
Rui Ueyama b1382fd5e6 Update documentation 2022-10-14 13:13:37 +08:00
Rui Ueyama f4ce278729 [ELF][S390X] Support more relocation types 2022-10-14 12:59:57 +08:00
Rui Ueyama 30dd63cc0a [ELF] Do not create .plt.got for ppc64/ppc64le 2022-10-14 12:09:24 +08:00
Rui Ueyama 2dbbc54c28 Merge pull request #776 from marxin/fix-2-warnings
fix 2 -Wextra warnings
2022-10-13 19:14:47 -07:00
Rui Ueyama 55552b1481 Update comments 2022-10-13 21:12:29 +08:00
Rui Ueyama 1e24ce1f50 Update man page and comments 2022-10-13 20:53:57 +08:00
Rui Ueyama 687bd8ab65 Update comments 2022-10-13 16:33:15 +08:00
Rui Ueyama 08f34e3d67 [ELF][S390X] Skip tests affected by a GCC bug 2022-10-13 16:22:28 +08:00
Rui Ueyama 83e0632935 Update README 2022-10-13 15:16:38 +08:00
Rui Ueyama 2e7a0ad5f4 Update README 2022-10-13 15:07:36 +08:00
Rui Ueyama 1c63e0577a Document CMake options
Fixes https://github.com/rui314/mold/issues/734
2022-10-13 14:59:02 +08:00
Rui Ueyama c45db5c659 Fix CI 2022-10-13 14:08:47 +08:00
Rui Ueyama 0d205aa5e8 [ELF] Do not create PREINIT .dynamic entries if not necessary
Fixes https://github.com/rui314/mold/issues/773
2022-10-13 12:00:16 +08:00
Rui Ueyama 501a9fb57d [ELF][S390X] Set GOT[0] to _DYNAMIC
s390x psABI requires GOT[0] to be set to the link-time value of _DYNAMIC.
It also defines that GOT[1] as reserved.

https://sourceware.org/bugzilla/show_bug.cgi?id=29662
2022-10-13 09:42:26 +08:00
Rui Ueyama 33d388cc48 [ELF][S390X] Do not set GOT[0] unless -static-pie
It looks like we don't have to conservatively set GOT[0] to .dynamic
on s390x. glibc's -static-pie depends on GOT[0], so we need to set for
it, though.
2022-10-12 16:41:37 +08:00
Rui Ueyama 5010c0e66a Fix SuSE builder 2022-10-12 14:23:35 +08:00
Rui Ueyama a484df6885 Refactor 2022-10-12 12:34:00 +08:00
Rui Ueyama ce12303229 Fix CI 2022-10-12 12:10:14 +08:00
Rui Ueyama fb046cc6ed Refactor 2022-10-12 12:10:14 +08:00
Rui Ueyama f172cada2f Refactor 2022-10-11 15:28:17 +08:00
Rui Ueyama 5a5d25895c [ELF] Attempt to fix CI 2022-10-11 15:03:44 +08:00
Rui Ueyama bdecfeef7f Refactor 2022-10-11 14:43:20 +08:00
Rui Ueyama 86fd0241e0 Update comments 2022-10-11 14:24:27 +08:00
Rui Ueyama c3e8fea746 Fix build and refactor 2022-10-11 14:00:46 +08:00
Rui Ueyama 336a7b89c3 Merge pull request #778 from toppa102/freebsd-fix
Fix /proc/self behaviour on FreeBSD
2022-10-10 22:56:17 -07:00
Rui Ueyama 0d368b44de [ELF] Fix -Wtype-limits
These relocations are defined as follows

  R_SPARC_GOTDATA_OP_HIX22    (G >> 10) ^ (G >> 31)
  R_SPARC_GOTDATA_OP_LOX10    (G & 0x3ff) | ((G >> 31) & 0x1c00)

where G is an offset into .got. Since .got is much smaller than 4 GiB,
(G >> 31) is always zero, so we can ignore that part.

https://docs.oracle.com/cd/E19120-01/open.solaris/819-0690/chapter6-24/index.html
2022-10-11 13:53:15 +08:00
Rui Ueyama 12ff7bb067 [ELF][PPC64V1] Enable QEMU tests on GitHub Actions
All tests now pass on my machine for ppc64v1 except a few disabled ones.
2022-10-11 13:24:24 +08:00
Rui Ueyama 305f0f801e [ELF][PPC64V1] Fix more tests 2022-10-11 12:46:56 +08:00
toppa102 e11aa75543 Fixed /proc/self behaviour on FreeBSD 2022-10-10 22:28:34 +03:00
Martin Liska 2d79d1f65c fix 2 -Wextra warnings
Fixes:
macho/input-files.cc:310:31: warning: missing initializer for member ‘mold::macho::Subsection<mold::macho::ARM64>::replacer’ [-Wmissing-field-initializers]
elf/mold-wrapper.c:68:15: warning: passing argument 1 of ‘debug_print’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]

Signed-off-by: Martin Liska <[email protected]>
2022-10-10 17:42:05 +02:00
Rui Ueyama e4c682b645 [ELF][ARM32] Support R_ARM_THM_JUMP19
Fixes https://github.com/rui314/mold/issues/774
2022-10-10 12:55:06 +08:00
Rui Ueyama cc3d9a274e Merge pull request #772 from ishitatsuyuki/issue-606
[ELF] Rework version_specified handling.
2022-10-09 19:32:33 -07:00
Rui Ueyama 2d5c9e0ff7 Refactor 2022-10-10 10:19:11 +08:00
Rui Ueyama 1a58a0a6d4 Merge pull request #771 from marxin/fix-compiler-warnings
fix compiler warnings
2022-10-09 19:18:03 -07:00
Tatsuyuki Ishi 2e099a12a7 [ELF] Rework version_specified handling.
We should only override the default export behavior in executable if the default
version was actually overridden by a linker script (i.e. local: *;). Other
options, such as --dynamic-list and --export-dynamic-symbol[-list], doesn't
actually change this default, and should not be considered for this override.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-10-09 21:23:30 +08:00
Martin Liska 8352edfe94 fix compiler warnings
Fixes:

```
elf/arch-ppc64v1.cc:278:9: warning: unused variable 'loc' [-Wunused-variable]
elf/arch-ppc64v1.cc:285:10: warning: variable 'check' set but not used [-Wunused-but-set-variable]
elf/output-chunks.cc:1400:32: warning: unused variable 'sym' [-Wunused-variable]
```

Signed-off-by: Martin Liska <[email protected]>
2022-10-09 14:22:47 +02:00
Rui Ueyama 87f0262ce8 Refactor 2022-10-09 12:43:40 +08:00
Rui Ueyama 3b987874f4 Update comments 2022-10-09 12:32:21 +08:00
Rui Ueyama 4d9de802fc Update README 2022-10-09 11:33:17 +08:00
Rui Ueyama 6102ed531c Merge pull request #769 from AlexTMjugador/main
README.md: mention that installing clang is not needed for Rust when using the latest GCC
2022-10-08 20:13:08 -07:00
Rui Ueyama c9ec169d50 Merge pull request #770 from tosch42/spell
Fix spelling of "unknown"
2022-10-08 20:12:16 -07:00
Rui Ueyama 944d0fd3f6 [ELF][PPC64V1] Add initial PPC64 big-endian ELFv1 ABI
Since around 2015, IBM seems to have been encouraging their customers to
use PowerPC systems in little-endian mode. They ratified the little-
endian ABI for PPC64. Since it was completely a binary-compatibility-
breaking change anyway, they didn't only change the endianness but made a
few improvements to the ABI they have been wanting to make. So the new ABI
was born.

The new ABI is called the ELFv2 ABI. The original, big-endian-only one
is retrospectively called ELFv1. Technically, the new ABI supports both
little endiannesses. but effectively all systems that employ ELFv2 are
using the processor in the little-endian mode.

There are still many PowerPC systems that use the original ELF ABI in the
little-endian mode for binary compatibility. This commit is for such systems.

We already support ELFv2. Look at arch-ppc64v2.cc.

Currently, "73% tests passed, 63 tests failed out of 234" for the ppc64v1
target according to ctest.
2022-10-09 11:09:50 +08:00
Tom Schwindl 88e275f2b1 Fix spelling of "unknown"
Signed-off-by: Tom Schwindl <[email protected]>
2022-10-08 20:24:11 +02:00
Alejandro González d91ebb6c0c README.md: mention that installing clang is not needed for Rust when using the latest GCC
As explained in the "A classic way to use mold" section, the latest GCC releases support `mold` out of the box. Rust can take advantage of this to use `mold` too, without going through a system-wide `clang` linker.

I've just tested this on my Linux workstation that runs Debian unstable.
2022-10-08 19:40:30 +02:00
Rui Ueyama e48b7e767b Refactor 2022-10-08 09:49:45 +08:00
Rui Ueyama 8d0f3ee849 [ELF][S390X] Set _DYNAMIC to GOT[0]
https://github.com/rui314/mold/issues/767
2022-10-08 09:34:43 +08:00
Rui Ueyama fc66759444 [ELF] Set the .dynamic address to the first entry of .got
glibc for ARM64 prior to August 2021 arguably wrongly assumes that
the GOT first entry contains the address of the .dynamic section.
That's been removed in the following commit, but without satisfying
that assumption, mold can't create working static position-independent
execuables for ARM64.

https://sourceware.org/git/?p=glibc.git;h=43d06ed218fc8be58987bdfd00e21e5720f0b862
2022-10-08 09:06:28 +08:00
Rui Ueyama 8bedc4d7e7 Refactor 2022-10-08 07:15:21 +08:00
Rui Ueyama c2baf10d6b Disable static PIE tests on ARM64
They are failing only on GitHub Actions. I believe they don't work
with older versions of glibc. Until we fix them, I want to disable
them so that the tests are green.
2022-10-08 06:59:01 +08:00
Rui Ueyama 5dc906dc6b [ELF][S390] TLSLE computes an offset from TP, so we don't need a GOT entry for it 2022-10-08 06:55:53 +08:00
Rui Ueyama 8ea3316c7f Refactor 2022-10-08 06:55:53 +08:00
Rui Ueyama 5ff581b363 Merge pull request #766 from marxin/tests-use-skip
tests: use skip function call when possible
2022-10-06 01:10:46 -07:00
Rui Ueyama 7778ef7fa3 Merge pull request #765 from marxin/machine-test
tests: add missing MACHINE check in x86_64_large-bss.sh
2022-10-06 01:10:20 -07:00
Martin Liska ec4c1ae981 tests: use skip function call when possible
Signed-off-by: Martin Liska <[email protected]>
2022-10-06 09:53:05 +02:00
Martin Liska 1906d210ab tests: add missing MACHINE check in x86_64_large-bss.sh
Signed-off-by: Martin Liska <[email protected]>
2022-10-06 09:49:59 +02:00
Rui Ueyama 864d91569d Enable more -static-pie tests for ARM64 and i386 2022-10-06 15:32:22 +08:00
Rui Ueyama c05e2691c0 Merge pull request #764 from marxin/cleanup-test
remove extra OK message from a test
2022-10-06 00:24:25 -07:00
Rui Ueyama d3ab0c732c Fix CI 2022-10-06 15:23:18 +08:00
Rui Ueyama bd16377bd8 [ELF][i386] Implement R_386_GOT32X relaxation 2022-10-06 15:20:17 +08:00
Martin Liska c38bf979ce remove extra OK message from a test
Signed-off-by: Martin Liska <[email protected]>
2022-10-06 09:12:57 +02:00
Rui Ueyama 8251c0d467 Enable tests that depend on zstdcat, gdb and dwarfdump 2022-10-06 14:06:18 +08:00
Rui Ueyama 52fc5877f7 Refactor 2022-10-06 13:15:55 +08:00
Rui Ueyama e1275942c8 Factor out common piece of code to common.inc 2022-10-06 12:07:31 +08:00
Rui Ueyama 9e4e81b061 Fix -Wnarrowing on i386
FIxes https://github.com/rui314/mold/issues/763
2022-10-06 09:36:56 +08:00
Rui Ueyama c7f181c30b Rename S390 S390X
s390 technically means the 32-bit ESA/390 ISA, so s390x is more precise.
2022-10-06 09:34:30 +08:00
Rui Ueyama 03721f9abe Update comments 2022-10-05 22:31:31 +08:00
Rui Ueyama a79a6059e2 Refactor 2022-10-05 21:22:56 +08:00
Rui Ueyama 1145900c51 Refactor 2022-10-05 21:13:17 +08:00
Rui Ueyama 6bbf82f3b0 Refactor 2022-10-05 20:52:02 +08:00
Rui Ueyama 7aae0bf7ba [ELF][S390] Implement TLS GD -> LE relaxation 2022-10-05 20:31:38 +08:00
Rui Ueyama 2b0ab0e974 [ELF][S390] Fix linker-synthesized __tls_get_offset
__tls_get_offset is supposed to return an offset from TP. Previously,
we instead returned an offset from the beginning of the TLS block.
2022-10-05 18:08:49 +08:00
Rui Ueyama 4bf21122e1 Refactor 2022-10-05 16:21:24 +08:00
Rui Ueyama b6b6c178b4 Fix comments 2022-10-05 15:48:28 +08:00
Rui Ueyama 5eb81b4e00 Refactor 2022-10-05 15:43:56 +08:00
Rui Ueyama f5aeeeb01d Add comments 2022-10-05 15:20:42 +08:00
Rui Ueyama 1efc14d45d [ELF][S390] Allow R_390_TLS_LDO64 in non-memory-allocated sections 2022-10-05 14:27:36 +08:00
Rui Ueyama da5d4380cf Merge pull request #759 from ishitatsuyuki/docs
[elf] Update push/pop-state documentation.
2022-10-04 23:13:43 -07:00
Tatsuyuki Ishi 9d873f555e [elf] Update push/pop-state documentation.
Closes: https://github.com/rui314/mold/issues/755
Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-10-05 14:03:44 +08:00
Rui Ueyama a39086fa3b Fix CI 2022-10-05 13:45:01 +08:00
Rui Ueyama ffac38ae9e [ELF][S390] Support more relocations, enabling tests
It seems all tests pass with this change, so I'm enabling them.
2022-10-05 13:02:47 +08:00
Rui Ueyama 182db15da7 [ELF] Add initial s390x support
The implementation is far from complete, but mold/s390 is already able
to dynamically link a "Hello World" program for s390 which can
successfully run on qemu-s390x.
2022-10-05 10:13:21 +08:00
Rui Ueyama 4801234609 Refactor 2022-10-05 10:06:53 +08:00
Rui Ueyama 6ea03e6433 [ELF] Use $ instead of @ for lihnker-synthesized symbols
gdb recognizes "@" as an operator, so it's better to use a different symbol.
2022-10-04 16:46:21 +08:00
Rui Ueyama 5000a5f05d Merge pull request #754 from ZhongRuoyu/dist-fail-early
dist.sh: do not proceed when `cmake --build` fails
2022-10-04 00:34:51 -07:00
Zhong Ruoyu 89f8990dde dist.sh: do not proceed when cmake --build fails
Signed-off-by: Zhong Ruoyu <[email protected]>
2022-10-04 14:11:49 +08:00
Rui Ueyama e5adf2fe49 [ELF][i386] Make PLT entries to start with ENDBR32
Unlike GNU ld, we do not create .plt.sec section.

%ecx is defined as a scratch register, so we can use it in our PLT entries.
2022-10-04 13:07:36 +08:00
Rui Ueyama ed0996a590 Refactor 2022-10-04 10:04:08 +08:00
Rui Ueyama f19c242901 Fix CI 2022-10-03 23:16:28 +08:00
Rui Ueyama 443a9c6d2d Fix CI 2022-10-03 23:00:15 +08:00
Rui Ueyama d414f8ff6b Attempt to fix CI 2022-10-03 22:29:14 +08:00
Rui Ueyama 1205b1c18b [ELF] Do not truncate section size to 2^32
Fixes https://github.com/rui314/mold/issues/753
2022-10-03 21:55:28 +08:00
Rui Ueyama 1b86708683 [ELF] Resurrect .plt.got
This reverts commit ef04befcba and
6c964df459.

Even though these commits are not technically wrong, they caused a
regression on ARM32 and PPC64LE. It is because glibc cannot handle
IRELATIVE relocations in .rela.plt on these targets. Compare the
following two source source files:

  https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/x86_64/dl-machine.h;h=005d089501fa78654e16103de9ec901af7be4ff2;hb=HEAD#l530

  https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/arm/dl-machine.h;h=b0521c15496b9967a1c00a0ca7214bad2337be14;hb=HEAD#l464

ARM doesn't handle IRELATIVE for some reason, though x86-64 does.
I guess this is glibc's bug, but apparently we can't create IRELATIVE
relocations in .rela.plt. So we need to create it in .rela.dyn.
2022-10-03 21:45:15 +08:00
Rui Ueyama ef04befcba [ELF] Do not emit .plt.got
If a symbol has both PLT and GOT entries, we used to create its PLT
entry in .plt.got so that the runtime needs to look up the symbol
exactly once. This optimization however doesn't seem to be useful
because the number of such symbols is usually very small (<100 for
a large program). So I don't think its worth its complexity.
2022-10-03 17:21:45 +08:00
Rui Ueyama 6c964df459 [ELF] Do not always create a GOT entry for IFUNC 2022-10-03 17:07:43 +08:00
Rui Ueyama c74c001891 Merge pull request #749 from erneestoc/bundle-loader-bug
Makes xcode tests run
2022-10-02 22:52:24 -07:00
Rui Ueyama 324658fe1c Rename a function 2022-10-03 13:04:46 +08:00
Rui Ueyama c89d742be6 Refactor 2022-10-03 13:04:46 +08:00
Rui Ueyama 0f611697e0 Merge pull request #751 from rafalh/patch-1 2022-10-02 08:14:52 -07:00
Rafał Harabień 850627e7c9 Add Linux Mint support in install-build-deps.sh
Should fix following error on Linux Mint 21:
```
Error: don't know anything about build dependencies on linuxmint-21
```
2022-10-02 16:30:30 +02:00
Rui Ueyama c4e8fab106 Fix CI 2022-10-02 17:08:35 +08:00
Rui Ueyama a7f1e20594 [ELF] Emit local symbols for .got, .plt and .plt.got
These symbols are purely informational. They are not used for symbol
resolution. But they are useful for making disassembly readable.
2022-10-02 16:51:45 +08:00
Ernesto Cambuston 48ee718f23 Makes xcode tests run, Signed-off-by: Ernesto Cambuston <[email protected]> 2022-10-02 00:13:47 -07:00
Rui Ueyama ae91e487df Do not include .sh in test name 2022-10-02 14:44:07 +08:00
Rui Ueyama 1709ad5996 [ELF] Do not create a PLT entry for IFUNC if -fno-plt 2022-10-02 14:26:33 +08:00
Rui Ueyama 424f43772a Refactor 2022-10-02 13:59:59 +08:00
Rui Ueyama 3663b60074 [ELF] Place a section header at the very end of a file
Conventionally, a section header is placed at the very end of a file.
It's not technically required to do so, though.
2022-10-02 13:01:25 +08:00
Rui Ueyama 3c123cfe9d [ELF] Always set alignment 1 to PT_GNU_RELRO and PT_GNU_STACK
Alignment values are not significant for these types of segments,
so I don't want to set them to meainingful values.
2022-10-02 12:42:48 +08:00
Rui Ueyama 0fa4cff086 [ELF] Fix thread-pointer calculation
TLS segments were always page-aligned before 9c7b95f108,
so we didn't notice, but our expressions to compute TP and TLS offset
were wrong.
2022-10-02 11:41:04 +08:00
Rui Ueyama 2f5366f764 Refactor 2022-10-01 16:16:28 +08:00
Rui Ueyama 92c2c9bc8f Refactor 2022-10-01 16:13:52 +08:00
Rui Ueyama 19db4bbe13 [ELF] Create symbols for range extension thunks 2022-10-01 15:52:59 +08:00
Rui Ueyama 0929788ccc Refactor 2022-10-01 11:43:26 +08:00
Rui Ueyama fb4c21a65a Raise the support level of SPARC64 to match other targets 2022-10-01 11:22:40 +08:00
Rui Ueyama b36562fc94 Show skipped tests
https://github.com/rui314/mold/pull/745
2022-10-01 10:57:43 +08:00
Rui Ueyama 5cf3ad6fe7 Handle MOLD_ENABLE_QEMU_TESTS 2022-10-01 10:57:04 +08:00
Rui Ueyama 930964ab38 [ELF] Do not run target-specific tests on unintended targets
This commit reduces the number of tests that are invoked only to
print out the "skipped" message.
2022-10-01 10:29:40 +08:00
Rui Ueyama 56de92f65f Fix CI 2022-10-01 10:25:25 +08:00
Rui Ueyama 7d8bf817e9 [ELF] Reorganize test files 2022-09-30 15:59:53 +08:00
Rui Ueyama 438d67bcf5 Refactor 2022-09-30 12:30:32 +08:00
Rui Ueyama 020863f238 Merge pull request #740 from SupervisedThinking/up_mold_binary_install_path
CMakeLists: allow custom mold binary install path
2022-09-29 19:35:10 -07:00
Rui Ueyama 322ce8eb9d [ELF] Do not create an unnecessary gap before an executable segment 2022-09-30 10:24:56 +08:00
Rui Ueyama 57f2099a36 Revert "Detect skipped tests"
This reverts commit 313629e1af because
it made `ctest` to print out too many lines after the test summary
report for skipped test names.
2022-09-30 10:20:50 +08:00
Rui Ueyama 2fcfb9b470 [ELF] Do not allocate disk space for .relro_padding
With this change, there should be no file size penalty on specifying
a large value to `-z max-page-size`.
2022-09-30 10:18:55 +08:00
Rui Ueyama 8ef01f87b1 Merge pull request #743 from sicherha/detect_skipped_tests 2022-09-29 18:23:39 -07:00
Rui Ueyama 5eed32bcf2 [ELF] Do not discard .gnu.warning sections
.gnu.warning* section may contain strings referenced by other sections,
so we can't discard them unconditionally. In this commit, we simply
keep all .gnu.warning* sections.
2022-09-30 08:57:23 +08:00
Rui Ueyama c7767dd36d Merge pull request #744 from lkr0n/fix_gnu_warn_segfault
only ignore .gnu.warning. sections if emit_relocs is true
2022-09-29 16:02:58 -07:00
Louis Kronberg 5b147db113 only ignore .gnu.warning. sections if emit_relocs is true
This attempts to fix Issue #567 where mold would segfault
trying to emit relocations for .gnu.warning. sections.
2022-09-29 16:52:23 +02:00
Christoph Erhardt 313629e1af Detect skipped tests
This allows CTest to differentiate between tests that were executed
successfully and tests that were skipped.

Signed-off-by: Christoph Erhardt <[email protected]>
2022-09-29 16:43:17 +02:00
Rui Ueyama 260182d439 Fix CI 2022-09-29 21:52:32 +08:00
Rui Ueyama 458f88b6cf Fix CI 2022-09-29 21:00:58 +08:00
Rui Ueyama 34ee49f3de [ELF] Add a padding at end of a PT_GNU_RELRO segment
We used to extend just a load segment containing RELRO sections.
strip command shrinks such segment so that it fits its contents.
So we need a dummy section for padding.

https://github.com/rui314/mold/issues/732
2022-09-29 20:02:49 +08:00
Rui Ueyama 5746060cde Refactor 2022-09-29 20:02:33 +08:00
SupervisedThinking f7f2ef6182 CMakeLists: allow custom mold binary install path
- https://cmake.org/cmake/help/latest/command/install.html
- ${CMAKE_INSTALL_BINDIR} defaults to bin if not set
2022-09-29 11:49:57 +02:00
Rui Ueyama 886dbe6b24 Refactor 2022-09-29 16:52:33 +08:00
Rui Ueyama d1d6c00e0c Improve a script 2022-09-29 15:53:08 +08:00
Rui Ueyama 3bf3709799 Add a missing dependency
We need `util-linux` package for `hexdump`
2022-09-29 15:46:06 +08:00
Rui Ueyama d504b24419 [ELF] Fix test for PPC64LE
`readelf --symbols` print out auxiliary information after a symbol name
for PPC64, so something like `foo$` didn't match.

     7: 0000000000000000    80 FUNC    GLOBAL DEFAULT    3 main [<localentry>: 8]
     8: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND .TOC.
     9: 0000000000000000    72 FUNC    GLOBAL DEFAULT   11 foo  [<localentry>: 8]
    10: 0000000000000000    40 FUNC    GLOBAL DEFAULT   19 bar

Fixes https://github.com/rui314/mold/issues/739
2022-09-29 15:43:18 +08:00
Rui Ueyama b8ab2fd016 Refactor 2022-09-29 15:04:23 +08:00
Rui Ueyama a5448f2a48 Merge pull request #738 from jpalus/cmake-absolute-install-paths
cmake: use unambiguously absolute paths for install directories
2022-09-29 00:02:36 -07:00
Rui Ueyama e541ad3811 [ELF] Do not try to merge RELRO with a RO segment
Because of db415be21c, a RELRO segment
no longer follow a read-only data segment. So this optimization doesn't
do anything.
2022-09-29 14:08:58 +08:00
Rui Ueyama db415be21c [ELF] Place readonly data after ELF headers
They are both read-only, so by placing them next to each other, we can
reduce the number of the load segments by one, which translates to one
less mmap(2) at runtime.
2022-09-29 13:36:45 +08:00
Rui Ueyama 33de554f41 Revert "Revert recent memory layout changes"
This reverts commit e62de0b31f so that
we can try this for 1.5.2.
2022-09-29 13:22:03 +08:00
Rui Ueyama 6abf26ef38 [ELF] Sort loadable segments on p_vaddr 2022-09-29 11:47:04 +08:00
Rui Ueyama 1ed941f3f0 Bump mold version to 1.5.1 2022-09-28 17:33:54 +08:00
Rui Ueyama e62de0b31f Revert recent memory layout changes
This commit reverts the following commits:

- 3d33349691 [ELF] Fix -max-page-size
- 14b2ba3b74 Refactor
- 41c762b6c5 Update comments
- d22e85f345 [ELF] Save one memory page for RELRO
- 2941d75c71 [ELF] Do not page-align loadable segments
- a2552b6fd1 Refactor
- 919f58dc5d Fix CI
- ef6e6ecdf4 Refactor
- 9c7b95f108 [ELF] Do not page-align RELRO and TLS segments

I'll revert these changes because they caused a regression on systems
with large page size. Even though I believe most users are not
affected, it's a critical bug as mold creates completely unusable
output files for certain systems. In order to release 1.5.1, I'll
revert all of them.
2022-09-28 17:24:19 +08:00
Rui Ueyama 56b9ad9c62 Merge pull request #736 from sicherha/fix_test_failure_with_clang15
Disable PIE in `run-clang.sh` unit test
2022-09-27 19:57:34 -07:00
Jan Palus 9464a12960 cmake: use unambiguously absolute paths for install directories
as per https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
CMAKE_INSTALL_<dir> can be both relative and absolute. so far mold made
assumption these are relative only, but handle both cases by using
CMAKE_INSTALL_FULL_<dir> instead.

Signed-off-by: Jan Palus <[email protected]>
2022-09-27 23:48:07 +02:00
Christoph Erhardt 7aa87220c4 Disable PIE in run-clang.sh unit test
This fixes the following error when Clang 15 is installed on the system:
> mold: error: out/test/elf/x86_64/run-clang/a.o:(.text):
> R_X86_64_32 relocation at offset 0x5 against symbol `.rodata' can not
> be used; recompile with -fPIC

The error occurs because Clang 15 assumes PIE to be enabled by default:
https://releases.llvm.org/15.0.0/tools/clang/docs/ReleaseNotes.html#build-system-changes

Attempting to produce a position-independent executable from an object
file that was created by `cc` without `-fPIE` caused the linker to bail
out.

Signed-off-by: Christoph Erhardt <[email protected]>
2022-09-27 15:16:44 +02:00
Rui Ueyama 95ad47ca7d Bump mold version to 1.5.0 2022-09-27 14:23:31 +08:00
Rui Ueyama 9db16a87f5 Improve build script 2022-09-27 11:50:09 +08:00
Rui Ueyama 3d33349691 [ELF] Fix -max-page-size
Fixes https://github.com/rui314/mold/issues/732
2022-09-27 11:19:31 +08:00
Rui Ueyama 5fab142c73 Refactor 2022-09-27 07:44:36 +08:00
Rui Ueyama 0a4ec45949 Merge pull request #731 from marxin/remove-duplicate 2022-09-26 14:28:22 -07:00
Martin Liska c9fbc48a6c remove duplicate in CMakeLists.txt
Signed-off-by: Martin Liska <[email protected]>
2022-09-26 21:22:01 +02:00
Rui Ueyama 14b2ba3b74 Refactor 2022-09-26 22:24:01 +08:00
Rui Ueyama 41c762b6c5 Update comments 2022-09-26 21:26:08 +08:00
Rui Ueyama d22e85f345 [ELF] Save one memory page for RELRO 2022-09-26 21:08:07 +08:00
Rui Ueyama 07ecfbcfe1 Refactor 2022-09-26 17:36:20 +08:00
Rui Ueyama c623b4e3f0 [ELF] Handle .eh_frame_seg as a special symbol for .eh_frame
Looks like Intel C/C++ compiler emits this symbol in .eh_frame.
I don't excatly know how this symbol is being used, but it looks like
this symbol is supposed to refer the beginning of the output .eh_frame.

Fixes https://github.com/rui314/mold/issues/685
2022-09-26 16:15:31 +08:00
Rui Ueyama 747c205773 [ELF] Do not copy .llvm_addrsig to an output file 2022-09-26 14:17:30 +08:00
Rui Ueyama 2941d75c71 [ELF] Do not page-align loadable segments
Previously, we align each loadable segment and the beginning of
readable-writable non-RELRO segment to page boundaries. That's one
posible layout, but it made too many holes in files that resulted
in output file bloat.

That bloat is most visible on targets supporting large pages.
We conservatively link output files for the largest possible page
size so that the output will run both on large pages and usual small
pages. As an example, we use 64 KiB as a page size for ARM64.
So we wasted up to 64 KiB for each loadable segment. A "hello world"
program for exapmle became almost 200 KiB on ARM64 because of that
reason.

This commit changes the file layout. Loadable segments are no longer
aligned to page boundaries. Loadable segments are still placed into
different memory pages. A page at a boundary of two loadable segments
are doubly mapped to memory.

This change reduces output file size. It is most noticeable when an
output is small -- a "hello world" on ARM64 is now smaller than 10
KiB now.
2022-09-26 13:48:03 +08:00
Rui Ueyama a2552b6fd1 Refactor 2022-09-25 20:27:00 +08:00
Rui Ueyama 919f58dc5d Fix CI 2022-09-25 20:27:00 +08:00
Rui Ueyama ef6e6ecdf4 Refactor 2022-09-25 17:53:44 +08:00
Rui Ueyama 9c7b95f108 [ELF] Do not page-align RELRO and TLS segments
Previously, we always aligned RELRO and TLS segments to page boundaries.
Paddings for doing that bloated up resulting output files.
2022-09-25 17:42:59 +08:00
Rui Ueyama 6f6e0a6611 Refactor 2022-09-25 14:19:38 +08:00
Rui Ueyama 3c1425fe88 [ELF] Do not set W bit to PT_TLS
Since the actual writability is controlled by the W bit of the LOAD
segments, I don't think it actually matters. But in the spirit, TLS
segment contains the initial TLS image and should not be writable.
2022-09-24 17:47:54 +08:00
Rui Ueyama 101c64b427 Downgrade required CMake version
CMake 3.13 should be reasonably old enough. Ubuntu 20.04 includes
CMake 3.16.3. I wanted to support Ubuntu 18.04's CMake, but that was
3.10.2, and that's too old.
2022-09-24 13:34:55 +08:00
Rui Ueyama 622e18bd40 Fix CI 2022-09-24 09:18:26 +08:00
Rui Ueyama 652ab0c1da Fix CI 2022-09-24 08:15:25 +08:00
Rui Ueyama 64f6a89a0d Fix CI 2022-09-23 23:06:41 +08:00
Rui Ueyama b93ad52a73 Enable separate compilation for each source file and target pair
Almost all functions and data types are template in mold, which are
parameterized to target type (e.g. X86_64 or ARM32). I'm generally
happy with that design, but there's one drawback; as we add more
targets, compilation gets slower.

Now we support more than 10 targets, so the compiler has to do 10x
more work than it originall did. As a result, compiling output-chunks.cc
(one of our largest file) took more than 30 seconds to compile on a
Threadripper machine. I hasitated to add a support for a new target
because of this problem. We needed to fix it.

This commit tweaks the build system configs so that the build system
generates bunch of intermediate .cc files. Each generated .cc file
instantiates an original .cc file for one target.

The total amount of required computation doesn't change by this hack,
but now we can parallelize the compilation step. That works well on a
modern multi-core machine.

I generally don't like to tweak build system to workaround a tool's
issue (that's why I'm creating mold in the first place), but it looks
like there's no way to speed up compilation other than this. Or,
maybe we can write a faster C++ compiler someday, but that's another
topic.
2022-09-23 22:28:40 +08:00
Rui Ueyama 6b23821276 Fix build failure if MOLD_DEBUG_X86_64_ONLY is set 2022-09-23 11:45:37 +08:00
Rui Ueyama d37bc2eb2d Merge pull request #727 from marxin/enable-compress-debug-sections-zstd-for-GCC
Enable compress-debug-sections-zstd for GCC
2022-09-22 07:09:42 -07:00
Martin Liska b5f9d936da Enable compress-debug-sections-zstd for GCC
The compression option is directly passed to linker,
so GCC can handle it as well.

Signed-off-by: Martin Liska <[email protected]>
2022-09-22 16:06:16 +02:00
Rui Ueyama 97bf734b67 Merge pull request #726 from marxin/mold-V-alignment
fix output of mold -V
2022-09-22 06:27:34 -07:00
Martin Liska 38dfad1c6f fix output of mold -V
Add missing space and remove trailing newline.

Signed-off-by: Martin Liska <[email protected]>
2022-09-22 15:10:49 +02:00
Rui Ueyama 302a9ed8d8 Add missing targets and emulations 2022-09-22 19:53:01 +08:00
Rui Ueyama 264ca5aab4 Bug fix 2022-09-22 15:56:23 +08:00
Rui Ueyama b2ffaf9294 Refactor 2022-09-22 15:08:01 +08:00
Rui Ueyama a1e0ca8a7f Refactor 2022-09-22 14:15:02 +08:00
Rui Ueyama 54f50a7cb4 Refactor 2022-09-22 12:59:41 +08:00
Rui Ueyama ae53c4202a Refactor 2022-09-22 12:44:04 +08:00
Rui Ueyama 1dd2b9e662 Update comments 2022-09-22 12:05:59 +08:00
Rui Ueyama 4d02762fd9 Add a comment 2022-09-22 11:56:17 +08:00
Rui Ueyama 218038c7a4 [ELF][RISCV] Support big-endian RISC-V targets
These are experimental, but gcc already supports them with `-mbig-endian`.
2022-09-22 11:35:37 +08:00
Rui Ueyama c320f546fe Refactor 2022-09-22 09:01:59 +08:00
Rui Ueyama 068e52859b [ELF] Rename PPC64LE PPC64V2
The original PPC64 psABI was big-endian only which is retrospectively
called the ELF v1 ABI. Around 2016, IBM decided to push little-endian
use of PowerPC platform and ratified a new psABI which is called the
ELF v2 ABI.

Changing the endianness inevitably breaks ABI compatibility, so IBM
took that chance to clean up the ABI. So the difference between v1 and
v2 are not just endianness.

However, v2 isn't technically little-endian only. You can still create
an ELFv2-based big-endian system. Such systems are not popular though.

In many systems, the original ELFv1 big-endian system is called
"ppc64" and the v2 little-endian system is called "ppc64le". But these
names are not very accurate. I think ppc64v1 and ppc64v2 (or ppc64v2le
and ppc64v2be) are more accurate.
2022-09-21 21:23:24 +08:00
Rui Ueyama 615978a132 [ELF] Emit addend if both --pack-dyn-relocs and --no-apply-dynamic-relocs are given 2022-09-21 19:48:22 +08:00
Rui Ueyama 867c285332 [ELF] Allow more than 2^11 range extension thunks
It's unlikely that we have so many range extension thunks in a single
binary, but I don't think we need to save 4 bytes here.
2022-09-21 19:27:34 +08:00
Rui Ueyama d92cef9559 Attempt to fix ASAN issue
https://github.com/rui314/mold/issues/723
2022-09-21 18:05:55 +08:00
Rui Ueyama b67335fadd Merge pull request #722 from marxin/fix-Wreorder 2022-09-21 02:01:14 -07:00
Rui Ueyama 18a424dbc9 Merge pull request #724 from marxin/fix-i586-warning 2022-09-21 02:00:48 -07:00
Martin Liska d315ff2eff fix i686 ld warning
ld: warning: out/test/elf/i686/tls-module-base-i386/a.o:
missing .note.GNU-stack section implies executable stack

Signed-off-by: Martin Liska <[email protected]>
2022-09-21 10:17:48 +02:00
Martin Liska 5c275ce843 fix -Wreoder warning
Fixes:

elf/elf.h:2107:6: warning: ‘mold::elf::SparcEB64Rela::r_type’ will be initialized after [-Wreorder]
 2107 |   u8 r_type;
      |      ^~~~~~
elf/elf.h:2106:8: warning:   ‘mold::ub24 mold::elf::SparcEB64Rela::r_type_data’ [-Wreorder]
 2106 |   ub24 r_type_data; // SPARC-specific: used for R_SPARC_OLO10

Signed-off-by: Martin Liska <[email protected]>
2022-09-21 09:57:48 +02:00
Rui Ueyama 46f74fe7ed Refactor 2022-09-21 12:11:17 +08:00
Rui Ueyama 8e922416ee Do not build with mimalloc on i386
mimalloc on i386 seems to cause a runtime error on i386.

Fixes https://github.com/rui314/mold/issues/718
2022-09-21 11:06:32 +08:00
Rui Ueyama 24affd8ed3 Refactor 2022-09-21 10:18:48 +08:00
Rui Ueyama 0e4db53774 Update comments 2022-09-21 09:38:40 +08:00
Rui Ueyama 57442144ef [ELF][SPARC] Handle more relocations 2022-09-21 09:26:33 +08:00
Rui Ueyama 3f45f68a5d Enable SPARC64 tests on GitHub Actions 2022-09-21 08:49:55 +08:00
Rui Ueyama 3625c40f04 [ELF][SPARC] Disable gdb-index tests
These tests don't pass even with GNU ld on SPARC64. gdb doesn't seem
to be able to set a breakpoint to a function in an DSO for some resaon.
2022-09-21 08:06:01 +08:00
Rui Ueyama 9094e2eee1 [ELF][SPARC] Write little-endian values to .gdb_index 2022-09-21 08:04:29 +08:00
Rui Ueyama 5e8e35940a Refactor 2022-09-21 07:34:04 +08:00
Rui Ueyama 3400567fee Update comments 2022-09-20 23:04:07 +08:00
Rui Ueyama 91ce29d30c Update comments 2022-09-20 22:58:31 +08:00
Rui Ueyama 3564b71c4f Update comments 2022-09-20 22:52:15 +08:00
Rui Ueyama e9714be08f Refactor 2022-09-20 22:10:46 +08:00
Rui Ueyama 99d6478b35 Disable on SPARC64 2022-09-20 21:00:51 +08:00
Rui Ueyama 321d8208cb [ELF][SPARC] Make LTO plugin work 2022-09-20 21:00:18 +08:00
Rui Ueyama 76ab25d486 [ELF][SPARC64] Fix struct definition 2022-09-20 18:18:31 +08:00
Rui Ueyama 3b58bf52a7 [ELF][SPARC] Fix R_SPARC_OLO10 2022-09-20 17:44:05 +08:00
Rui Ueyama ce85848867 Add more constants 2022-09-20 17:20:33 +08:00
Rui Ueyama 9784632214 [ELF][SPARC] Fix endianness issue
Bitfields are placed in an address-increasing order on both little
and big-endian hosts. Therefore, the following struct has the same
layout on both endiannesses.

  struct {
    uint32_t x : 8;
    uint32_t y : 16;
  }

The address of `x` is smaller than `y`, though you can't take an
address of a bitfield using the `&` operator in C.

However, if two bitfields are placed the same byte, they are placed in
a reverse order. In LE, bitfields are placed from LSB to MSB, while in
BE, they are placed from MSB to LSB. Therefore, members something like
this

  struct {
    uint32_t x : 4;
    uint32_t y : 4;
  }

needs to be swapped.
2022-09-20 16:04:24 +08:00
Rui Ueyama e6625d0c86 Refactor 2022-09-20 16:03:59 +08:00
Rui Ueyama 1f53fd2adf Refactor 2022-09-20 14:18:29 +08:00
Rui Ueyama c0cd1f5d58 Revert "[ELF][SPARC] Enable SPARC64 tests" to unbreak CI
This reverts commit 8c4d65179f.
2022-09-20 14:09:56 +08:00
Rui Ueyama 8c4d65179f [ELF][SPARC] Enable SPARC64 tests 2022-09-20 13:50:45 +08:00
Rui Ueyama f1ccc05c3f [ELF][SPARC] Simplify TLS handling
__tls_get_addr is not available in statically-linked executables,
so we have been relaxing all TLSGD and TLSLD relocations for static
executables. However, I noticed that it's much easier to provide a
replacement function for __tls_get_addr instead of implementing all
TLS relaxations.

With this change, all mold's unit tests pass on qemu-sparc64.
2022-09-20 13:30:52 +08:00
Rui Ueyama 46c38ca738 [ELF][SPARC] Fix .eh_frame_hdr 2022-09-20 11:32:49 +08:00
Rui Ueyama 546c552644 Fix tests 2022-09-20 11:21:21 +08:00
Rui Ueyama a1a8058b3d [ELF][SPARC] Fix TLSLD relaxation 2022-09-20 11:17:59 +08:00
Rui Ueyama d8fa5343ec [ELF][SPARC] Fix TLSGD relaxation 2022-09-20 09:45:25 +08:00
Rui Ueyama 9dcc70f6ee [ELF][SPARC] Fix more test failures 2022-09-19 21:03:37 +08:00
Rui Ueyama 139aae9444 [ELF][SPARC64] Relax R_SPARC_GOTDATA relocations 2022-09-19 17:13:21 +08:00
Rui Ueyama 956433bd8e Refactor 2022-09-19 15:33:01 +08:00
Rui Ueyama 6952ba3953 [ELF][SPARC64] Relax TLSGD and TLSLD relocations 2022-09-19 15:16:31 +08:00
Rui Ueyama 0788013cd8 [ELF] Create symbols for relocations referring mergeable section symbols
Previously, a relocation is associated either to a symbol or a section
fragment. Now, we synthesize a symbol for each unnamed piece of section
fragment and associate it to a relocation.
2022-09-19 15:16:31 +08:00
Rui Ueyama 39847a4a27 Refactor 2022-09-19 12:07:21 +08:00
Rui Ueyama 6f6a814439 Move a struct member for better packing 2022-09-19 11:10:41 +08:00
Rui Ueyama a789e48452 [ELF] Use a tagged pointer to store the origin of a pointer
A symbol can belong to an input section, an output section or a section
fragment. They are mutually exclusive, and their data structures are
aligned to at least 4 bytes boundaries. So we can use a tagged pointer
to store all of them in a single pointer-size object.
2022-09-19 11:04:00 +08:00
Rui Ueyama 7b6db0308e Merge pull request #715 from marxin/sparc64-unused-code
sparc64: remove unused code
2022-09-18 17:10:32 -07:00
Rui Ueyama 3e185623c1 Merge pull request #716 from marxin/fix-test
fix a test warning
2022-09-18 17:10:10 -07:00
Martin Liska 459cdcb6f1 fix a test warning
Fixes:
./test/elf/tls-gd2.sh: line 15: [: missing `]'

Signed-off-by: Martin Liska <[email protected]>
2022-09-18 19:22:46 +02:00
Martin Liska a9e697660b sparc64: remove unused code
Signed-off-by: Martin Liska <[email protected]>
2022-09-18 19:18:55 +02:00
Rui Ueyama dbfb584ab9 [ELF][SPARC64] Fix more tests 2022-09-18 22:23:30 +08:00
Rui Ueyama 154031af66 Refactor 2022-09-18 21:56:19 +08:00
Rui Ueyama ee11979a76 [ELF] Do not allow --no-apply-dynamic-relocs on REL-type targets 2022-09-18 21:36:50 +08:00
Rui Ueyama b87398be69 Merge pull request #712 from wangp/which
Don't use which(1) or perl
2022-09-18 06:10:54 -07:00
Rui Ueyama 982b06da2d Merge pull request #714 from marxin/fix-Worder-issues 2022-09-18 05:53:34 -07:00
Rui Ueyama 5c8cd76d2e [ELF][SPARC] Support TLS relocations 2022-09-18 19:43:46 +08:00
Rui Ueyama b28e771756 [ELF][SPARC64] Fill .plt.got contents 2022-09-18 17:26:03 +08:00
Martin Liska 1174cf7406 fix -Wreorder warnings
Fixes:

elf/elf.h: In constructor 'mold::elf::EB64Rel::EB64Rel(mold::u64, mold::u32, mold::u32, mold::i64)':
elf/elf.h:1928:8: warning: 'mold::elf::EB64Rel::r_type' will be initialized after [-Wreorder]
 1928 |   ub32 r_type;
      |        ^~~~~~
elf/elf.h:1927:8: warning:   'mold::ub32 mold::elf::EB64Rel::r_sym' [-Wreorder]
 1927 |   ub32 r_sym;
      |        ^~~~~
elf/elf.h:1923:3: warning:   when initialized here [-Wreorder]
 1923 |   EB64Rel(u64 r_offset, u32 r_type, u32 r_sym, i64 r_addend = 0)
      |   ^~~~~~~
elf/elf.h: In constructor 'mold::elf::EB32Rel::EB32Rel(mold::u64, mold::u32, mold::u32, mold::i64)':
elf/elf.h:1938:6: warning: 'mold::elf::EB32Rel::r_type' will be initialized after [-Wreorder]
 1938 |   u8 r_type;
      |      ^~~~~~

Signed-off-by: Martin Liska <[email protected]>
2022-09-18 11:01:34 +02:00
Rui Ueyama 190da9ce92 [ELF][SPARC64] Support non-position-independent executables 2022-09-18 15:26:23 +08:00
Rui Ueyama 874876ab82 Refactor 2022-09-18 13:26:29 +08:00
Rui Ueyama 4698c1364a Refactor 2022-09-18 13:04:56 +08:00
Rui Ueyama adde0130f5 [ELF] Do not promote hidden symbols to dynamic symbols
Fixes https://github.com/rui314/mold/pull/713
2022-09-18 12:32:56 +08:00
Rui Ueyama 562b52906f [ELF][SPARC64] Support more relocations
With this commit, we can now build a dynamically-linked "hello world"
program for SPARC64.
2022-09-18 12:08:26 +08:00
Peter Wang c56429b1d6 Use sed instead of perl 2022-09-17 14:00:17 +10:00
Peter Wang 7cdf0abbb3 Use command -v instead of which 2022-09-17 13:41:02 +10:00
Peter Wang d4004cf054 Directly run clang to check if available
"which clang" may find a symlink from "clang" to ccache,
thus succeeding even when clang is not installed on the system.
2022-09-17 13:40:40 +10:00
Rui Ueyama c1bdbe2327 Add a comment 2022-09-16 21:56:31 +08:00
Rui Ueyama ce78dfd4b2 Simplify 2022-09-16 21:39:01 +08:00
Rui Ueyama 2331492840 Refactor 2022-09-16 21:23:45 +08:00
Rui Ueyama a189dae361 [ELF][SPARC64] Implement features
With this commit, mold/SPARC64 can create an output file for
hello-dynamic.sh test, though the output didn't work correctly.
2022-09-16 18:06:19 +08:00
Rui Ueyama d72e96f02e [ELF] Add a stub for SPARC64 2022-09-16 14:00:21 +08:00
Rui Ueyama 1fdb13c816 [ELF] Add data types for SPARC64 2022-09-16 13:50:02 +08:00
Rui Ueyama 8af8eced16 [ELF] Rename PPC64 PPC64LE 2022-09-16 13:35:35 +08:00
Rui Ueyama d92d6c0cd7 Update comments 2022-09-16 12:36:03 +08:00
Rui Ueyama 20edf1b44b Refactor 2022-09-16 10:29:23 +08:00
Rui Ueyama 441d53c302 Refactor 2022-09-16 09:38:19 +08:00
Rui Ueyama 26168f662a Refactor 2022-09-16 08:51:30 +08:00
Rui Ueyama 2af061f7fd Update comments 2022-09-15 19:53:47 +08:00
Rui Ueyama fea0734c41 Use one more word for each symbol
I don't think saving 32 bits here doesn't worth the cost of worrying
about possible integer overflow.
2022-09-15 18:03:40 +08:00
Rui Ueyama f0f8b30a2d Create an Docker multi-architecture build image
So that we can create binary distribution images on any machine.
2022-09-15 15:30:21 +08:00
Rui Ueyama 9d748ba967 Do not depend on compiler optimization too much
This is a performance critical part, and I started to think that
depending on a smart compiler optimization is a bit too risky.
2022-09-15 12:50:02 +08:00
Rui Ueyama 37863ccbaf Update comments 2022-09-15 11:52:37 +08:00
Rui Ueyama fb5b828996 Simplify 2022-09-15 11:20:57 +08:00
Rui Ueyama 7d36399035 Merge branch 'marxin-use-CC-in-tests' 2022-09-15 10:03:07 +08:00
Martin Liska 0825208628 tests: fix test/elf/exception-mcmodel-large.sh
Fix syntax error:
line 31: int main() {}: command not found

Signed-off-by: Martin Liska <[email protected]>
2022-09-15 10:02:39 +08:00
Rui Ueyama 86d67b1b17 Simplify 2022-09-15 10:02:22 +08:00
Rui Ueyama 8612d411d1 Refactor 2022-09-15 10:02:22 +08:00
Rui Ueyama 3fd9ca553b Merge pull request #710 from marxin/fix-a-test
tests: fix test/elf/exception-mcmodel-large.sh
2022-09-14 18:50:16 -07:00
Rui Ueyama 62c077924a Simplify 2022-09-15 09:14:13 +08:00
Rui Ueyama 3795b71350 Refactor 2022-09-15 08:52:46 +08:00
Martin Liska bcb21edcb1 tests: use $CC instead of cc
Signed-off-by: Martin Liska <[email protected]>
2022-09-14 21:46:41 +02:00
Martin Liska 30617cc632 tests: fix test/elf/exception-mcmodel-large.sh
Fix syntax error:
line 31: int main() {}: command not found

Signed-off-by: Martin Liska <[email protected]>
2022-09-14 21:46:20 +02:00
Rui Ueyama 183e4db696 Support big-endian hosts
Note that we do not support any big-endian targets. This commit enables
users to use mold to cross compile little-endian binaries on big-endian
hosts.
2022-09-14 21:43:29 +08:00
Rui Ueyama 1b9dc06150 Revert "Enable IFUNC tests on RISC-V" to fix CI
This reverts commit 70b69b2698.
2022-09-14 18:24:39 +08:00
Rui Ueyama 34b63e7f92 Fix CI 2022-09-14 17:57:20 +08:00
Rui Ueyama 045bc58da5 Simplify 2022-09-14 17:55:43 +08:00
Rui Ueyama 70b69b2698 Enable IFUNC tests on RISC-V 2022-09-14 17:45:37 +08:00
Rui Ueyama 0856d3f76e Check if $CC accepts -static
Fixes https://github.com/rui314/mold/issues/707
2022-09-14 17:24:48 +08:00
Rui Ueyama f8176051c1 Simplify 2022-09-14 16:26:39 +08:00
Rui Ueyama 80f2c66413 Simplify 2022-09-14 16:19:10 +08:00
Rui Ueyama e00ddceda2 Simplify 2022-09-14 16:08:10 +08:00
Rui Ueyama 9e6e472b2a Attempt to suppress GCC's -Walloc-size-larger-than warnings
https://github.com/rui314/mold/issues/708
2022-09-14 15:20:29 +08:00
Rui Ueyama c55e1216b8 Disable -Wsign-compare and -Wunused-function
https://github.com/rui314/mold/issues/708
2022-09-14 15:12:50 +08:00
Rui Ueyama 07636727c7 Fix -Wunused-variable warnings
https://github.com/rui314/mold/issues/708
2022-09-14 15:00:49 +08:00
Rui Ueyama 75c142f321 Fix GCC's -Wclass-memaccess warnings
GCC prints out bunch of the following warnings when compiling mold.

```
macho/input-files.cc:717:11: warning: 'void* memset(void*, int, size_t)'
  clearing an object of non-trivial type 'struct mold::macho::MachSection';
  use assignment or value-initialization instead [-Wclass-memaccess]

  717 |     memset(hdr, 0, sizeof(*hdr));
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~
```

This commit suppresses it by making our classes trivial.

https://github.com/rui314/mold/issues/708
2022-09-14 14:49:42 +08:00
Rui Ueyama 8e2e6d8603 Set LIBDIR for mold-wrapper.so
Fixes https://github.com/rui314/mold/issues/697
2022-09-14 14:28:17 +08:00
Rui Ueyama fdcb3c2efe Refactor 2022-09-14 14:10:36 +08:00
Rui Ueyama b4c148dd0c Do not over-specify distro version 2022-09-14 11:24:23 +08:00
Rui Ueyama 4e5fe38a2d Simplify 2022-09-14 11:17:07 +08:00
Rui Ueyama 9fd8313657 Simplify 2022-09-13 17:27:37 +08:00
Rui Ueyama 6a71ec6804 Fix CI 2022-09-13 16:21:22 +08:00
Rui Ueyama 896e49cc9e Update the man page 2022-09-13 15:53:03 +08:00
Rui Ueyama 258ec353b0 [ELF] Support reading ZSTD-compressed debug info section 2022-09-13 15:47:59 +08:00
Rui Ueyama 7b9bfe08a6 [ELF] Delete support of .zdebug-style compressed debug sections
lld 15 stopped supporting it since its usage is very low if not none.

https://reviews.llvm.org/D126793
2022-09-13 15:47:59 +08:00
Rui Ueyama a3512e6636 Fix CI 2022-09-13 15:47:59 +08:00
Rui Ueyama 145369e1f1 Fix CI 2022-09-13 15:33:39 +08:00
Rui Ueyama 26591cfd41 Fix CI 2022-09-13 15:09:14 +08:00
Rui Ueyama c8abc0f189 Suppress compiler warnings 2022-09-13 14:55:20 +08:00
Rui Ueyama ede7a5aaa3 [ELF] Support --compress-debug-sections=zstd
Fixes https://github.com/rui314/mold/issues/700
2022-09-13 14:55:20 +08:00
Rui Ueyama 5919914c54 Add libzstd to support --compress-debug-sections=zstd 2022-09-13 14:55:17 +08:00
Rui Ueyama 34bd56e15b Update comments 2022-09-13 13:10:02 +08:00
Rui Ueyama da550493b6 Refactor 2022-09-13 13:04:35 +08:00
Rui Ueyama b1055b42b7 Refactor 2022-09-13 11:58:14 +08:00
Rui Ueyama b941a37b1e Make addresses given to --start-address multiples of 65536
On PPC64, page size is 65536 bytes or 0x10000 bytes.

https://github.com/rui314/mold/issues/554
2022-09-12 19:37:58 +08:00
Rui Ueyama c0ff4a246b [ELF][PPC64] Handle R_PPC64_DTPREL64 against non-alloc sections
https://github.com/rui314/mold/issues/554
2022-09-12 16:27:00 +08:00
Rui Ueyama ed1acd31c8 Do not use fgrep or egrep
fgrep and egrep are deprecated.

Fixes https://github.com/rui314/mold/issues/705
2022-09-12 16:22:55 +08:00
Rui Ueyama cda57cfe4a [ELF] Do not create multiple NOTE segments 2022-09-12 15:58:20 +08:00
Rui Ueyama 428aac7458 Update comments 2022-09-12 15:07:53 +08:00
Rui Ueyama 629f2157dd Update comments 2022-09-12 14:43:32 +08:00
Rui Ueyama 8dc8ddb5d4 Update comments 2022-09-12 14:18:27 +08:00
Rui Ueyama d4c7062bd4 Simplify 2022-09-12 13:11:32 +08:00
Rui Ueyama bbf591288e Add a comment 2022-09-12 13:06:15 +08:00
Rui Ueyama f702c398b2 Update comments 2022-09-12 12:16:45 +08:00
Rui Ueyama a5eb8b9d24 [ELF][PPC64] REL24's range is not 2^23 but 2^25 2022-09-12 10:33:38 +08:00
Rui Ueyama 56c7761485 Simplify 2022-09-12 10:22:04 +08:00
Rui Ueyama 6d588cc3a8 [ELF] Add more error checks 2022-09-11 20:42:47 +08:00
Rui Ueyama e01f8b4993 [ELF] Add more error checks 2022-09-11 19:33:53 +08:00
Rui Ueyama cbf786bb59 Simplify 2022-09-11 18:24:32 +08:00
Rui Ueyama 2ee1b530b6 Update comments 2022-09-11 17:39:16 +08:00
Rui Ueyama b96a4150d9 [ELF][x86] Simplify TLS relaxation
Previously, TLSLD relocation on i386/x86-64 produced different values
than it normally does if it's relaxed. If relaxed, it's evaluated to
TP, which is the end address of the TLS block. If not relaxed, it's
evaluated to the beginning of the TLS block.

As a result, we needed to adjust subsequent DTPOFF relocations so that
it is based on the end of the TLS block only when the corresponding
symbol was relaxed. This is very tricky.

I believe the psABI TLS spec specifies this way because they couldn't
find a replacement instruction sequence that is equal to or shorter
then the replacing instructions. `mov %fs:0, %rax` is 9 bytes long,
so it barely fits the location where a TLSLD refers to.

I found that `xor %eax, %eax; mov %fs(%rax), %rax` is shorter than
`mov %fs:0, %rax` while it yields the same value. The two instructions
are 5 bytes in total. By saving 4 bytes, we can now add another `add`
instruction to adjust the resulting value, so that the result is always
relative to the beginning of the TLS block.
2022-09-11 16:40:02 +08:00
Rui Ueyama a6777e9c50 Refactor 2022-09-11 16:33:19 +08:00
Rui Ueyama 20effdc21c [ELF][i386] Enable more TLS tests 2022-09-11 16:04:42 +08:00
Rui Ueyama c7ad760534 Add comments 2022-09-11 11:49:27 +08:00
Rui Ueyama 7406b18042 Add a test 2022-09-11 11:35:49 +08:00
Rui Ueyama c97d6088e5 Remove dead code
https://github.com/rui314/mold/pull/703
2022-09-11 10:36:20 +08:00
Rui Ueyama 01240db538 Simplify 2022-09-11 10:14:41 +08:00
Rui Ueyama 055e2423e5 Update comments 2022-09-10 21:11:34 +08:00
Rui Ueyama ac7a7cb1f3 Update comments 2022-09-10 20:52:43 +08:00
Rui Ueyama fe59dc9dff [ELF][PPC64] Create range extension thunks for unreachable branches
With this, all tests pass on PPC64. We need to support TOC-less
functions, though.
2022-09-10 19:55:44 +08:00
Rui Ueyama 3bf132f7ed Revert "Improve a test"
This reverts commit 100fcaebf4 to unbreak CI.
2022-09-10 19:54:17 +08:00
Rui Ueyama 100fcaebf4 Improve a test 2022-09-10 19:17:24 +08:00
Rui Ueyama 1b3e0fe0fb Update a test 2022-09-10 18:18:54 +08:00
Rui Ueyama b0776d9496 Style changes 2022-09-10 17:59:13 +08:00
Rui Ueyama 7b6dc763ad Update a help message 2022-09-10 17:44:41 +08:00
Rui Ueyama 43e3aa24ef Merge pull request #701 from rod-salazar/lto_lib_doc_text
Remove 'Ignored' helptext for lto_library and order_file
2022-09-10 02:42:39 -07:00
Rui Ueyama 1cbae48a29 Style changes 2022-09-10 17:34:55 +08:00
Rui Ueyama 623549ff45 Style changes 2022-09-10 17:31:38 +08:00
Rodrigo Salazar 042910a848 Remove 'Ignored' helptext for lto_library and order_file 2022-09-10 02:20:39 -07:00
Rui Ueyama 0f7c87ca03 Add a comment 2022-09-10 16:43:17 +08:00
Rui Ueyama febb696a39 [ELF][PPC64] Enable PPC64 tests if -DMOLD_ENABLE_QEMU_TESTS is specified 2022-09-10 15:59:24 +08:00
Rui Ueyama 594dd50246 Simplify 2022-09-10 15:57:52 +08:00
Rui Ueyama 6aa2c56497 [ELF][PPC64] Enable CI 2022-09-10 15:39:28 +08:00
Rui Ueyama 5ca3d4bf48 [ELF][PPC64] Handle .toc just like .got 2022-09-10 15:35:15 +08:00
Rui Ueyama a3a0582ac4 Fix CI 2022-09-10 14:32:51 +08:00
Rui Ueyama 6b5f0f1c92 [ELF][PPC64] Fix various issues for ppc64 2022-09-10 13:47:28 +08:00
Rui Ueyama 5dcb2b634e Improve error messages 2022-09-09 21:07:22 +08:00
Rui Ueyama aa9cab8323 Simplify 2022-09-09 20:45:19 +08:00
Rui Ueyama d739547feb [ELF][PPC64] Handle relocations against non-alloc sections 2022-09-09 20:02:53 +08:00
Rui Ueyama 20d80b806a [ELF][PPC64] Remove an unnecessary padding from .plt.got 2022-09-09 19:33:33 +08:00
Rui Ueyama 21be1d7d5e Update comments 2022-09-09 19:24:54 +08:00
Rui Ueyama 1227897ab0 Update README 2022-09-09 18:08:02 +08:00
Rui Ueyama 3cd25344a8 Simplify 2022-09-09 17:55:46 +08:00
Rui Ueyama 3e02327858 Fix invalid uses of a relocation 2022-09-09 17:52:42 +08:00
Rui Ueyama c8013ae871 Update comments 2022-09-09 17:49:32 +08:00
Rui Ueyama 98b35d3793 [ELF][PPC64] Add R_PPC64_TLSLD, R_PPC64_DTPREL16_HA and R_PPC64_DTPREL16_LO 2022-09-09 17:23:24 +08:00
Rui Ueyama 5a8181f7ff [ELF][PPC64] Add R_PPC64_GOT_TLSLD16_HA 2022-09-09 17:19:18 +08:00
Rui Ueyama f38e131242 [ELF][PPC64] Add R_PPC64_REL64 2022-09-09 17:15:35 +08:00
Rui Ueyama 2dd6bbbb3d [ELF][PPC64] Restore r2 after function call 2022-09-09 17:09:20 +08:00
Rui Ueyama 87e2e06530 Add links to psABI documents 2022-09-09 14:24:02 +08:00
Rui Ueyama 678dcfb748 Update comments 2022-09-09 12:57:19 +08:00
Rui Ueyama 7b4afc48ff [ELF][PPC64] Fix PLT contents
With this change, tests/elf/hello-dynamic.sh passes.
2022-09-09 12:47:03 +08:00
Rui Ueyama fda84aa648 Simplify 2022-09-09 07:46:04 +08:00
Rui Ueyama 12b5699750 Add a comment 2022-09-08 21:51:11 +08:00
Rui Ueyama aa300ae973 [ELF][PPC64] Remove an unnecessary section 2022-09-08 21:36:57 +08:00
Rui Ueyama c1de2d53dc [ELF][PPC64] Do not disk space to .got.plt 2022-09-08 19:29:17 +08:00
Rui Ueyama da7c3f878f Style changes 2022-09-08 17:31:52 +08:00
Rui Ueyama 5bf05b5f45 Merge pull request #699 from ksco/eh-frame-hdr
Fix --no-eh-frame-hdr option
2022-09-08 02:28:24 -07:00
Yang Liu 410e1633e2 Add a no-eh-frame-header test
Signed-off-by: Yang Liu <[email protected]>
2022-09-08 17:07:12 +08:00
Yang Liu 5871018d10 Fix --no-eh-frame-hdr
Signed-off-by: Yang Liu <[email protected]>
2022-09-08 17:07:12 +08:00
Rui Ueyama 2940d93123 Remove dead code 2022-09-08 17:02:04 +08:00
Rui Ueyama be0131fc63 [ELF] Add initial PPC64LE support 2022-09-08 16:57:59 +08:00
Rui Ueyama 4d8d3fda55 Refactor 2022-09-08 16:57:59 +08:00
Rui Ueyama 28f89b0a4f Merge pull request #698 from ksco/global-pointer
Fix global-pointer value
2022-09-08 00:05:18 -07:00
Yang Liu 906abcedee Fix global-pointer value
Global-pointer's value should be .sdata+0x800.

Signed-off-by: Yang Liu <[email protected]>
2022-09-08 14:24:35 +08:00
Rui Ueyama 1950def5f9 Refactor 2022-09-06 21:19:56 +08:00
Rui Ueyama 692fe9af1e Update comments 2022-09-06 18:15:57 +08:00
Rui Ueyama ff6afd39e0 Simplify 2022-09-06 18:03:03 +08:00
Rui Ueyama a712f91a03 Rename a variable 2022-09-06 13:24:20 +08:00
Rui Ueyama 8c7f31cafa [ELF] Copy ELF st_type when creating symbol aliases for --defsym
Fixes https://github.com/rui314/mold/issues/695
2022-09-06 12:54:34 +08:00
Rui Ueyama eede5a08b0 Update comments 2022-09-06 10:18:39 +08:00
Rui Ueyama ecdb6034af Update comments 2022-09-05 20:50:04 +08:00
Rui Ueyama 85d496dd45 Update a comment 2022-09-05 20:42:29 +08:00
Rui Ueyama 00273f3d0c Simplify 2022-09-05 20:21:43 +08:00
Rui Ueyama 7cad171a34 Rename functions 2022-09-05 20:17:05 +08:00
Rui Ueyama 1d0c1f8f32 [ELF] Add overflow checks 2022-09-05 20:16:00 +08:00
Rui Ueyama 7ffdcd49d8 [ELF] Set a unique dummy value to linker-synthesized symbols 2022-09-05 17:33:34 +08:00
Rui Ueyama bb0e601eaa Avoid GNU assembler's bug
Looks like GNU assembler produces illegal code and relocations for
_GLOBAL_OFFSET_TABLE, so we can't directly use that symbol in our
tests.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106834
2022-09-05 17:06:19 +08:00
Rui Ueyama f34c345c7c Move code so that the relocations are in the same order in all switch-cases 2022-09-05 14:43:35 +08:00
Rui Ueyama d2bba23541 Update comments 2022-09-05 14:21:54 +08:00
Rui Ueyama fc49faa896 Style changes 2022-09-05 14:19:36 +08:00
Rui Ueyama ddbf501a66 Merge pull request #687 from ksco/relax
[RISCV] Add zero-page relaxation
2022-09-04 22:58:42 -07:00
Rui Ueyama be13b5de4a [ELF] Replace branch instructions with NOPs 2022-09-05 13:44:53 +08:00
Rui Ueyama 72e26d9b69 [ELF] Do not convert a call with a weak undef to a nop in DSO
On ARM, calling an remaining weak undefined symbol is a NOP. But
if such symbol was promoted to a dynamic symbol, we need to execute
that call instruction instead of converting to a NOP because it may
be resolved to a defined symbol at runtime.

Fixes https://github.com/rui314/mold/issues/660
2022-09-05 13:34:59 +08:00
Rui Ueyama 6d51493e46 [ELF] Avoid accidental string prefix matches 2022-09-05 10:10:20 +08:00
Rui Ueyama 25c7aee1d9 [ELF] Merge .rodata mergeable strings to .rodata.str
Fixes https://github.com/rui314/mold/issues/511
2022-09-05 09:46:58 +08:00
Rui Ueyama fafc0d0b94 Simplify 2022-09-04 20:34:44 +08:00
Rui Ueyama 8d16301665 [ELF][RISC-V] Do not allocate r_deltas for non-executable sections
RISC-V relocations are relaxed only for executable code sections,
so we don't need to allocate r_deltas for non-executable sections.
2022-09-04 19:23:02 +08:00
Rui Ueyama 98042443ac Simplify 2022-09-04 19:19:43 +08:00
Rui Ueyama 2c86726c06 Suppress a dynamic linker's warning message
glibc started printing out the following warning message on process
startup, starting from glibc 2.36:

  warning: direct reference to protected function `baz' in
  `out/test/elf/x86_64/protected/b.so' may break pointer equality

It does so if it finds there's a canonical PLT against a protected
symbol. The warning message itself makes sense -- there's no way to
create a canonical PLT against a protected symbol while keeping
pointer equality, and you should recompile object files with `-fPIC`
to suppress this warning.

However, in this test, we intentionally create a canonical PLT against
a protected symbol, so we just want to silence it.

Fixes https://github.com/rui314/mold/issues/689
2022-09-04 17:54:51 +08:00
Rui Ueyama ba43a01c8c Merge pull request #690 from ksco/script-test
Improve linker-script-defsym tests
2022-09-04 02:48:41 -07:00
Yang Liu c1dc0e6c2d Improve linker-script-defsym tests
Signed-off-by: Yang Liu <[email protected]>
2022-09-04 17:42:48 +08:00
Rui Ueyama 3ab548971f [ELF] Make riscv_resize_sections faster
We saw a significant performance improvement with this commit. Here
is before and after numbers when cross-building mold for RV32 on a
simulated 16-core machine:

  $ time ./mold.old @rsp
  real    0m45.216s
  user    0m0.016s
  sys     0m0.000s

  $ time ./mold.new @rsp
  real    0m0.240s
  user    0m0.014s
  sys     0m0.003s

  $ ls -lh mold
  -rwxrwxr-x 1 ruiu ruiu 152M Sep  4 17:16 mold
2022-09-04 17:24:07 +08:00
Yang Liu b6549580be [RISCV] Add zero-page relaxation
Signed-off-by: Yang Liu <[email protected]>
2022-09-04 16:02:53 +08:00
Rui Ueyama 807af97a4b Revert "wip" which was made by mistake 2022-09-04 15:46:46 +08:00
Rui Ueyama 682fc41c0d [ELF] Do not try to relax dead input sections
It's just a waste of time.
2022-09-04 15:31:13 +08:00
Rui Ueyama ff0679f7b8 wip 2022-09-04 15:03:03 +08:00
Rui Ueyama b7bfe418ba Bump mold version to 1.4.2 2022-09-04 12:59:58 +08:00
Rui Ueyama 05f8bcff31 Improve comments 2022-09-04 09:58:04 +08:00
Rui Ueyama d148db3c2d Fix GCC's -Woverflow warnings 2022-09-04 09:16:48 +08:00
Yang Liu e58f55959d Update comments 2022-09-04 02:06:09 +08:00
Yang Liu 9507f11f77 Remove redundant code 2022-09-04 02:06:09 +08:00
Yang Liu 114fb21b8e Update comments
Signed-off-by: Yang Liu <[email protected]>
2022-09-04 02:06:09 +08:00
Rui Ueyama 29f054c49c Fix comment 2022-09-03 20:21:38 +08:00
Rui Ueyama fc38c15897 Update comments 2022-09-03 20:01:07 +08:00
Rui Ueyama 4528abc1c9 [ELF][ARM32] Change the way how we compute TLSDESC trampoline address 2022-09-03 19:55:33 +08:00
Rui Ueyama a83985c3b3 Update comments 2022-09-03 17:09:10 +08:00
Rui Ueyama 0beba29082 Update comments 2022-09-03 16:35:00 +08:00
Rui Ueyama 62ee0b8d72 Remove a redundant command 2022-09-03 16:25:25 +08:00
Rui Ueyama 0b42416868 Fix CI 2022-09-03 16:16:51 +08:00
Rui Ueyama 6cd5eb93b6 Merge pull request #686 from ericriff/eriff/fix-cmake-system-mimalloc
Fix build error while using the system version of mimalloc and CMake
2022-09-03 01:16:43 -07:00
Rui Ueyama ef7c698713 Simplify 2022-09-03 16:04:46 +08:00
Rui Ueyama 97bea18e5a Simplify 2022-09-03 15:33:13 +08:00
Rui Ueyama b8855f0749 Simplify 2022-09-03 15:10:59 +08:00
Rui Ueyama 78d65510ff Fix CI 2022-09-03 13:56:30 +08:00
Rui Ueyama 13808663cc [ELF] Reduce the size of a per-relocation object 2022-09-03 13:49:29 +08:00
Rui Ueyama 645c8f9931 [ELF] Avoid "relocation out of range" error for TLS trampoline 2022-09-03 13:34:53 +08:00
Rui Ueyama 1f7553d53b [ELF] Support R_ARM_TLS_CALL 2022-09-03 12:44:07 +08:00
Rui Ueyama cf208a531e Do not always skip range-extension-thunk-arm32 test 2022-09-03 12:44:06 +08:00
Riff, Eric 2fae57c4d2 Address 'Cannot specify compile definitions for target "mimalloc" which is not built by this project.' CMake error 2022-09-02 13:20:37 -03:00
Rui Ueyama 1408e6ab6c Update comments 2022-09-02 20:04:25 +08:00
Rui Ueyama 994af8db20 Update comments 2022-09-02 19:59:15 +08:00
Rui Ueyama fccf3902e0 Add comments 2022-09-02 19:37:01 +08:00
Rui Ueyama f667b0c4b9 Merge pull request #684 from ksco/tls
[RISCV] Enable tls-gd-noplt tests for RV32 and RV64
2022-09-02 04:09:00 -07:00
Yang Liu 66dfce5d03 [RISCV] Enable tls-gd-noplt tests for RV32 and RV64
Signed-off-by: Yang Liu <[email protected]>
2022-09-02 18:24:11 +08:00
Rui Ueyama 7c32e613e8 Merge pull request #683 from ksco/tls 2022-09-02 03:19:11 -07:00
Yang Liu a0dc74bb87 [RISCV] Enable tls tests for RV32 and RV64
Signed-off-by: Yang Liu <[email protected]>
2022-09-02 18:16:46 +08:00
Rui Ueyama 96524e48fd [ELF] Fix RISC-V TLSGD relocation
For RISC-V, DTPOFF is computed 0x800 off from the start of each TLS block
to maximize the accessible range for memory access instructions with
signed 12-bit immediate. DTPMOD is usually computed by the dynamic loader,
but when we do for static binaries, we need to subtract 0x800 to offset
the offset.

https://github.com/rui314/mold/issues/461
2022-09-02 17:57:40 +08:00
Rui Ueyama b48d3d3da3 Rename a variable 2022-09-02 17:57:40 +08:00
Rui Ueyama 899e6c5e6e Merge pull request #682 from ksco/linker-script
Fix missing parameter in linker script tests
2022-09-02 01:36:45 -07:00
Rui Ueyama 6ae335f379 Refactor 2022-09-02 16:22:30 +08:00
Yang Liu 0d2a258e77 Fix missing parameter in linker script tests
Signed-off-by: Yang Liu <[email protected]>
2022-09-02 16:12:44 +08:00
Rui Ueyama df521f2a04 Refactor 2022-09-02 16:08:50 +08:00
Rui Ueyama fb71467574 Refactor 2022-09-02 15:57:48 +08:00
Rui Ueyama 62511ae2c3 [ELF] Reduce the alignment of thunks 2022-09-02 15:46:00 +08:00
Rui Ueyama b23ae9de2a Fix test for Raspberry Pi 4 2022-09-02 15:19:44 +08:00
Rui Ueyama ceeec0e1da Move an assignmen out of a loop 2022-09-02 14:28:39 +08:00
Rui Ueyama 56bacad887 Improve comments 2022-09-02 13:47:47 +08:00
Rui Ueyama a6c0aba80b Improve test coverage 2022-09-02 13:12:52 +08:00
Rui Ueyama e989b57f8f [ELF] Add tests for range extension thunks 2022-09-02 12:58:26 +08:00
Rui Ueyama 5403df8cfa [ELF] Implement range extension thunks for ARM32
Previously, we couldn't create an executable whose .text is larger
than 16 MiB.
2022-09-02 12:33:04 +08:00
Rui Ueyama 0069fff8a5 [ELF] Do not call get_eflags for each relaxable relocation 2022-09-01 21:50:53 +08:00
Rui Ueyama 4a2f6574f4 Refactor
Make it consistent with arch-x86-64.cc.
2022-09-01 21:50:48 +08:00
Rui Ueyama b6bd7b83f0 Merge pull request #681 from ksco/rvc
[RISCV] Check rvc support when relaxing R_RISCV_CALL_PLT
2022-09-01 06:27:48 -07:00
Rui Ueyama 017f2492bf Merge pull request #680 from ksco/check
[RISCV] Check relocation range
2022-09-01 06:05:27 -07:00
Yang Liu c7534f49f1 [RISCV] Add a no RVC test
Signed-off-by: Yang Liu <[email protected]>
2022-09-01 20:53:45 +08:00
Yang Liu eb2f02c2e2 [RISCV] Check rvc support when relaxing R_RISCV_CALL_PLT
Signed-off-by: Yang Liu <[email protected]>
2022-09-01 20:53:45 +08:00
Yang Liu 9e303fd8ac [RISCV] Check relocation range
Signed-off-by: Yang Liu <[email protected]>
2022-09-01 19:37:24 +08:00
Rui Ueyama df1b8d9f56 Remove dead code 2022-09-01 14:37:04 +08:00
Rui Ueyama ea779c36a4 [ELF] Fix build issue on Raspberry Pi 4
We need -latomic on ARMv7.
2022-09-01 12:18:37 +08:00
Rui Ueyama 1a0a242c45 Add Rasbian OS 2022-09-01 12:02:59 +08:00
Rui Ueyama 2fa850ceeb Simplify 2022-09-01 10:26:24 +08:00
Rui Ueyama 7e56070c77 Update a comment 2022-09-01 10:25:10 +08:00
Rui Ueyama a557877fb5 [ELF] Do not allocate disk space for a virtual address space hole
Previously, if a large address is specified by --start-address, we
created a large file.

Fixes https://github.com/rui314/mold/issues/676
2022-08-31 17:43:55 +08:00
Rui Ueyama 5f2a4a0498 Update comments 2022-08-31 14:36:24 +08:00
Rui Ueyama 099f85a29d [ELF][RISC-V] Relax R_RISCV_TPREL_HI20 and R_RISCV_TPREL_ADD 2022-08-31 14:15:50 +08:00
Rui Ueyama f0d0cd5b1c Revert "[ELF][RISC-V] Implement LUI → C.LUI or C.LI relaxation"
This reverts commit a96657bcac to unbreak CI.
2022-08-31 13:00:43 +08:00
Rui Ueyama a96657bcac [ELF][RISC-V] Implement LUI → C.LUI or C.LI relaxation
This is a re-submission of c625e28e1c.
2022-08-31 12:49:05 +08:00
Rui Ueyama d887569522 Revert "[ELF][RISC-V] Implement LUI → C.LUI or C.LI relaxation"
This reverts commit c625e28e1c to unbreak CI.
2022-08-31 11:44:51 +08:00
Rui Ueyama c625e28e1c [ELF][RISC-V] Implement LUI → C.LUI or C.LI relaxation 2022-08-31 10:54:21 +08:00
Rui Ueyama 8b45ffe17a Simplify 2022-08-31 10:00:05 +08:00
Rui Ueyama c79f58856f Update a comment 2022-08-30 20:38:24 +08:00
Rui Ueyama 78f8832acf Simplify 2022-08-30 20:29:58 +08:00
Rui Ueyama 4c760cd87f Rename functions 2022-08-30 19:43:03 +08:00
Rui Ueyama e06e6b474d Simplify 2022-08-30 14:12:49 +08:00
Rui Ueyama 10a9a6bafb [ELF] C.J and C.JAL can jump within ±2 KiB
The number of bits of the operand is 11 bits, but since the least
significant bit is always zero and omitted, the effective number
of bits is 12.
2022-08-30 14:02:58 +08:00
Rui Ueyama e6b1e6d7ec Refactor
r_deltas contained negative numbers. This commit inverts them.
2022-08-30 13:49:34 +08:00
Rui Ueyama 34bdfeb69f [ELF] Parallelize RISC-V relaxation 2022-08-30 13:49:34 +08:00
Rui Ueyama 4c5cad43fb [ELF] Make the output deterministic
Mutating symbols values in this loop is not safe because we also
read symbol values in the same loop.
2022-08-29 21:29:38 +08:00
Rui Ueyama 09d12639b4 Refactor 2022-08-29 20:07:28 +08:00
Rui Ueyama 2f38ebd1cc Format 2022-08-29 20:02:39 +08:00
Rui Ueyama 136f32ac2e Do not create a circular symlink 2022-08-29 19:24:41 +08:00
Rui Ueyama cddbdba091 Fix CI 2022-08-29 19:02:21 +08:00
Rui Ueyama 99090d0e37 Archive object files for tests 2022-08-29 18:01:53 +08:00
Rui Ueyama 9598ba4d25 Archive test results even if tests failed 2022-08-29 17:36:09 +08:00
Rui Ueyama c43f648fa1 Add a comment 2022-08-29 17:33:07 +08:00
Rui Ueyama 82564cb571 Simplify 2022-08-29 17:06:23 +08:00
Rui Ueyama e791b34d50 Simplify 2022-08-29 16:51:00 +08:00
Rui Ueyama 584837e294 Make test results downloadable 2022-08-29 14:51:09 +08:00
Rui Ueyama 037d6e6d22 Simplify 2022-08-29 14:43:29 +08:00
Rui Ueyama f08bc94618 Fix comment 2022-08-29 13:24:27 +08:00
Rui Ueyama 14bf89918c Remove redundnat chmod 2022-08-29 13:21:20 +08:00
Rui Ueyama 33d8657270 Merge pull request #675 from ksco/tailcall
Add tail call test
2022-08-28 22:20:41 -07:00
Yang Liu 9de22f8945 Add tail call test
Signed-off-by: Yang Liu <[email protected]>
2022-08-29 13:03:00 +08:00
Rui Ueyama bd5fb9ec9b Rename a function 2022-08-29 12:55:47 +08:00
Rui Ueyama e8453216cf Simplify 2022-08-29 12:54:48 +08:00
Rui Ueyama c39b9bb100 Make log message less verbose 2022-08-29 12:47:14 +08:00
Rui Ueyama 6eac1e60ad Fix CI 2022-08-29 12:37:23 +08:00
Rui Ueyama 00aa3124cd [ELF] Detect an error
Distance between two instructions on RISC-V should be a multiple of two
because instructions are aligned to at least two bytes boundaries.
2022-08-29 12:10:11 +08:00
Rui Ueyama 3ad19a7555 Simplify 2022-08-29 11:30:27 +08:00
Rui Ueyama d1babd0682 Style changes 2022-08-29 11:15:27 +08:00
Rui Ueyama 8999732344 Merge pull request #672 from ksco/relax
[RISCV] Relax AUIPC+JALR to C.JAL or C.J
2022-08-28 19:48:49 -07:00
Rui Ueyama 667d1e7d6e Update RV32 tests 2022-08-29 10:39:55 +08:00
Rui Ueyama f189ea805c Remove an unnecessary apt-get line 2022-08-29 10:33:48 +08:00
Rui Ueyama 1fc86d7905 Run RV32 tests on CI
https://github.com/rui314/mold/pull/672
2022-08-29 10:29:07 +08:00
Rui Ueyama e54d7e9761 Merge pull request #673 from ksco/make 2022-08-28 04:07:28 -07:00
Yang Liu 538239e1c2 [RISCV] Relax AUIPC+JALR to C.JAL or C.J
Signed-off-by: Yang Liu <[email protected]>
2022-08-28 18:34:02 +08:00
Yang Liu 3de6eb920c Add MOLD_ENABLE_RV32_QEMU_TESTS option
Signed-off-by: Yang Liu <[email protected]>
2022-08-28 18:25:52 +08:00
Rui Ueyama 91d40e07fc Simplify 2022-08-28 18:20:47 +08:00
Rui Ueyama 70b5a69f31 Simplify 2022-08-28 17:48:27 +08:00
Rui Ueyama 0604f638ea [ELF] R_RISCV_ALIGN should align the next insn to r_addend + 1 2022-08-28 17:46:29 +08:00
Rui Ueyama 00a004d698 Simplify 2022-08-28 15:02:55 +08:00
Rui Ueyama cef99ce48f Merge pull request #671 from ksco/rv64-relax-fix
[RV64] Fix jalr assemble error
2022-08-27 23:46:50 -07:00
Yang Liu 6f78946a15 [RV64] Fix jalr assemble error
Signed-off-by: Yang Liu <[email protected]>
2022-08-28 12:26:55 +08:00
Rui Ueyama 0a4586ab96 Merge pull request #670 from ksco/rv32gc-strip-fix
[RV32] Skip all test cases not applicable to RV32
2022-08-27 18:21:40 -07:00
Yang Liu ec5da29d17 [RV32] Skip all test cases not applicable to RV32
Signed-off-by: Yang Liu <[email protected]>
2022-08-28 08:42:02 +08:00
Rui Ueyama 63115cfa34 Merge pull request #669 from ksco/rv32gc
[RV32] Fix PLT header
2022-08-27 15:46:27 -07:00
Yang Liu ce849a2e5f [RV32] Fix PLT header
According to spec[1], .got.plt offset is lg2(16/PTRSIZE), under RV32 it is 2.

[1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc#program-linkage-table

Signed-off-by: Yang Liu <[email protected]>
2022-08-27 21:04:25 +08:00
Rui Ueyama bbafdc3d23 Revert "[RISCV32] Fix R_RISCV_HI20 relocations"
This reverts commit e65cc7feea because
I don't think this is a correct fix.

We can't emit a R_RISCV_32 dynamic relocation for R_RISCV_HI20
relocation. If we do, the dynamic loader will override an entire 32
bit word with an address of a specified symbol. HI20 is expected to
set a high 20 bits as an instruction operand, so they are not
compatible.

https://github.com/rui314/mold/pull/668
2022-08-27 18:05:29 +08:00
Rui Ueyama 29c4a9c996 Update comments 2022-08-27 18:00:02 +08:00
Rui Ueyama 42e8f9a439 Merge pull request #668 from ksco/rv32gc 2022-08-27 02:51:43 -07:00
Yang Liu e65cc7feea [RISCV32] Fix R_RISCV_HI20 relocations
Signed-off-by: Yang Liu <[email protected]>
2022-08-27 17:27:44 +08:00
Rui Ueyama 340d8b3742 Improve comments 2022-08-27 09:30:10 +08:00
Rui Ueyama 8a3b291ee7 Move a comment 2022-08-26 15:48:17 +08:00
Rui Ueyama 2d364b0e78 [ELF] R_RISCV_64 should not be available on RV32 2022-08-26 12:45:09 +08:00
Rui Ueyama a0dffce882 Refactor 2022-08-26 12:45:09 +08:00
Rui Ueyama 694f973dc5 [Mach-O] Emit addends for dynamic relocations
Previously, all dynamic symbols had addend 0.

Fixes https://github.com/rui314/mold/issues/657
2022-08-25 19:02:07 +08:00
Rui Ueyama 8c4109389d Improve an error message 2022-08-25 19:02:07 +08:00
Rui Ueyama 800d246ec3 [ELF] Fix i386 PC-relative relocations 2022-08-24 13:48:13 +08:00
Rui Ueyama 2eb0258991 Simplify 2022-08-24 13:41:03 +08:00
Rui Ueyama 70bdc9bc94 [ELF] Do not promote absolute symbols from DSO to dynamic ones 2022-08-24 13:08:46 +08:00
Rui Ueyama a8bd32d2ea [ELF][RV32] Do not emit a dynamic relocation for R_RISCV_64 2022-08-24 11:25:09 +08:00
Rui Ueyama ac705872dd Remove dead code
There's no thing like PC-relative dynamic relocation, so the `else`
part will never be executed.
2022-08-24 10:45:12 +08:00
Rui Ueyama a3da318ff9 Simplify 2022-08-24 09:56:45 +08:00
Rui Ueyama a2c3b6fa1c Merge pull request #662 from ideasman42/patch-1
Fix #661: Restore ld location to $(LIBEXECDIR)/mold/ld
2022-08-23 18:50:19 -07:00
Campbell Barton 5e65a4fa77 Fix #661: Restore ld location to $(LIBEXECDIR)/mold/ld 2022-08-24 09:46:42 +10:00
Rui Ueyama 89038c2c27 Fix typos 2022-08-23 19:49:48 +08:00
Rui Ueyama e2ca959bed Rename a function 2022-08-23 19:48:40 +08:00
Rui Ueyama f787f4bdac Merge pull request #658 from marxin/really-skip-arm32-thumb-interwork.sh
armv6l: properly skip arm32-thumb-interwork.sh
2022-08-23 02:41:21 -07:00
Martin Liska c760c5daf7 armv6l: properly skip arm32-thumb-interwork.sh
I was not correct as the 'sorry, unimplemented: Thumb-1 'hard-float' VFP ABI
really comes late in target register allocator. Thus one needs to
assembly a function.

Fixes: #655
Signed-off-by: Martin Liska <[email protected]>
2022-08-23 11:15:52 +02:00
Rui Ueyama 4cb4a93d3d Fix CI 2022-08-23 16:05:37 +08:00
Rui Ueyama f6051993e4 Style fixes 2022-08-23 15:26:20 +08:00
Rui Ueyama 277d56d6f4 Add a comment 2022-08-23 13:26:54 +08:00
Rui Ueyama a31f95bd9a Simplify 2022-08-23 13:09:03 +08:00
Rui Ueyama b9b000bed0 Simplify 2022-08-23 12:28:11 +08:00
Rui Ueyama 45b3fd5ecf Simplify 2022-08-23 12:00:44 +08:00
Rui Ueyama 1992af8b51 Simplify 2022-08-23 08:40:14 +08:00
Rui Ueyama 159d4401df Remove dead code 2022-08-22 20:24:31 +08:00
Rui Ueyama e6e68945cf Remove unnecessary variables 2022-08-22 19:37:03 +08:00
Rui Ueyama cb6e1a5b9a Fix a requires expression
I don't know if the previous expression was correct, but this new
one should be correct.
2022-08-22 18:16:04 +08:00
Rui Ueyama c794112836 Simplify 2022-08-22 16:33:59 +08:00
Rui Ueyama 7bd86d9c48 [Mach-O] Fix spurious "duplicate symbol" error
Fixes https://github.com/rui314/mold/issues/654
2022-08-22 16:04:34 +08:00
Rui Ueyama a9b34e6f03 Skip a test if the compiler doesn't accept -mthumb
Fixes https://github.com/rui314/mold/issues/655
2022-08-22 15:55:41 +08:00
Rui Ueyama c4b3c28445 Add a test 2022-08-22 15:32:48 +08:00
Rui Ueyama 4682f02a45 Simplify 2022-08-22 15:12:49 +08:00
Rui Ueyama 88edf02912 Simplify 2022-08-22 14:29:22 +08:00
Rui Ueyama b184ebb73d Simplify 2022-08-22 14:19:03 +08:00
Rui Ueyama f8d81f0981 Simplify 2022-08-22 13:55:57 +08:00
Rui Ueyama c945c855ad Simplify
Because we are using C++20, we can use `requires`.
2022-08-22 13:39:33 +08:00
Rui Ueyama 7af3664791 [ELF][RISCV32] Create dynamic relocations for R_RISCV_32 2022-08-22 13:05:54 +08:00
Rui Ueyama ba3903e969 Simplify 2022-08-21 20:30:33 +08:00
Rui Ueyama f26f1e6192 Simplify 2022-08-21 20:04:37 +08:00
Rui Ueyama 29ca848dc9 Refactor 2022-08-21 17:44:11 +08:00
Rui Ueyama abb3ee0a62 Refactor 2022-08-21 16:48:39 +08:00
Rui Ueyama 95863f9ccf Simplify 2022-08-21 16:27:36 +08:00
Rui Ueyama 647395ecff Simplify 2022-08-21 15:09:30 +08:00
Rui Ueyama ab1ee42a9e Simplify 2022-08-21 14:58:02 +08:00
Rui Ueyama 784eaa2d39 Simplify 2022-08-21 14:50:20 +08:00
Rui Ueyama 19a681e06b Simplify 2022-08-21 14:25:22 +08:00
Rui Ueyama a3b9c26657 Remove an unused parameter 2022-08-21 13:42:15 +08:00
Rui Ueyama 9a7b63b55a Handle R_AARCH64_ADR_PREL_PG_HI21 as an absolute relocation
I don't think PIE uses R_AARCH64_ADR_PREL_PG_HI21 relocation because
in PIE, we need to use R_AARCH64_CALL26 or R_AARCH64_JUMP26 for branches
and use GOT to take an address of a global object.
2022-08-21 13:21:49 +08:00
Rui Ueyama 15dbcb6d52 Update the decision table for relocation processing
- PC64 relocations are not representable using DYNREL because
  DYNREL is for an absolute address

- PC-relative relocations should be able to refer PLT entries
  in the same ELF module
2022-08-21 13:03:18 +08:00
Rui Ueyama bdf5373119 Remove code for MSVC
Since we are using clang-cl for Windows, we don't need to write code
for MSVC.
2022-08-21 11:55:22 +08:00
Rui Ueyama 300f051939 Suppress "control reaches end of non-void function" warning 2022-08-21 11:54:27 +08:00
Rui Ueyama 507fb3f445 [ELF] Set st_size to 0 to imported symbols 2022-08-21 11:35:41 +08:00
Rui Ueyama 63552afa91 Simplify 2022-08-21 11:32:01 +08:00
Rui Ueyama d47a18bde2 Simplify 2022-08-21 09:58:45 +08:00
Rui Ueyama 454fd916ff Improve error message 2022-08-21 09:51:59 +08:00
Rui Ueyama 0f3437a0f0 Fix compilation error for the optimized build
Fixes https://github.com/rui314/mold/issues/648
2022-08-21 09:44:12 +08:00
Rui Ueyama 1d09662818 Simplify 2022-08-21 09:30:22 +08:00
Rui Ueyama cbfc042dae Merge pull request #649 from rbartlensky/fix-550
Correctly compute R_ARM_GOT_PREL.
2022-08-20 18:23:41 -07:00
Rui Ueyama 14c8a119f4 Respect DESTDIR when installing symlinks
Fixes https://github.com/rui314/mold/issues/650
2022-08-21 09:18:44 +08:00
Robert Bartlensky 00d9017088 arm32: Correctly compute R_ARM_GOT_PREL.
Fixes #550.

In the Arm32 [spec][spec], R_ARM_GOT_PREL is defined as follows:

R_ARM_GOT_PREL: GOT(S) + A – P

Where:
> GOT(S) is the address of the GOT entry for the symbol S.

If we look at the code a bit, notice that G is actually the _offset_
of S into the GOT, not the symbol's address in GOT. This patch makes
sure that the relocation is computed using the GOT address of the
symbol, thereby fixing the mentioned issue.

[spec]: https://github.com/ARM-software/abi-aa/blob/60a8eb8c55e999d74dac5e368fc9d7e36e38dda4/aaelf32/aaelf32.rst#5612relocation-types

Signed-off-by: Robert Bartlensky <[email protected]>
2022-08-21 02:09:03 +01:00
Rui Ueyama 71daaa22df [ELF] Fix ARM32 exception handling
Fixes https://github.com/rui314/mold/issues/646
2022-08-20 21:23:07 +08:00
Rui Ueyama 7d91c754dd Refactor 2022-08-20 17:30:07 +08:00
Rui Ueyama 6901c1ff45 Refactor 2022-08-20 17:11:09 +08:00
Rui Ueyama 8eaf81b0bd Simplify 2022-08-20 16:47:25 +08:00
Rui Ueyama 112b52c300 Refactor 2022-08-20 16:15:55 +08:00
Rui Ueyama c661a467cb Always create git-hash.cc if missing 2022-08-20 15:59:05 +08:00
Rui Ueyama 9c61fc648d Do not override CMAKE_INSTALL_LIBDIR
Fixes https://github.com/rui314/mold/issues/641
2022-08-20 15:27:58 +08:00
Rui Ueyama e2730c6e0e Improve a test 2022-08-20 15:26:43 +08:00
Rui Ueyama 7890bf36b7 Improve error message
https://github.com/rui314/mold/issues/604
2022-08-20 15:13:52 +08:00
Rui Ueyama 58fd94d96d Merge pull request #645 from imichael2e2/main
Support compilation of mold-wrapper.c on FreeBSD
2022-08-19 23:15:40 -07:00
Michael Lee 5a422bd8a1 Support compilation of mold-wrapper.c in FreeBSD 2022-08-20 13:46:08 +08:00
Rui Ueyama 0ef1e49134 Refactor 2022-08-20 13:32:05 +08:00
Rui Ueyama 49ec4671fb Eliminate all uses of Python3 2022-08-20 12:29:03 +08:00
Rui Ueyama 2406e4cd5f Rewrite update-git-hash.py in CMake 2022-08-20 12:16:25 +08:00
Rui Ueyama 0a80016276 Update README 2022-08-20 09:41:03 +08:00
Rui Ueyama 9005e163bd Merge pull request #639 from nickgerace/docs
Add Rust macOS instructions to README
2022-08-19 18:24:24 -07:00
Rui Ueyama a653478d85 Add CONFIGURE_DEPENDS to CMake file glob
Without `CONFIGURE_DEPENDS`, cmake build file is not automatically
regenerated when a new file is added.
2022-08-20 09:03:53 +08:00
Rui Ueyama a817f8d576 Enable mold to be built under BSDs
This commit is imported from
https://github.com/oneapi-src/oneTBB/commit/c4a42feb5333488360617a9b58f90e479659b744

Fixes https://github.com/rui314/mold/issues/549
2022-08-20 08:54:17 +08:00
Rui Ueyama b613a4192b Merge pull request #637 from nevack/nevack/python-shebang
Use portable shebang for python3 in update-git-hash.py
2022-08-19 17:52:42 -07:00
Rui Ueyama a5dd93ea7b Merge pull request #644 from ltratt/openbsd_support
Enable mold to build under OpenBSD.
2022-08-19 17:52:07 -07:00
Laurence Tratt 35d94cc046 Enable mold to build under OpenBSD. 2022-08-19 20:51:36 +01:00
Rui Ueyama 60070e0c13 Simplify 2022-08-19 20:05:26 +08:00
Rui Ueyama 04d76d7929 Indentation 2022-08-19 19:42:37 +08:00
Rui Ueyama 38d2b22f9b Revert "Simplify" to fix CI
This reverts commit a436ba36e5.
2022-08-19 19:26:06 +08:00
Rui Ueyama a436ba36e5 Simplify 2022-08-19 18:14:01 +08:00
Rui Ueyama 17f0f7a7c2 Simplify 2022-08-19 17:29:43 +08:00
Rui Ueyama 41cb428550 Merge pull request #640 from ZhongRuoyu/fix-macho-version-flag
Fix `ld64.mold` version flag
2022-08-19 00:57:20 -07:00
Rui Ueyama 431211321c Make "make clean" to remove symlinks 2022-08-19 15:15:32 +08:00
Zhong Ruoyu f6fb88a3ec Revert "[Mach-O] Add flag --version"
This reverts commit 156aad6354 and lines in `test/macho/version.sh` that cover this.

Signed-off-by: Zhong Ruoyu <[email protected]>
2022-08-19 15:13:19 +08:00
Rui Ueyama 771a97822b Do not request a sign-off for small patches
Tiny patches are not copyrightable in the first place, so we do not
need a sign-off for such changes.
2022-08-19 15:08:28 +08:00
Rui Ueyama c1bc12b2db Ignore directories commonly used with CMake 2022-08-19 14:33:20 +08:00
Zhong Ruoyu 4636580508 [Mach-O] Add a test to cover version flags
Signed-off-by: Zhong Ruoyu <[email protected]>
2022-08-19 14:22:51 +08:00
Zhong Ruoyu 156aad6354 [Mach-O] Add flag --version
Signed-off-by: Zhong Ruoyu <[email protected]>
2022-08-19 14:20:04 +08:00
Zhong Ruoyu 6d8dcc9cea [Mach-O] Fix nonzero return code with ld64.mold -v
Signed-off-by: Zhong Ruoyu <[email protected]>
2022-08-19 14:19:39 +08:00
Rui Ueyama f341fbfdc9 Fix CI 2022-08-19 11:06:38 +08:00
Rui Ueyama 0515b4b100 Improve error message
https://github.com/rui314/mold/issues/638
2022-08-19 10:36:28 +08:00
Rui Ueyama c8ae70d591 Merge pull request #635 from nevack/nevack/snprintf
remove unused to_string impl for Digest (aka array<uint8_t, ...>)
2022-08-18 18:29:49 -07:00
Rui Ueyama 3a6e1cd79a Refactor 2022-08-19 09:28:53 +08:00
Dzmitry Neviadomski b871a4ff66 remove to_string implementation for Digest (aka array<uint8_t, ...>)
function uses sprintf which is deprecated in latest macOS 13.0 SDK

Signed-off-by: Dzmitry Neviadomski <[email protected]>
2022-08-19 04:03:31 +03:00
Nick Gerace 97737a32ec Add Rust macOS instructions to README
Signed-off-by: Nick Gerace <[email protected]>
2022-08-18 13:45:55 -04:00
Dzmitry Neviadomski dea48143db Use portable shebang for python3 in update-git-hash.py
Signed-off-by: Dzmitry Neviadomski <[email protected]>
2022-08-18 16:59:20 +03:00
Rui Ueyama f57d10dcda Merge pull request #634 from sicherha/arm_testcase_preconditions 2022-08-18 04:57:12 -07:00
Christoph Erhardt a4a0592795 Fix precondition check for ARM architecture
The string `arm` is too restrictive: the architecture can also be
`armv7l`, for example.

Signed-off-by: Christoph Erhardt <[email protected]>
2022-08-18 12:16:25 +02:00
Christoph Erhardt 1bc11579e7 Remove precondition checks for ARM architecture
These two test cases work fine on ARM; there is no need to skip them any
more.

Signed-off-by: Christoph Erhardt <[email protected]>
2022-08-18 12:16:18 +02:00
Rui Ueyama 19d9255d72 Bump mold version to 1.4.1 2022-08-18 16:27:51 +08:00
Rui Ueyama 6d5e3e7d18 Remove a test that uses valgrind
Looks like it is causing a false negative on some ARM32-based systems.

Fixes https://github.com/rui314/mold/issues/442
2022-08-18 16:22:45 +08:00
Rui Ueyama 053b90b489 [ELF] Fix R_ARM_CALL
If a R_ARM_CALL refers an ARM instruction that jumps to Thumb, we
need to rewrite an instruction to BLX. We previously didn't do that.

Fixes https://github.com/rui314/mold/issues/442
2022-08-18 13:13:56 +08:00
Rui Ueyama 64d7532b75 Refactor 2022-08-18 12:52:04 +08:00
Rui Ueyama a8d1e293fe Refactor 2022-08-17 19:34:57 +08:00
Rui Ueyama b6f4e171c5 Merge pull request #633 from marxin/binutils-2-39
Fix warnings seen with binutils 2.39
2022-08-17 04:17:45 -07:00
Martin Liska 980219b435 Fix warnings seen with binutils 2.39
The following warnings are seen:

Testing pltgot ... /usr/lib64/gcc/x86_64-suse-linux/12/../../../../x86_64-suse-linux/bin/ld: warning: /tmp/ccpkwmmy.o: missing .note.GNU-stack section implies executable stack
/usr/lib64/gcc/x86_64-suse-linux/12/../../../../x86_64-suse-linux/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker

Testing reloc ... /usr/lib64/gcc/x86_64-suse-linux/12/../../../../x86_64-suse-linux/bin/ld: warning: out/test/elf/x86_64/reloc/a.o: missing .note.GNU-stack section implies executable stack
/usr/lib64/gcc/x86_64-suse-linux/12/../../../../x86_64-suse-linux/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker

Signed-off-by: Martin Liska <[email protected]>
2022-08-17 12:29:44 +02:00
Rui Ueyama bfba468ddd Add a description for mold/macOS 2022-08-17 17:41:14 +08:00
Rui Ueyama f9e3a31d25 Always run update-git-hash.py
Previously, the script didn't run unless the script itself is updated.
2022-08-17 16:57:31 +08:00
Rui Ueyama a2c06b2975 Do not update git-hash.cc if .git directory is missing
Fixes https://github.com/rui314/mold/issues/632.
2022-08-17 16:56:13 +08:00
Rui Ueyama a65d1a58be Do not install mold-wrapper.so for macOS
mold-wrapper.so works only on ELF-based systems, so we should not
install that file with `make install`.

https://github.com/rui314/mold/issues/621
2022-08-17 16:56:13 +08:00
Rui Ueyama bbae3116e4 Make --hash-style=both default instead of --hash-style=sysv
It is found by https://blog.hiler.eu/win32-the-only-stable-abi/.
I didn't intend to make mold to be different from GNU ld. It's
simply a compatibility bug.
2022-08-17 12:34:43 +08:00
Rui Ueyama 810eac0ff8 Format 2022-08-17 12:34:43 +08:00
Rui Ueyama d0ec2243b1 Merge pull request #631 from sicherha/fix_test_always_skipped
Fix test case being skipped unconditionally
2022-08-16 06:55:57 -07:00
Christoph Erhardt 9666041de7 Fix test case being skipped unconditionally
The precondition check was supposed to find out whether the compiler
supports `-fcfprotection`, but it always failed complaining about an
undefined reference to `main()`. As a consequence, the test case was
never executed.

Add `-c` to omit the link step in the compiler call.

Signed-off-by: Christoph Erhardt <[email protected]>
2022-08-16 15:44:34 +02:00
Rui Ueyama 6b27a7e9b3 Fix a regression introduced in 0a8431b930
That change made test/macho/all-load.sh to hang up.
2022-08-16 15:44:36 +08:00
Rui Ueyama 000b51a60c [Mach-O] Symbols flags in an export trie as bit flags
Fixes https://github.com/rui314/mold/issues/624
2022-08-16 15:44:36 +08:00
Rui Ueyama 3c236bdcfb Merge pull request #628 from marxin/fix-output-of-defsym2-test 2022-08-15 23:21:11 -07:00
Martin Liska b1242f55e9 tests: grep for output of nm in defsym2.sh test
Right now, the test prints to the output:

Testing defsym2 ...                  w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
                 U __cxa_finalize
                 w __gmon_start__
00000000000010f9 T bar
00000000000010f9 T foo
OK

which is changed to:

Testing defsym2 ... OK

Signed-off-by: Martin Liska <[email protected]>
2022-08-16 08:00:10 +02:00
Rui Ueyama bce2170cfe Add a test for a595c4874d 2022-08-16 12:53:54 +08:00
Rui Ueyama da4c309071 Remove dead code 2022-08-16 12:26:03 +08:00
Rui Ueyama 47793b0aa4 Let users to use clang-cl to compile mold on Windows 2022-08-16 12:10:24 +08:00
Rui Ueyama 5dd282ded5 Merge pull request #625 from rbartlensky/compute-correct-shndx
Make sure symbol points to correct section.
2022-08-15 20:13:10 -07:00
Robert Bartlensky a595c4874d Make sure symbol points to correct section.
I was debugging #550, and I noticed a symbol was pointing to the
start of a section, but its shndx was set to SHN_UNDEF. Looking over
the code, I realized that for each section you create a corresponding
output section, but if the input section is mergeable, you also create
a fragment for it whose parent is MergeableSection, which in the end
will be copied into the output binary instead of the output section.

Since the symbol was pointing to the start of a mergeable section, I
realized that it is probably wrong to use the shndx of
`isec->output_section`, because that particular Chunk never actually
makes it to the list of final Chunks for mergeable sections.

Before:
```
$ eu-readelf -s ./target/debug/mold_test | grep _rustc
  Num:    Value   Size Type    Bind   Vis          Ndx Name
   77: 000d563c     34 OBJECT  LOCAL  DEFAULT    UNDEF __rustc_debug_gdb_scripts_section__

$ eu-readelf -S ./target/debug/mold_test
[Nr] Name                 Type         Addr     Off    Size   ES Flags Lk Inf Al
...
[22] .debug_gdb_scripts   PROGBITS     000d563c 0d563c 000022  0 A      0   0  1
...
```

After:
```
$ eu-readelf -s ./target/debug/mold_test | grep _rustc
  Num:    Value   Size Type    Bind   Vis          Ndx Name
   77: 000d563c     34 OBJECT  LOCAL  DEFAULT       22 __rustc_debug_gdb_scripts_section__

$ eu-readelf -S ./target/debug/mold_test
[Nr] Name                 Type         Addr     Off    Size   ES Flags Lk Inf Al
...
[22] .debug_gdb_scripts   PROGBITS     000d563c 0d563c 000022  0 A      0   0  1
...
```

Signed-off-by: Robert Bartlensky <[email protected]>
2022-08-15 22:44:41 +01:00
Rui Ueyama 0a8431b930 Fix an assertion failure for -flto and -dead_strip_dylibs
Fixes https://github.com/rui314/mold/issues/620
2022-08-15 20:13:02 +08:00
Rui Ueyama 3fbb604577 Re-submit 9eeae5b295 in a different style
With a comment explaining why we need this macro.
2022-08-15 16:43:46 +08:00
Rui Ueyama 70a64b7391 [Mach-O] Temporarily disable linker optimization hints
It seems buggy and causes subtle linker errors. Disable it for now so that
we can focus on getting the essential parts of the linker right.

Fixes https://github.com/rui314/mold/issues/619
2022-08-15 16:14:17 +08:00
Rui Ueyama 76f6959a8e Revert "Windows: define the version of header files to Windows 10"
This reverts commit 9eeae5b295 because
I didn't actually understand what that meant.
2022-08-15 12:54:08 +08:00
Rui Ueyama 0902dd731f Merge pull request #618 from vtorri/vtorri_win10
Windows: define the version of header files to Windows 10
2022-08-14 21:46:56 -07:00
Rui Ueyama 18ca557fbd Add logging
To debug https://github.com/rui314/mold/issues/617
2022-08-15 08:27:41 +08:00
Vincent Torri 9eeae5b295 Windows: define the version of header files to Windows 10
Signed-off-by: Vincent Torri <[email protected]>
2022-08-14 21:47:50 +02:00
Rui Ueyama 9ea9a3312d [Mach-O] Remove a warning message 2022-08-14 17:40:22 +08:00
Rui Ueyama 59542519eb Update the man page 2022-08-14 16:10:52 +08:00
Rui Ueyama a2262989f9 Update the man page 2022-08-14 15:59:47 +08:00
Rui Ueyama 0bbad93d02 Add a link to the man page 2022-08-14 15:06:52 +08:00
Rui Ueyama d51c5a197d Fix CI 2022-08-14 14:39:02 +08:00
Rui Ueyama 446474e46e Add a missing #include
Fixes https://github.com/rui314/mold/issues/613
2022-08-14 14:33:55 +08:00
Rui Ueyama 9afbd99d88 Sort 2022-08-14 13:46:27 +08:00
Rui Ueyama f5b0c8d47a Do not pass GNU-ish options if we use MSVC-compatible clang-cl 2022-08-14 13:18:03 +08:00
Rui Ueyama 7d5e4bdd48 Tidy up 2022-08-14 13:15:26 +08:00
Rui Ueyama b575d2ba79 [ELF] Add ARM32, RV32 and RV64 to the --help message 2022-08-14 12:56:44 +08:00
Rui Ueyama dcaef43283 Split lines that are too long 2022-08-14 12:51:31 +08:00
Rui Ueyama 1bec466d3b Simplify 2022-08-14 12:45:11 +08:00
Rui Ueyama b439a2ba36 Merge pull request #616 from ADKaster/missing-tests 2022-08-13 19:10:00 -07:00
Andrew Kaster f77220c9fa test: Add missing tests to CMakeLists
These tests were added to the repo, but not the list of tests in the
corresponding CMakeLists. As a result, they are not run in CI when using
CTest.

Signed-off-by: Andrew Kaster <[email protected]>
2022-08-13 11:41:46 -06:00
Rui Ueyama 168cc16de2 Merge pull request #614 from vtorri/vtorri_pow_2
Windows: does not test pow() when compiling also with mingw
2022-08-13 04:58:08 -07:00
Vincent Torri 1df6fa8855 Windows: does not test pow() when compiling also with mingw
Signed-off-by: Vincent Torri <[email protected]>
2022-08-13 13:31:26 +02:00
Rui Ueyama 22c78e112b Use MSVC builtin function for unreachable 2022-08-13 17:57:45 +08:00
Rui Ueyama 6abf01597e Fix CI 2022-08-13 17:38:04 +08:00
Rui Ueyama e8332bb052 Add a Windows builder 2022-08-13 17:16:16 +08:00
Rui Ueyama 01bf7847d3 Fix build failure 2022-08-13 17:14:55 +08:00
Rui Ueyama 94d6edb7eb Fix build errors for Windows
With this change, we can compile mold on Windows using Visual Studio
2022-08-13 01:54:38 -07:00
Rui Ueyama c434c2ce94 Fix CI 2022-08-13 16:11:53 +08:00
Rui Ueyama ed1166a08f Fix more compile errors for Windows 2022-08-13 00:55:47 -07:00
Rui Ueyama 76f4c28a1b Fix typo 2022-08-13 13:49:12 +08:00
Rui Ueyama 9f05c9e26f Update email address 2022-08-13 13:47:13 +08:00
Rui Ueyama 6bbc3a56ca Include the LICENSE file into the binary distribution 2022-08-13 13:29:04 +08:00
Rui Ueyama 5eaeed25aa Remove an unneeded option 2022-08-13 13:22:10 +08:00
Rui Ueyama 93e476796b Add third-party components licenses to the main license file 2022-08-13 13:13:44 +08:00
Rui Ueyama f70a86fe45 Fix compiler warnings on Unix 2022-08-13 13:12:49 +08:00
Rui Ueyama 802aad8891 Fix CI 2022-08-13 12:49:16 +08:00
Rui Ueyama 3b796819e5 Split LTO source files for Windows 2022-08-12 21:47:02 -07:00
Rui Ueyama 4050f5241f Revert "Reduce block nesting level"
This reverts commit 73ee17337c.
We no longer use MSVC cl.exe as a compiler. clang doesn't have the
silly 128-level nesting level restriction.
2022-08-13 12:23:48 +08:00
Rui Ueyama 2ed36aef23 Merge branch 'main' of https://github.com/rui314/mold 2022-08-12 21:22:30 -07:00
Rui Ueyama 10fa6c87ef Use clang-cl instead of MSVC's cl as a compiler on Windows 2022-08-12 21:21:01 -07:00
Rui Ueyama f72b93cc66 Add a comment 2022-08-13 11:04:00 +08:00
Rui Ueyama 9daf9f942c Fix MSVC compile errors 2022-08-12 20:49:16 +08:00
Rui Ueyama 73ee17337c Reduce block nesting level
MSVC has a hard limit of 128 block nesting levels. So you can't write
cascaded "else if"s more than 128. That's a very silly restriction,
but we need to work it around.
2022-08-12 20:15:31 +08:00
Rui Ueyama 7908eae30a Silence MSVC's "unknown pragma" warnings' 2022-08-12 19:57:40 +08:00
Rui Ueyama e79f21d2e3 Fix compilation error with MSVC 2022-08-12 19:50:45 +08:00
Rui Ueyama d35d7bf918 Make it compile with MSVC
Turned out that `if constexpr` causes compilation errors with MSVC.
2022-08-12 19:50:06 +08:00
Rui Ueyama 27ef381242 Simplify 2022-08-12 19:37:57 +08:00
Rui Ueyama 0bf4d90b9b Simplify 2022-08-12 19:28:28 +08:00
Rui Ueyama 340a302e3c Attempt to unbreak CI 2022-08-12 18:18:00 +08:00
Rui Ueyama 6780da9eb0 wip 2022-08-12 18:16:10 +08:00
Rui Ueyama 9aa1eb50f4 Simplify 2022-08-12 18:03:44 +08:00
Rui Ueyama 43231abc5c Do not use fork hack on Windows 2022-08-12 17:52:35 +08:00
Rui Ueyama d5f9ca608a Simplify 2022-08-12 17:49:17 +08:00
Rui Ueyama fbd75e2831 Do not build mold-wrapper on non-Unix systems
mold-wrapper just does not work on non-Unix systems.
2022-08-12 17:43:03 +08:00
Rui Ueyama 688ded77ac Simplify 2022-08-12 17:40:35 +08:00
Rui Ueyama 630acaea46 Simplify 2022-08-12 17:37:03 +08:00
Rui Ueyama 9774ff6134 Simplify 2022-08-12 17:19:59 +08:00
Rui Ueyama c3a901e0f2 Simplify 2022-08-12 16:44:51 +08:00
Rui Ueyama 2721c45b41 Merge pull request #608 from clemenswasser/win
Initial Windows fixes
2022-08-12 01:23:32 -07:00
Rui Ueyama f0e1237b00 [ELF] Allow linker script to define symbol aliases
Fixes https://github.com/rui314/mold/issues/610
2022-08-12 15:32:27 +08:00
Rui Ueyama 5dd122710c [ELF] Export symbols defined by --defsym
Previously, symbols defined by `--defsym` would never be exported
because we created a dynamic symbol table before processing `--defsym`.
2022-08-12 15:30:24 +08:00
Clemens Wasser 71c8e5d8c0 Fix narrowing conversions for Windows
Signed-off-by: Clemens Wasser <[email protected]>
2022-08-11 18:03:31 +02:00
Clemens Wasser cd46476c76 Fix mold-wrapper for Windows
Signed-off-by: Clemens Wasser <[email protected]>
2022-08-11 17:32:07 +02:00
Clemens Wasser 965b562cdf Fix CMake for Windows
Signed-off-by: Clemens Wasser <[email protected]>
2022-08-11 17:32:07 +02:00
Clemens Wasser f7703dacd8 Port errno_string to Windows
Signed-off-by: Clemens Wasser <[email protected]>
2022-08-11 17:32:07 +02:00
Clemens Wasser 1c75580a24 Port TimerRecord to Windows
Signed-off-by: Clemens Wasser <[email protected]>
2022-08-11 17:32:07 +02:00
Clemens Wasser 61dc019c05 Port MappedFile to Windows
Signed-off-by: Clemens Wasser <[email protected]>
2022-08-11 17:32:07 +02:00
Clemens Wasser a681e3add3 Fix stderr fileno for Windows
Signed-off-by: Clemens Wasser <[email protected]>
2022-08-11 17:32:07 +02:00
Clemens Wasser fde9e852f3 Port dynamic loading to Windows
Signed-off-by: Clemens Wasser <[email protected]>
2022-08-11 17:32:07 +02:00
Clemens Wasser e8a915e0dd Port bswap to Windows
Signed-off-by: Clemens Wasser <[email protected]>
2022-08-11 17:32:07 +02:00
Clemens Wasser 996dc7c9a3 Port mmap failure signal handler to Windows
Signed-off-by: Clemens Wasser <[email protected]>
2022-08-11 17:32:07 +02:00
Clemens Wasser 6df1f30750 Port SHA256 to Windows using CNG
Signed-off-by: Clemens Wasser <[email protected]>
2022-08-11 17:32:07 +02:00
Clemens Wasser c8af11588a Disable C++ demangling on Windows
Signed-off-by: Clemens Wasser <[email protected]>
2022-08-11 17:28:11 +02:00
Clemens Wasser 246f1a1b49 Fixes for Windows string_view impl
Signed-off-by: Clemens Wasser <[email protected]>
2022-08-11 17:28:11 +02:00
Clemens Wasser 08a83c7aaa Disable includes unavailable on Windows
Signed-off-by: Clemens Wasser <[email protected]>
2022-08-11 17:28:11 +02:00
Rui Ueyama ee68d1f2ff Add a SHA256 fallback implementation
We are going to use this implementation on Windows.
2022-08-11 21:30:13 +08:00
Rui Ueyama 8524705a48 Remove a disclaimer to support CMake officially 2022-08-11 20:44:44 +08:00
Rui Ueyama 2ade8e950f Change test names 2022-08-11 18:07:56 +08:00
Rui Ueyama daf2a5173c Add more tests for CMake 2022-08-11 17:56:12 +08:00
Rui Ueyama ae2e177cb4 Simplify 2022-08-11 17:34:55 +08:00
Rui Ueyama a7d09b7149 Add a new CMake option to disable tests that use QEMU 2022-08-11 17:16:23 +08:00
Rui Ueyama 051dbc0bef Install ld.mold.1 man page as an alias to mold.1
Fixes https://github.com/rui314/mold/issues/607
2022-08-10 22:26:38 +08:00
Rui Ueyama c3a86f5b24 Remove MOLD_DEBUG_ARM64_ONLY
Because it's a developer option, and I'm not using it.
2022-08-10 16:51:07 +08:00
Rui Ueyama d8ad53cc6d Add developer options for faster compilation 2022-08-10 16:43:58 +08:00
Rui Ueyama b1fff13659 [ELF][RISC-V] As per the psABI, this is the correct alignment requirement 2022-08-10 16:33:36 +08:00
Rui Ueyama 78e676cdd0 Fix for ARM64 2022-08-10 15:08:48 +08:00
Rui Ueyama 46be0e152b Fix a build issue on macOS 2022-08-10 15:08:30 +08:00
Rui Ueyama b55cd9be14 Fix build errors 2022-08-10 14:29:37 +08:00
Rui Ueyama 16752b82a3 Do not always link the main executable 2022-08-10 14:29:04 +08:00
Rui Ueyama 5dbb996b36 Format 2022-08-09 22:25:32 +08:00
Rui Ueyama d0e2437f4a Disable exceptions
We are not using exceptions in mold.
2022-08-09 22:24:59 +08:00
Rui Ueyama b16306806d [ELF] Do not export a local symbol even if referenced by a DSO
Fixes https://github.com/rui314/mold/issues/606
2022-08-09 17:28:59 +08:00
Rui Ueyama 910c82a4f4 Remove dead code 2022-08-09 17:22:49 +08:00
Rui Ueyama 3a1a8b0dc7 Fix indentation 2022-08-08 21:54:50 +08:00
Rui Ueyama 635c017400 Run native tests without Qemu 2022-08-08 21:54:06 +08:00
Rui Ueyama b2c6206aa9 Add a script to create a .cc file containing the current git hash 2022-08-08 20:31:02 +08:00
Rui Ueyama e15cdbfad2 Simplify 2022-08-08 17:42:00 +08:00
Rui Ueyama f7f257a663 Specify target name 2022-08-08 17:30:53 +08:00
Rui Ueyama 415673a49e Simplify 2022-08-08 17:20:24 +08:00
Rui Ueyama 0c1c48c3b2 Use CMake in dist.sh 2022-08-08 17:11:32 +08:00
Rui Ueyama eab4f663bf Fix /usr/libexec/mold/ld symlink 2022-08-08 16:40:21 +08:00
Rui Ueyama 3041714a16 Update to LLVM 15 and OpenSSL 3.0.5 2022-08-08 14:03:56 +08:00
Rui Ueyama c622da4a62 Add MOLD_LTO 2022-08-08 13:35:18 +08:00
Rui Ueyama 6ed017919e Build vendored zlib if zlib is not found 2022-08-08 13:01:52 +08:00
Rui Ueyama eee1888d2c Remove a cmake-generated file 2022-08-08 12:47:04 +08:00
Rui Ueyama b6eaa8505b Add MOLD_USE_ASAN and MOLD_USE_TSAN 2022-08-08 12:33:18 +08:00
Rui Ueyama a998d5e845 Simplify 2022-08-08 12:10:01 +08:00
Rui Ueyama 83e4163ed4 Remove make test as we can just run ctest 2022-08-08 11:23:36 +08:00
Rui Ueyama 6a613a12e2 Simplify 2022-08-08 11:22:57 +08:00
Rui Ueyama 3987ebaf34 Add -DMOLD_USE_MOLD=O~n/OFF 2022-08-08 11:11:26 +08:00
Rui Ueyama f8a1d6b3f1 Change tab width from 4 to 2 2022-08-08 11:04:08 +08:00
Rui Ueyama 863c454979 Add a note about the OneTBB patch
Follow-up for https://github.com/rui314/mold/commit/add94b86266b40bc66789e26358675da9d603919
2022-08-07 19:50:50 +08:00
Rui Ueyama 023f1f3596 Make test scripts to print out command trace 2022-08-07 15:41:12 +08:00
Rui Ueyama 00e7119440 Simplify 2022-08-07 15:34:13 +08:00
Rui Ueyama cdd10d4e2e Add a CI for macOS with cmake 2022-08-07 14:25:15 +08:00
Rui Ueyama a937e8fe55 Fix Mach-O tests 2022-08-07 14:16:17 +08:00
Rui Ueyama 3ee4611640 Refactor 2022-08-07 14:14:40 +08:00
Rui Ueyama 76b1845732 Remove unnecessary commands 2022-08-07 13:52:53 +08:00
Rui Ueyama 1a041ffc62 Add to zlib to third-party
We are going to use it on Windows.
2022-08-07 13:42:06 +08:00
Rui Ueyama b3bc37c479 Fix CI 2022-08-07 13:03:24 +08:00
Rui Ueyama 2ea5bd3b02 Add a CI for cmake build 2022-08-07 12:30:21 +08:00
Rui Ueyama 56e82cfc50 Fix test failures
foo_host and foo_x86_64 tests should run simultaneously as
they are the same.
2022-08-07 12:27:29 +08:00
Rui Ueyama fb91f8dfc2 Do not link against external tbb and mimalloc by default
We do not want to change the default settings when we migrate to
cmake.

Also fixed build failures.
2022-08-07 11:16:56 +08:00
Rui Ueyama d4ccc10ed4 Merge pull request #571 from clemenswasser/cmake
CMake Port
2022-08-07 10:37:44 +08:00
Rui Ueyama add94b8626 Specify relative full paths for rust-demangle.h and xxhash.h
They are always in the same directory relative to the top directory,
so we can just specify their relative paths.
2022-08-06 21:24:30 +08:00
Rui Ueyama 6d4f228238 Merge pull request #601 from friendlyanon/feature/third-party-includes
Include only what is needed from third-party
2022-08-06 21:17:12 +08:00
friendlyanon b42d039bd5 Include only what is needed from third-party
Both rust-demangle and xxhash provide usage instructions with include
paths that do not have an extra directory component. This patch fixes
uses of these libraries in the code and avoids including the third-party
directory wholesale.

Signed-off-by: friendlyanon <[email protected]>
2022-08-06 14:59:40 +02:00
Rui Ueyama 12ec2b8acc [Mach-O] -framework in LC_LINKER_OPTION can be missing 2022-08-06 13:02:37 +08:00
Rui Ueyama 637e05bed3 [Mach-O] Allow past-the-end relocations
Relocation may refer past-the-end location of a section. Therefore,
if section X is [0, 0x1000) and section Y is [0x1000, 0x2000), we
can't determine whether a relocation refers address 0x1000 refers
X or Y. We need to pass a section index.
2022-08-06 11:54:12 +08:00
Rui Ueyama e30e8e363a git is no longer a build-time dependency 2022-08-06 08:57:24 +08:00
Rui Ueyama 4739e5f724 Add Pop!_OS
https://github.com/rui314/mold/pull/599
2022-08-06 08:53:01 +08:00
Rui Ueyama 5f8609fe7a Improve error message 2022-08-05 14:47:30 +08:00
Rui Ueyama 76cb2f917f git is no longer a build dependency 2022-08-05 14:40:41 +08:00
Rui Ueyama 627cb0664c Avoid possible accidental prefix match 2022-08-05 14:40:15 +08:00
Rui Ueyama 9bcf974a11 [ELF][RISC-V] Remove deprecated relocations 2022-08-05 13:50:00 +08:00
Rui Ueyama a8345e83c5 [ELF][RISC-V] Make calling an undefined weak symbol an infinite loop 2022-08-05 12:14:08 +08:00
Rui Ueyama 7177f7442b Bump mold version to 1.4.0 2022-08-04 20:47:21 +08:00
Rui Ueyama da2f3fe12c Revert "Re-submit b23c47ae6dbe285e02627803eac0604cfaaa1e78"
This reverts commit a70b1eb58b because
it's too risky to include it into 1.4.0.
2022-08-04 20:46:09 +08:00
Rui Ueyama 10c211f1ab [ELF] Fix a regression for libprotobuf
The `extern "C"` directive in a version script should match a non-C++
mangled name for the sake of compatibility with other linkers. It
caused a regression for libprotobuf.
2022-08-04 18:15:05 +08:00
Rui Ueyama 135e6465c9 Add sponsor names 2022-08-04 15:22:45 +08:00
Rui Ueyama d3cf7cd239 Fix CI 2022-08-04 14:57:10 +08:00
Rui Ueyama 989dacf6d2 [ELF] Fix st_shndx for linker-synthesized symbols 2022-08-04 13:43:12 +08:00
Rui Ueyama 04e3492d77 [ELF] Define __dso_handle only if undefined
GCC 11's crtbeginS.o contains `__dso_handle` as a word-size data
which cnotains its own address as a value. Overriding that symbol
programs that depend on the value to crash.

This fix is needed for 7zip.
2022-08-04 13:41:18 +08:00
Rui Ueyama 456071dafd [ELF][RISCV] Write nops for R_RISCV_ALIGN 2022-08-03 20:35:11 +08:00
Rui Ueyama ab93c8c1e3 [ELF][RISCV32] Use lw instead of ld for RV32 2022-08-03 17:54:19 +08:00
Rui Ueyama 2a8eb67089 [Mach-O] Support LOH_ARM64_ADRP_ADRP 2022-08-03 14:04:26 +08:00
Rui Ueyama aa78db8193 Refactor 2022-08-03 13:16:17 +08:00
Rui Ueyama 1709fc3ca0 [Mach-O] Support LOH_ARM64_ADRP_LDR 2022-08-03 12:47:20 +08:00
Rui Ueyama 7d91674a98 Refactor 2022-08-03 11:29:16 +08:00
Rui Ueyama 8f2768904f [ELF] Add supportec targets to the -V message 2022-08-03 10:54:31 +08:00
Rui Ueyama 04dc1a74db Style fix 2022-08-02 16:36:28 +08:00
Rui Ueyama d553cea606 Refactor 2022-08-02 15:56:53 +08:00
Rui Ueyama 71886e5e2a Fix CI 2022-08-02 13:23:58 +08:00
Rui Ueyama d9db6bcf49 [ELF] Add an initial 32-bit RISC-V support 2022-08-02 13:12:05 +08:00
Rui Ueyama 123dde1e8f Refactor 2022-08-01 17:13:53 +08:00
Rui Ueyama 172c7f6bb4 Refactor 2022-08-01 17:11:21 +08:00
Rui Ueyama 0ce50e1cf8 Refactor 2022-08-01 16:11:45 +08:00
Rui Ueyama 1121879199 Refactor 2022-08-01 14:09:59 +08:00
Rui Ueyama d2829e1806 Simplify 2022-08-01 11:03:29 +08:00
Rui Ueyama 0988565c2f Simplify 2022-08-01 10:28:30 +08:00
Rui Ueyama a70b1eb58b Re-submit b23c47ae6d
With a fix for a bug in my previous test script.
2022-08-01 09:38:12 +08:00
Rui Ueyama bb999c5e93 Revert "[ELF] Garbage-collect C identifier sections"
This reverts commit b23c47ae6d because
it broke CI.
2022-07-31 20:56:37 +08:00
Rui Ueyama b23c47ae6d [ELF] Garbage-collect C identifier sections
If a section name is valid as a C identifier (i.e. it doesn't start
with '.' and doesn't contain any punctuators), the linker automatically
creates new symbols by prepending `__start_` and `__stop_` to the
section name.

Previously, we conservatively keep such C identifier sections during
garbage collection. However, since `__start_` and `__stop_` symbols
are hidden symbols, if we do not have `__start_foo` or `__stop_foo`,
we can safely discard section `foo`.
2022-07-31 20:26:31 +08:00
Rui Ueyama 8cd699c110 Remove dead code 2022-07-31 17:29:42 +08:00
Rui Ueyama e3495efad7 Refactor 2022-07-31 16:51:06 +08:00
Rui Ueyama 5414ae7a36 Merge pull request #593 from ishitatsuyuki/issue-592
[elf] Align .symtab's ELF attributes with .dynsym's.
2022-07-31 12:13:19 +08:00
Rui Ueyama bc81472adb [ELF] Fix TSAN issue
Fixes https://github.com/rui314/mold/issues/594
2022-07-31 10:59:51 +08:00
Tatsuyuki Ishi b83cb924a5 [elf] Rename write_symtab to export_to_symtab.
write_symtab feels like we're writing to the input file, which isn't the
case. export_to_symtab conveys the meaning clearer.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-07-30 22:30:57 +09:00
Tatsuyuki Ishi 536e0e7dca [elf] Align .symtab's ELF attributes with .dynsym's.
Notably, we previously wrote symbols that have been demoted into STB_LOCAL
as STB_GLOBAL. Fix this by using a logic shared with dynsym to determine
the output attributes.

Also reorder the symbols since the LOCAL ones need to come first.

Found in Mesa test suite.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-07-30 22:30:57 +09:00
Tatsuyuki Ishi b19599f81d [elf] Extract computation of output esym into a helper.
Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-07-30 22:30:57 +09:00
Tatsuyuki Ishi bbbda7925e [elf] Add helper to determine if a symbol is STB_LOCAL in output.
Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-07-30 22:30:57 +09:00
Rui Ueyama 467294eb17 [Mach-O] Allow only one LC_SEGMENT_64 command 2022-07-30 16:44:58 +08:00
Rui Ueyama 13ef968fb1 [Mach-O] Do not read the same library or framework more than once 2022-07-30 14:59:11 +08:00
Rui Ueyama 3deaafca30 [Mach-O] Improve relaxation 2022-07-30 13:03:38 +08:00
Rui Ueyama f998104bb0 [Mach-O] Respect N_NO_DEAD_STRIP for executables 2022-07-30 12:39:54 +08:00
Rui Ueyama 4a73ca28ca Fix CI 2022-07-29 21:37:23 +08:00
Rui Ueyama 070907e367 [Mach-O] Allow LC_LINKER_OPTIONS to refer a missing library 2022-07-29 21:24:54 +08:00
Rui Ueyama ed72ca3509 [Mach-O] Change our tool magic number 2022-07-29 21:24:19 +08:00
Rui Ueyama 5a493d4868 [Mach-O] Use 16 KiB page for code signature on ARM64
Based on https://github.com/rui314/mold/pull/536
2022-07-29 12:51:06 +08:00
Rui Ueyama b2b16e66b4 [Mach-O] Add -no_function_starts 2022-07-29 10:48:12 +08:00
Rui Ueyama 4ed7d72372 Update a comment 2022-07-29 09:50:24 +08:00
Rui Ueyama 8143fe2fcc [Mach-O] Fix a relaxation bug 2022-07-29 09:13:18 +08:00
Rui Ueyama 65b0aec355 Update comments 2022-07-28 23:47:55 +08:00
Rui Ueyama 12f941c58d [Mach-O] Improve LOH_ARM64_ADRP_LDR_GOT_LDR 2022-07-28 17:15:37 +08:00
Rui Ueyama 08cf940a7a Merge pull request #590 from alexfanqi/main
[ELF][RISCV] add R_RISCV_SET32 in EhFrameSection
2022-07-28 15:35:27 +08:00
Rui Ueyama 0e1b60dd6e [Mach-O] Fix mis-optimization bug for LOH_ARM64_ADRP_LDR_GOT_LDR 2022-07-28 15:18:14 +08:00
Alex Fan 68bd00caa7 [ELF][RISCV] add missing R_RISCV_SET32 in EhFrameSection
Signed-off-by: Alex Fan <[email protected]>
2022-07-28 16:36:23 +10:00
Rui Ueyama d10b129b13 Update comments 2022-07-27 20:13:37 +08:00
Rui Ueyama bedbb1f4e5 [Mach-O] Fix LOH_ARM64_ADRP_ADD 2022-07-27 19:51:14 +08:00
Rui Ueyama 59f4197edb [Mach-O] Add asserts 2022-07-27 19:17:42 +08:00
Rui Ueyama 390d0dc634 Refactor 2022-07-27 18:04:01 +08:00
Rui Ueyama 8fb3082529 [Mach-O] Support LOH_ARM64_ADRP_ADD 2022-07-27 17:43:15 +08:00
Rui Ueyama f81337cc8b [ELF][RISC-V] Do not assume HI20 relocs appear before LO12 relocs
This re-commits 990b0ac4cd.

As clarified in
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/issues/303,
the order of HI20 and LO12 relocations can be arbitrary.
2022-07-27 17:41:47 +08:00
Rui Ueyama 62ee59ecc6 [Mach-O] Fix bugs in linker relaxation 2022-07-27 16:24:16 +08:00
Rui Ueyama 54399fe567 [Mach-O] Support LOH_ARM64_ADRP_LDR_GOT_LDR 2022-07-27 14:45:13 +08:00
Rui Ueyama d3d0c81bc6 [Mach-O] Fix typo 2022-07-25 19:54:09 +08:00
Rui Ueyama 18063f3ac9 [Mach-O] Add -mark_dead_strippable_dylib 2022-07-25 18:12:39 +08:00
Rui Ueyama 5b8f9f1a7a [Mach-O] Respect MH_NO_REEXPORTED_DYLIBS 2022-07-25 17:13:47 +08:00
Rui Ueyama a6d9955a08 Add a comment 2022-07-25 17:02:42 +08:00
Rui Ueyama 92cbaada34 [Mach-O] Improve -dead_strip performance 2022-07-25 16:03:40 +08:00
Rui Ueyama e9b07df4fb [Mach-O] Parallelize -dead_strip 2022-07-25 15:49:22 +08:00
Rui Ueyama 04909597e9 Fix CI 2022-07-25 12:11:24 +08:00
Rui Ueyama e2c43dcb5e [Mach-O] Report an error for unknown export types 2022-07-25 11:39:42 +08:00
Rui Ueyama 853d1f8a6f [Mach-O] Do not load the same dylib more than once 2022-07-24 20:22:28 +08:00
Rui Ueyama 339eeef435 Simplify 2022-07-24 18:16:10 +08:00
Rui Ueyama 4a21d5dca3 80 columns 2022-07-24 17:46:31 +08:00
Rui Ueyama b824f73912 [Mach-O] Handle EXPORT_SYMBOL_FLAGS_REEXPORT in an export trie 2022-07-24 13:51:01 +08:00
Rui Ueyama b5ed4a67cb [Mach-O] Support -bundle_loader 2022-07-23 20:22:50 +08:00
Rui Ueyama 0a57aec7bb [Mach-O] Use ctx.output_type instead of ctx.arg.dylib 2022-07-23 20:22:50 +08:00
Rui Ueyama e0906564dc Merge pull request #588 from ishitatsuyuki/dynamic-list
[elf] Implement --export-dynamic-symbol[-list].
2022-07-23 20:20:19 +08:00
Tatsuyuki Ishi 1c8778b6e3 [elf] Add test for globs in --dynamic-list, --export-dynamic-symbol-list.
Glob and function names are inherited from version-script14.sh.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-07-23 19:21:19 +09:00
Tatsuyuki Ishi 58f393ac8b [elf] Add test for --export-dynamic-symbol[-list].
Piggybacked on existing tests for --dynamic-list.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-07-23 19:21:19 +09:00
Tatsuyuki Ishi cd25f6b6c7 [elf] Update man for --dynamic-list, --export-dynamic-symbol[-list].
Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-07-23 19:21:19 +09:00
Tatsuyuki Ishi e115aaef4c [elf] Implement --export-dynamic-symbol[-list].
Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-07-23 19:21:19 +09:00
Tatsuyuki Ishi 85217abc7a [elf] Refactor input file argument parser to use string_view.
parse_dynamic_glob requires the passed string_view to be alive across the
entire linker invocation, so we need to avoid cloning for that.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-07-23 19:21:19 +09:00
Tatsuyuki Ishi b48ff94ad1 [elf] Extract dynamic-list glob handling to a helper function.
To ease handling indivudual globs passed through --export-dynamic-symbol.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-07-23 19:21:19 +09:00
Tatsuyuki Ishi 23b43d29c5 [elf] Assume -Bsymbolic when --dynamic-list is specified.
According to lld, --dynamic-list "implies -Bsymbolic but does not set
DF_SYMBOLIC" when creating shared objects. Follow suit in this patch.

Note that we don't set DF_SYMBOLIC currently, and arg.Bsymbolic has no
effect on non-shared objects.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-07-23 19:21:18 +09:00
Rui Ueyama c0e4de2feb Fix CI 2022-07-23 14:21:36 +08:00
Rui Ueyama 5900ee701c [Mach-O] Minimize alignments 2022-07-23 13:59:43 +08:00
Rui Ueyama fe09596d7c [Mach-O] Merge __TEXT,__StaticInit to __TEXT,__text 2022-07-22 20:47:57 +08:00
Rui Ueyama c1195691f3 [Mach-O] Do not ignore N_NO_DEAD_STRIP for local symbols 2022-07-22 16:19:16 +08:00
Rui Ueyama bb1d2147a7 [Mach-O] Merge __objc_imageinfo sections 2022-07-21 22:29:40 +08:00
Rui Ueyama b80b94bd96 [Mach-O] Do not create empty subsections 2022-07-21 19:38:08 +08:00
Rui Ueyama ff087b26a2 [Mach-O] Rename a variable 2022-07-19 14:48:14 +08:00
Clemens Wasser 0a73cf1bfc Port CTest
Signed-off-by: Clemens Wasser <[email protected]>
2022-07-18 18:58:17 +02:00
Clemens Wasser 3c56ade25f Port CPack
Signed-off-by: Clemens Wasser <[email protected]>
2022-07-18 18:58:17 +02:00
Clemens Wasser e6a0e67a38 Port CMake
Signed-off-by: Clemens Wasser <[email protected]>
2022-07-18 18:58:17 +02:00
Rui Ueyama d7b42f29f2 [Mach-O] Define ${section,segment}${start,end}$ symbols. 2022-07-18 19:39:11 +08:00
Rui Ueyama 852bd457d8 [Mach-O] Fix thread-local variable handling 2022-07-18 19:39:11 +08:00
Rui Ueyama b66e55c7e5 [Mach-O] Do not dead-strip module initializers 2022-07-18 19:39:11 +08:00
Rui Ueyama 3ba30f7f09 Create a test workdir for each machine/test pair 2022-07-18 15:25:56 +08:00
Rui Ueyama f6a85acc07 Revert "[ELF][RISC-V] Do not assume HI20 relocs appear before LO12 relocs"
This reverts commit 990b0ac4cd.

This is what the RISC-V psABI says

> The R_RISCV_HI20 refers to an LUI instruction containing the high
> 20-bits to be relocated to an absolute symbol address. The LUI
> instruction is followed by an I-Type instruction (add immediate or
> load) with an R_RISCV_LO12_I relocation or an S-Type instruction
> (store) and an R_RISCV_LO12_S relocation. The addresses for pair of
> relocations are calculated like this:

I read LO12 is guaranteed to always appear after HI20.
2022-07-18 13:16:47 +08:00
Rui Ueyama 990b0ac4cd [ELF][RISC-V] Do not assume HI20 relocs appear before LO12 relocs 2022-07-16 19:51:46 +08:00
Rui Ueyama 29af9b5177 Unmask amd64 2022-07-16 19:51:46 +08:00
Rui Ueyama a8559be1b1 Merge pull request #586 from ltratt/doc_fix
Fix spelling of "support".
2022-07-16 15:33:48 +08:00
Laurence Tratt c8b0522fa6 Fix spelling of "support".
Signed-off-by: Laurence Tratt <[email protected]>
2022-07-16 07:59:56 +01:00
Rui Ueyama 70d5f60aa1 Make pacman non-interactive 2022-07-14 13:44:40 +08:00
Rui Ueyama 4335732d5d Relax version match conditions 2022-07-14 13:02:46 +08:00
Rui Ueyama fc98d73d7e Add an assertion 2022-07-14 13:01:25 +08:00
Rui Ueyama 1275b80eb8 Merge pull request #585 from aslikr42069/add-arch-linux-support-install-deps
Add support to install deps on Arch
2022-07-14 13:01:19 +08:00
aslikr42069 dabe283e4a Add support to install deps on Arch 2022-07-13 21:54:09 -05:00
Rui Ueyama b8a4df51ca [ELF][LTO] Support GCC's LDPT_GET_API_VERSION 2022-07-13 15:29:15 +08:00
Rui Ueyama 2af7e73258 Fix CI 2022-07-12 21:13:05 +08:00
Rui Ueyama ed7e7c7ae0 Merge makefiles for tests into the main makefile 2022-07-12 21:03:54 +08:00
Rui Ueyama 152ee5a261 Update comments 2022-07-12 16:38:47 +08:00
Rui Ueyama b33c3eb010 Refactor 2022-07-12 16:31:37 +08:00
Rui Ueyama 5a190422cd Add comments 2022-07-12 16:08:27 +08:00
Rui Ueyama c4eefe267d Refactor 2022-07-12 15:52:56 +08:00
Rui Ueyama b8dbaff539 Refactor 2022-07-12 13:11:56 +08:00
Rui Ueyama dd32de31c8 [ELF][ARM32] Ignore R_ARM_V4BX
R_ARM_V4BX is a marker relocation which we can savely ignore.

Fixes https://github.com/rui314/mold/issues/582
2022-07-12 12:33:02 +08:00
Rui Ueyama 9f771dd129 Add comments 2022-07-12 12:33:01 +08:00
Rui Ueyama 764d7575f7 [ELF] Define __dso_handle
`cxa_finalize` takes `__dso_handle` to uniquify identify an ELF module
in memory. Its actual location doesn't matter but needs to be different
for each ELF module.

Fixes https://github.com/rui314/mold/issues/507
2022-07-11 18:01:23 +08:00
Rui Ueyama 04efce2d29 Refactor 2022-07-11 15:52:51 +08:00
Rui Ueyama e3e371dcd3 [ELF][x86-64] Always create PLT entries starting with ENDBR64
This change removes the compact PLT and non-IBT PLT and replaces
them with IBT PLT. The compact PLT wasn't compatible with `-z ibtplt`.

Fixes https://github.com/rui314/mold/issues/581
2022-07-11 13:59:32 +08:00
Rui Ueyama 4f1211f7fb Refactor 2022-07-10 20:17:47 +08:00
Rui Ueyama 4d3e59f716 Refactor 2022-07-10 17:53:09 +08:00
Rui Ueyama 816835e25c Update comments 2022-07-10 17:26:15 +08:00
Rui Ueyama 01f89730e1 Simplify 2022-07-10 16:31:01 +08:00
Rui Ueyama 55379e1142 Fix tests for i686
Fixes https://github.com/rui314/mold/issues/579
2022-07-10 12:40:25 +08:00
Rui Ueyama df3f6999a3 [Mach-O] Support NO_DEAD_STRIP attributes 2022-07-09 19:59:29 +08:00
Rui Ueyama d9cb06c270 Merge pull request #576 from wangp/musl-execvp
Fix run.sh failure on musl
2022-07-09 19:51:53 +08:00
Peter Wang 31d2a902e5 Fix run.sh failure on musl
The command "mold -run foo.ld" can fail when foo.ld is an empty file.
The musl execvp() call fails with "Exec format error" when the script
to be executed is empty. The fix is to create foo.ld with a valid
Unix shebang.

Signed-off-by: Peter Wang <[email protected]>
2022-07-09 17:37:57 +10:00
Rui Ueyama 593f2cfdbc Do not run LTO tests if LTO is not supported
Fixes https://github.com/rui314/mold/issues/577
2022-07-09 15:30:38 +08:00
Rui Ueyama 6a44eadd2f Use install-build-deps.sh to set up CI environments 2022-07-09 12:55:51 +08:00
Rui Ueyama 0cc9715df1 Merge pull request #575 from ZhongRuoyu/fix-ci
Fix double git installation in CI workflow
2022-07-09 12:47:43 +08:00
Zhong Ruoyu 50ccbcb444 Fix double git installation in CI workflow
Signed-off-by: Zhong Ruoyu <[email protected]>
2022-07-09 12:38:55 +08:00
Rui Ueyama 12c9c53b90 Add a test 2022-07-08 22:51:05 +08:00
Rui Ueyama 4a9e1439f6 [Mach-O] Rename more sections for compatibility with Apple's ld 2022-07-07 17:13:43 +08:00
Rui Ueyama 4aca9d471e Fix CI 2022-07-07 14:27:57 +08:00
Rui Ueyama af4ef3c76c [Mach-O] Merge all S_CSTRING_LITERALS sections
__TEXT,__cstring is one of such sections.
2022-07-07 14:01:18 +08:00
Rui Ueyama a4cc7f358a [Mach-O] Do not create a baserel for a subtracted relocation 2022-07-06 20:59:05 +08:00
Rui Ueyama be5fe4c727 [Mach-O] Map __DATA,__const to __DATA_CONST,__const 2022-07-06 17:22:52 +08:00
Rui Ueyama 5634b2287a [Mach-O] -ObjC should force-load any section starting with __swift 2022-07-06 15:27:41 +08:00
Rui Ueyama 5d5f75c41d [Mach-O] Fix undefined behavior
A new item may be added to `ctx.objs` in this loop, so we can't
use the range-based for loop here.
2022-07-05 15:55:28 +08:00
Rui Ueyama 256c467b05 [Mach-O] Mark symbols referenced by compact unwind records 2022-07-05 15:55:28 +08:00
Rui Ueyama 5071c42e72 Add a test for Rust demangler
https://github.com/rui314/mold/issues/371
2022-07-05 15:09:44 +08:00
Rui Ueyama 15f1139c31 [Mach-O] Allow compact unwind entry to refer global symbol 2022-07-05 10:52:15 +08:00
Rui Ueyama d6526ed9da [Mach-O] Allow more than one LC_LINKER_OPTION commands 2022-07-05 10:52:15 +08:00
Rui Ueyama 4928e3276d [Mach-O] Do not report unknown symbol types as errors
There are bunch of symbol types for debug symbols.
2022-07-05 10:52:15 +08:00
Rui Ueyama 2bfc724e42 [Mach-O] Add -dependency_info 2022-07-05 10:52:15 +08:00
Rui Ueyama 8bd705a3cb [Mach-O] Support X86_64_RELOC_SUBTRACTOR 2022-07-05 10:52:15 +08:00
Rui Ueyama 691892f48a Add a comment 2022-07-04 20:47:49 +08:00
Rui Ueyama 22e1bba58e Attempt to demangle as a Rust symbol before as C++
https://github.com/rui314/mold/issues/371
2022-07-04 20:42:06 +08:00
Rui Ueyama 808f1240ac Demangle Rust symbols
https://github.com/rui314/mold/issues/371
2022-07-04 19:28:55 +08:00
Rui Ueyama 0e88fd047e Add extern "C" 2022-07-04 19:28:55 +08:00
Rui Ueyama 80dc5cf1fb Merge commit '53e07d3a89bffe34a8d48136e25514e41d523d27' as 'third-party/rust-demangle' 2022-07-04 19:28:35 +08:00
Rui Ueyama 53e07d3a89 Squashed 'third-party/rust-demangle/' content from commit eed29f577
git-subtree-dir: third-party/rust-demangle
git-subtree-split: eed29f57732ddb2be434ec89f8ede9b695e5e157
2022-07-04 19:28:35 +08:00
Rui Ueyama 5fe5294133 Merge pull request #569 from sicherha/fix_compiler_warnings
Fix more compiler warnings
2022-07-04 15:37:29 +08:00
Christoph Erhardt 4af6ff614c Reorder segment_table member variables in bundled TBB library
This fixes a warning produced by GCC 12 related to the initialisation
order of the class members.

For details, see the discussion at
https://github.com/oneapi-src/oneTBB/issues/823. The concern about
potential ABI incompatibility is not relevant for a private bundled
library.

Signed-off-by: Christoph Erhardt <[email protected]>
2022-07-04 08:05:52 +02:00
Christoph Erhardt eaf52ee844 Use GCC-compatible unroll pragma
This notation is supported by both GCC and Clang, whereas
`#pragma unroll` is only supported by Clang.

Signed-off-by: Christoph Erhardt <[email protected]>
2022-07-04 08:05:51 +02:00
Christoph Erhardt ab81c9e51d Forward-declare ARM64 and X86_64 as struct, not as class
Clang warns that forward-declaring a `struct` as `class`
'is valid, but may result in linker errors under the Microsoft C++ ABI'.

Signed-off-by: Christoph Erhardt <[email protected]>
2022-07-04 08:05:14 +02:00
Christoph Erhardt 95d0af2958 Remove superfluous const qualifier
This fixes a compiler warning that occurs when building with `-Wextra`.

Signed-off-by: Christoph Erhardt <[email protected]>
2022-07-04 08:05:14 +02:00
Christoph Erhardt 9056011f67 Suppress 'unused function' compiler warning
Signed-off-by: Christoph Erhardt <[email protected]>
2022-07-04 08:05:12 +02:00
Rui Ueyama ff45af0f34 Refactor 2022-07-04 13:52:34 +08:00
Christoph Erhardt 4df062c72e Remove unused variable
Signed-off-by: Christoph Erhardt <[email protected]>
2022-07-03 21:58:10 +02:00
Rui Ueyama 721c59aea9 Simplify 2022-07-03 21:54:08 +08:00
Rui Ueyama 9ddbfa863a Refactor 2022-07-03 17:35:26 +08:00
Rui Ueyama cd2b8f93e4 Merge pull request #568 from sicherha/fix_compiler_warnings
Fix a few compiler warnings
2022-07-03 16:57:25 +08:00
Christoph Erhardt e2e025ed29 Remove unused #include and unused variable
This fixes an 'unused function' and an 'unused variable' warning.

Signed-off-by: Christoph Erhardt <[email protected]>
2022-07-03 09:18:59 +02:00
Christoph Erhardt 15441b60d3 Fix typos: missing colon and ampersand
Signed-off-by: Christoph Erhardt <[email protected]>
2022-07-03 09:16:08 +02:00
Rui Ueyama 71c4c90922 Simplify 2022-07-02 21:10:29 +08:00
Rui Ueyama 8d29501887 [Mach-O] Ignore OS name part of targets in TBD files 2022-07-02 13:57:12 +08:00
Rui Ueyama ea308bc77b [Mach-O] Add -add_ast_path 2022-07-02 13:52:19 +08:00
Rui Ueyama ad427f8629 [ELF] Skip one more test if musl
https://github.com/rui314/mold/issues/565
2022-07-01 19:05:32 +08:00
Rui Ueyama 23b90dfc38 [ELF] Detect musl libc in a more reliably way
Fixes https://github.com/rui314/mold/issues/565
2022-07-01 18:00:19 +08:00
Rui Ueyama 7f7d10cc89 Bump mold version to 1.3.1 2022-07-01 16:15:37 +08:00
Rui Ueyama 14392e7720 Fix a test for musl 2022-07-01 09:51:32 +08:00
Rui Ueyama 3b75398786 [ELF] Support .preinit_array
It looks like AddressSanitizer depends on this feature.

Fixes https://github.com/rui314/mold/issues/562
2022-06-30 16:29:50 +08:00
Rui Ueyama 5688115bb6 Merge pull request #561 from jpalus/armv6-libatomic
armv6 needs linking with libatomic as well
2022-06-29 20:58:42 +08:00
Jan Palus b1d951a96f armv6 needs linking with libatomic as well
mold: error: undefined symbol: __atomic_fetch_add_8
>>> referenced by compress.cc
>>>               out/compress.o:(void tbb::detail::d1::fold_tree<tbb::detail::d1::tree_node>(tbb::detail::d1::node*, tbb::detail::d1::execution_data const&))>>> referenced by arch-arm64.cc
>>>               out/elf/arch-arm64.o:(tbb::detail::d2::for_each_root_task_base<__gnu_cxx::__normal_iterator<mold::elf::InputSection<mold::elf::ARM64>**, std::span<mold::elf::InputSection<mold::elf::ARM64>*, 4294967295u> >, mold::elf::create_range_extension_thunks(mold::elf::Context<mold::elf::ARM64>&, mold::elf::OutputSection<mold::elf::ARM64>&)::{lambda(mold::elf::InputSection<mold::elf::ARM64>*)#2}, mold::elf::InputSection<mold::elf::ARM64>*>::cancel(tbb::detail::d1::execution_data&))>>> referenced by arch-arm64.cc
>>>               out/elf/arch-arm64.o:(tbb::detail::d2::for_each_root_task_base<__gnu_cxx::__normal_iterator<mold::elf::InputSection<mold::elf::ARM64>**, std::span<mold::elf::InputSection<mold::elf::ARM64>*, 4294967295u> >, mold::elf::create_range_extension_thunks(mold::elf::Context<mold::elf::ARM64>&, mold::elf::OutputSection<mold::elf::ARM64>&)::{lambda(mold::elf::InputSection<mold::elf::ARM64>*)#4}, mold::elf::InputSection<mold::elf::ARM64>*>::cancel(tbb::detail::d1::execution_data&))>>> referenced 971 more times

mold: error: undefined symbol: __atomic_load_8
>>> referenced by main.cc
>>>               out/elf/main.o:(mold::elf::Context<mold::elf::X86_64>::~Context())>>> referenced by output-chunks.cc
>>>               out/macho/output-chunks.o:(mold::macho::ExportEncoder::finish())>>> referenced by main.cc
>>>               out/elf/main.o:(mold::elf::Context<mold::elf::I386>::~Context())>>> referenced 3 more times

Signed-off-by: Jan Palus <[email protected]>
2022-06-29 14:08:55 +02:00
Rui Ueyama ff1d5cd245 [Mach-O] Add -sectalign 2022-06-28 21:16:13 +08:00
Rui Ueyama 3bd972ad85 [Mach-O] Ignore -debug_variant 2022-06-28 20:09:04 +08:00
Rui Ueyama 575a59ef75 [Mach-O] Ignore -objc_abi_version 2022-06-28 20:06:25 +08:00
Rui Ueyama 9a0b7e826b [Mach-O] Add -dylib_install_name 2022-06-28 19:56:18 +08:00
Rui Ueyama ded9cd4ffa Add -application_extension 2022-06-28 19:53:28 +08:00
Rui Ueyama 556e953045 Fix -Wdeprecated 2022-06-28 16:21:22 +08:00
Rui Ueyama 4a1d0dfc31 [Mach-O] Parallelize UUID computation 2022-06-28 16:13:22 +08:00
Rui Ueyama 73074389ed [Mach-O] Do not write x86-64 NOPs if ARM64 2022-06-28 15:49:29 +08:00
Rui Ueyama b0c6aa9a0f [Mach-O] Add -add_empty_section 2022-06-28 15:20:47 +08:00
Rui Ueyama 883320d5e7 Refactor 2022-06-28 13:07:10 +08:00
Rui Ueyama b81f3c22be Add a test 2022-06-28 11:35:36 +08:00
Rui Ueyama 26d45ed4c1 Fix a test
We passed two input files (/dev/null and "-") to the command which
is plainly wrong.

Fixes https://github.com/rui314/mold/issues/559
2022-06-28 10:42:26 +08:00
Rui Ueyama b5d7335e35 Revert "Implement `--(no-)allow-shlib-undefined."
This reverts the following commits because it causes a regression.

 - 62be1fcdb0
 - a7b8da9345
 - 21a2d6bb6c

Fixes https://github.com/rui314/mold/issues/559
2022-06-27 20:53:26 +08:00
Rui Ueyama bdee09ad02 [Mach-O] Handle LC_REEXPORT_DYLIB 2022-06-27 20:49:02 +08:00
Rui Ueyama a6a03b5851 Refactor 2022-06-27 17:43:53 +08:00
Rui Ueyama 8aa05de5e3 Refactor 2022-06-27 16:22:03 +08:00
Rui Ueyama 0e1226287b Remove a dead variable 2022-06-27 14:57:49 +08:00
Rui Ueyama 685085f6fe Refactor 2022-06-27 12:50:10 +08:00
Rui Ueyama 582350cc81 Simplify 2022-06-27 12:29:20 +08:00
Rui Ueyama 335698851b [Mach-O] Add -reexport-l 2022-06-26 18:27:36 +08:00
Rui Ueyama 7b5b1a340b [Mach-O] Handle weak dynamic symbols 2022-06-26 17:21:26 +08:00
Rui Ueyama 3e6f6fe8b5 Merge pull request #557 from wangp/grep-P
Don't use grep -P in tests
2022-06-26 16:42:20 +08:00
Rui Ueyama c001b75d90 Attempt to fix CI 2022-06-26 16:41:30 +08:00
Rui Ueyama 48b782ac6d Ensure that we build TBB with RelWithDebInfo release type
Fixes https://github.com/rui314/mold/issues/558
2022-06-26 16:23:35 +08:00
Rui Ueyama 0be1318b7e Attempt to fix CI 2022-06-26 16:15:06 +08:00
Rui Ueyama 1524746a80 [Mach-O] Fix weak undef symbols 2022-06-26 15:57:15 +08:00
Peter Wang 2963ab672c Don't use grep -P in tests
The version of grep being used may not support the -P flag
(Perl-compatible regular expressions).
2022-06-26 15:51:25 +10:00
Rui Ueyama fe72463f55 [Mach-O] Set mold's version to LC_BUILD_VERSION
I chose 0x6d6f6c64 as a magic number without coordinating with other
tools or Apple, but it should be fine.
2022-06-26 13:14:07 +08:00
Rui Ueyama 831f872886 [Mach-O] Do not emit corrupted unwind table 2022-06-25 19:22:38 +08:00
Rui Ueyama d9a28221dd [Mach-O] Sort the symtab and fill LC_DYSYMTAB fields 2022-06-24 16:00:50 +08:00
Rui Ueyama 62be1fcdb0 Simplify 2022-06-24 11:41:18 +08:00
Rui Ueyama a7b8da9345 Simplify 2022-06-24 10:44:35 +08:00
Rui Ueyama 9e2e70ce7d Merge pull request #540 from rbartlensky/allow-shlib-undefined
Implement `--(no-)allow-shlib-undefined.
2022-06-24 10:19:07 +08:00
Robert Bartlensky 21a2d6bb6c Implement `--(no-)allow-shlib-undefined.
This also fixes the `note-property` test which was hanging on my
machine. Turns out `$CC` was stuck waiting to read from `stdin`,
and as such I decided to write something into it.

Signed-off-by: Robert Bartlensky <[email protected]>
2022-06-23 23:46:15 +01:00
Rui Ueyama 9a3188bcf5 [Mach-O] Compute LC_UUID using the entire code signature section
We used to compute a file UUID using only the hashes in the code
signature section. So we computes the same UUID even if two files
are differnet only in some field of the code signature section.
2022-06-22 20:29:03 +08:00
Rui Ueyama 9cd811393f Simplify 2022-06-22 14:14:08 +08:00
Rui Ueyama 8b86c49f42 [Mach-O] Make sure -thread_count works properly 2022-06-22 14:14:08 +08:00
Rui Ueyama 52943009b7 [ELF] Handle R_ARM_MOVT_PREL and R_ARM_PREL31 as non-address-taking relocations
This is an attempt to fix https://github.com/rui314/mold/issues/545 though
I don't know if this is a correct fix.
2022-06-19 11:32:08 +08:00
Rui Ueyama 00c16556de Revert "[Mach-O] Do not fill text segment with 0x90"
This reverts commit b8f6fe1a1a as an
attempt to fix CI.
2022-06-18 19:38:12 +08:00
Rui Ueyama b8f6fe1a1a [Mach-O] Do not fill text segment with 0x90
0x90 is a NOP on x86-64 but doesn't make sense on ARM.
2022-06-18 19:21:35 +08:00
Rui Ueyama a9f063a394 [Mach-O] Parallelize claim_unresolved_symbols() 2022-06-18 19:16:28 +08:00
Rui Ueyama b0ad0048b2 Simplify 2022-06-18 16:43:39 +08:00
Rui Ueyama 37d798f064 Simplify 2022-06-18 12:15:04 +08:00
Rui Ueyama a9a8205be2 Bump mold version to 1.3.0 2022-06-18 11:29:18 +08:00
Rui Ueyama 0bbc1808cc Merge pull request #544 from lancethepants/main
Also copy mold-wrapper.so from docker build.
2022-06-17 22:51:42 +08:00
lancethepants cd3d82c89e Also copy mold-wrapper.so from docker build.
Signed-off-by: Lance Fredrickson <[email protected]>
2022-06-17 08:32:31 -06:00
Rui Ueyama 52c8e09ddb [ELF] Explain --icf=safe and --ignore-data-address-equality 2022-06-17 16:57:56 +08:00
Rui Ueyama c214bfc96b [Mach-O] Remove -dump
I added this option for debugging. Since mold is now mature enough,
we no longer need this option.
2022-06-16 20:53:27 +08:00
Rui Ueyama 7b8d7a6417 [Mach-O] Add -order_file 2022-06-16 16:52:25 +08:00
Rui Ueyama cfb7c268f5 [Mach-O] Do not strip __eh_frame 2022-06-16 15:26:06 +08:00
Rui Ueyama 285ea7ba26 [Mach-O] Add -u 2022-06-16 14:24:59 +08:00
Rui Ueyama 603a831f02 [Mach-O] Improve performance of __cstring merging 2022-06-16 13:17:54 +08:00
Rui Ueyama edfe9f30f2 [Mach-O] Do not enable -adhoc_codesign by default on Intel Mac 2022-06-16 12:23:03 +08:00
Rui Ueyama 5228fa2d78 Revert "[Mach-O] Add a hack to speed up code verification"
This reverts commit f3e1f728d3.
I'm not 100% sure why, but now the code signature verification works
way faster than before. Maybe it has improved in macOS 12.4 which was
released last month?
2022-06-16 12:05:22 +08:00
Rui Ueyama e4e267cc8b Simplify 2022-06-16 11:25:30 +08:00
Rui Ueyama 75ac73809b Remove dead code 2022-06-16 10:35:02 +08:00
Rui Ueyama 1b89d52504 [Mach-O] Reduce the number of personality functions 2022-06-15 20:34:00 +08:00
Rui Ueyama b05a671789 [Mach-O] Do not split into subsections if MH_SUBSECTIONS_VIA_SYMBOLS is not set 2022-06-15 17:45:25 +08:00
Rui Ueyama 30222dfb3f Revert "simplify opt_demangle setup"
This reverts commit f6b661a9051f5657ac701ea9c94dd54a85499365.
We want to make it possible to run two or more mold's `main` function
simultaneously in a single process, so we don't want to make `opt_demangle`
a global variable. That's why it was a thread-local variable.
2022-06-15 13:16:50 +08:00
Rui Ueyama 91aca3b7cf Attempt to fix CI 2022-06-15 13:12:18 +08:00
Rui Ueyama 610e839e9e Fix ASAN issue 2022-06-15 13:12:09 +08:00
Rui Ueyama dcbc85b412 Attempt to fix CI 2022-06-15 11:52:45 +08:00
Rui Ueyama 7133f8a547 Attempt to fix CI 2022-06-15 11:41:45 +08:00
Rui Ueyama 792773be20 Simplify 2022-06-15 10:40:38 +08:00
Rui Ueyama 13816a14e1 Merge pull request #538 from llunak/better-undefined
Better reporting of undefined symbols
2022-06-15 10:28:56 +08:00
Rui Ueyama 8f02509ba6 Print out an error message if mold -run is used on macOS 2022-06-09 10:36:02 -07:00
Luboš Luňák 87163c667a fix tests to work with new undefined references reporting
Signed-off-by: Luboš Luňák <[email protected]>
2022-06-09 13:32:23 +02:00
Luboš Luňák e45bebd1c7 group undefined symbols when reporting them (#508)
The output now roughly matches the lld report format, with
each symbol followed by a limited list of places that reference it.
Lld can additionally read debuginfo to report the exact location,
but that would require writing an interpreter for .debug_line.

Signed-off-by: Luboš Luňák <[email protected]>
2022-06-09 12:40:09 +02:00
Luboš Luňák d0cc19735d report also the referencing function for undefined symbols
Signed-off-by: Luboš Luňák <[email protected]>
2022-06-09 12:40:09 +02:00
Luboš Luňák 2c9e97c768 move duplicated symbol_strtab to base class InputFile
Signed-off-by: Luboš Luňák <[email protected]>
2022-06-09 12:40:09 +02:00
Luboš Luňák 114cb8e9c8 report also source file name in undefined symbol reports
Signed-off-by: Luboš Luňák <[email protected]>
2022-06-09 12:40:09 +02:00
Luboš Luňák 2af30acbb2 simplify opt_demangle setup
Setting it on demand is racy, and also not necessary, it's enough
to set it together with ctx.arg.demangle .

Signed-off-by: Luboš Luňák <[email protected]>
2022-06-09 12:40:09 +02:00
Rui Ueyama 6f9eedf98a [Mach-O] Fix an assertion failure 2022-06-07 20:15:47 +08:00
Rui Ueyama e60bf30513 [Mach-O] Do not include duplicated symbols from re-exported libs 2022-06-07 14:46:16 +08:00
Rui Ueyama 610ce3c307 Refactor 2022-06-07 14:46:16 +08:00
Rui Ueyama f3e1f728d3 [Mach-O] Add a hack to speed up code verification 2022-06-07 12:21:50 +08:00
Rui Ueyama 6f04ef9cf2 [Mach-O] Handle $ld$install_name$ symbols 2022-06-06 20:24:52 +08:00
Rui Ueyama 880204ebe5 [Mach-O] Handle $ld$hide$ symbols 2022-06-06 20:20:16 +08:00
Rui Ueyama 406d8786c9 Do not addd an element in a range-based loop
Adding a new element to a vector may invalidate existing iterators,
so it's not safe.
2022-06-06 20:10:30 +08:00
Rui Ueyama e11e68d508 [Mach-O] Handle $ld$add$ symbols 2022-06-06 19:49:58 +08:00
Rui Ueyama 3af44d08db Refactor 2022-06-06 18:52:14 +08:00
Rui Ueyama d5b5b9afe1 [Mach-O] Handle $ld$previous$ symbols 2022-06-06 17:23:10 +08:00
Rui Ueyama 0b537ae54c [Mach-O] Make -weak_framework to make framework weak 2022-06-06 14:19:24 +08:00
Rui Ueyama b364b3f453 [Mach-O] Add -weak-l<LIB> 2022-06-06 14:02:28 +08:00
Rui Ueyama ea31281149 Add tests 2022-06-06 12:03:01 +08:00
Rui Ueyama ce34654924 Refactor 2022-06-06 10:34:20 +08:00
Rui Ueyama 2d34ba13cb [Mach-O] Report errors in -{un,}exported_symbols_list early 2022-06-05 18:02:47 +08:00
Rui Ueyama eee315ea52 [Mach-O] Allow glob patterns in -exported_symbols_list and -unexported_symbols_list 2022-06-05 17:47:42 +08:00
Rui Ueyama d2d73cbcbc Move glob pattern matchers out of elf directory
Because we want to use them in macho too.
2022-06-05 17:31:32 +08:00
Rui Ueyama c786f55370 Style fix 2022-06-05 12:58:11 +08:00
Rui Ueyama 8ff4bd5e0f [Mach-O] Ignore -order_file 2022-06-05 12:51:14 +08:00
Rui Ueyama 169a22d643 [Mach-O] Add -current_versin 2022-06-05 12:50:28 +08:00
Rui Ueyama 4a8cda75ad [Mach-O] Add -compatibility_version 2022-06-05 12:48:54 +08:00
Rui Ueyama 1ebaf5be84 [Mach-O] Do not read the same .a more than once 2022-06-05 12:30:16 +08:00
Rui Ueyama a05aae7d7a Refactor 2022-06-05 11:45:45 +08:00
Rui Ueyama f9ea7890a8 Remove dead code 2022-06-05 11:39:09 +08:00
Rui Ueyama 0488d95f38 Refactor 2022-06-05 11:34:13 +08:00
Rui Ueyama 6d0d19dffb [Mach-O] Remove a hack for Chromium 2022-06-05 10:39:21 +08:00
Rui Ueyama e3e0593162 [Mach-O] Recurse on re-exported libraries 2022-06-04 22:23:41 +08:00
Rui Ueyama 7511aee558 Refactor 2022-06-04 22:23:21 +08:00
Rui Ueyama 6a3c35d97c [Mach-O] Add more hacks to link Chromium 2022-06-04 21:48:53 +08:00
Rui Ueyama 032b4d4cc5 Refactor 2022-06-04 21:10:52 +08:00
Rui Ueyama 3fb8b483b4 Fix CI 2022-06-04 20:31:09 +08:00
Rui Ueyama e14788102c [Mach-O] Fix dylib ordinal for flat-bounded symbols 2022-06-04 20:17:16 +08:00
Rui Ueyama 96d9859f45 [Mach-O] Add a workaround for linking Chrome 2022-06-04 20:17:16 +08:00
Rui Ueyama 56e6c038dc [Mach-O] Fix a constant 2022-06-04 20:17:16 +08:00
Rui Ueyama 1f5da3d313 [Mach-O] Ignore comment lines in --exported_symbols_list file 2022-06-04 20:17:16 +08:00
Rui Ueyama fc1aed3e99 [Mach-O] Load reexported libraries 2022-06-04 20:17:16 +08:00
Rui Ueyama 4b754348f5 [Mach-O] Support a local reference to a personality function 2022-06-04 20:17:16 +08:00
Rui Ueyama eee1a87742 [Mach-O] Define -weak_framework as an alias for -framework for now 2022-06-04 20:17:16 +08:00
Rui Ueyama 1b52d228d4 Add a test 2022-06-04 20:17:16 +08:00
Rui Ueyama 3842222956 Update FUNDING.yml 2022-06-04 21:14:38 +09:00
Rui Ueyama dce00d511b Create FUNDING.yml 2022-06-04 16:01:47 +09:00
Rui Ueyama 0de862191b [Mach-O] Add --unexported_symbol and --unexported_symbols_list 2022-06-03 19:48:57 +08:00
Rui Ueyama 485877a826 Update README 2022-06-03 19:38:35 +08:00
Rui Ueyama 7478c27ce8 [Mach-O] Add --exported_symbol and --exported_symbols_list 2022-06-03 18:55:00 +08:00
Rui Ueyama a5c216310b [Mach-O] Parallelize FunctionStartsSectoin::compute_size() 2022-06-03 17:57:16 +08:00
Rui Ueyama c55c98c4f2 [Mach-O] Parallelize SymtabSection::copy_buf(). 2022-06-03 17:05:41 +08:00
Rui Ueyama 6b3fc59143 [Mach-O] Parallelize SymtabSection::compute_size() 2022-06-03 16:29:27 +08:00
Rui Ueyama 6779b2bdfe [Mach-O] Do not emit __ind_sym_tab
It looks like no one is using __ind_sym_tab section, so I'll remove
it for now. We can add it back later if it turns out necessary.
2022-06-03 16:03:26 +08:00
Rui Ueyama 7097946eee [Mach-O] Merge symbol visibility 2022-06-03 15:03:29 +08:00
Rui Ueyama 67ec8f3376 [Mach-O] Handle symbols with N_WEAK_DEF|N_WEAK_REF as private extern 2022-06-03 13:23:45 +08:00
Rui Ueyama 0723476fa5 Add a test 2022-06-03 11:50:05 +08:00
Rui Ueyama a50173c259 Revert "Refactor"
This reverts commit 280782b3ae because
it broke CI.
2022-06-03 10:41:50 +08:00
Rui Ueyama 280782b3ae Refactor 2022-06-03 10:14:12 +08:00
Rui Ueyama 5621394dc3 Do not use git command in Makefile
Fixes https://github.com/rui314/mold/issues/529
2022-06-02 21:27:26 +08:00
Rui Ueyama fa420c38d4 [Mach-O] Handle private extern symbols 2022-06-02 21:27:10 +08:00
Rui Ueyama ae33fd278f [Mach-O] Rename variables 2022-06-02 18:18:42 +08:00
Rui Ueyama 68a779f76b [Mach-O] Fix a crash bug 2022-06-02 18:05:31 +08:00
Rui Ueyama f730dde6e7 [Mach-O] Add -object_path_lto 2022-06-02 16:29:50 +08:00
Rui Ueyama 8cf514408b [Mach-O] Print more staticstics numbers 2022-06-02 15:51:22 +08:00
Rui Ueyama 72c8446eb7 [Mach-O] Parallelize string merging 2022-06-02 14:25:52 +08:00
Rui Ueyama f5d85e854f wip 2022-06-02 14:03:08 +08:00
Rui Ueyama 4e845f3972 Fix CI 2022-06-02 14:01:15 +08:00
Rui Ueyama 03af112272 [Mach-O] Add -stats option 2022-06-02 13:57:48 +08:00
Rui Ueyama 66c1433be1 [Mach-O] Merge string constants in __TEXT,__cstring 2022-06-02 13:39:51 +08:00
Rui Ueyama 621e2edd65 Refactor 2022-06-02 11:14:30 +08:00
Rui Ueyama 03045cb2d0 Refactor 2022-06-02 10:27:44 +08:00
Rui Ueyama a572b803d2 Refactor 2022-06-02 10:23:32 +08:00
Rui Ueyama 7c52c41d7b Attempt to fix CI 2022-06-01 22:45:24 +08:00
Rui Ueyama 21fea57d99 [Mach-O] Parallelize export table construction 2022-06-01 22:31:26 +08:00
Rui Ueyama 965fa17b7b [Mach-O] Fix thread-local variables 2022-06-01 15:00:17 +08:00
Rui Ueyama 826bb56d59 [Mach-O] Fix thread-local variables 2022-05-31 16:54:05 +08:00
Rui Ueyama 3f12a843a6 Revert "[Mach-O] Merge string constants in __TEXT,__cstring"
This reverts commit e770df42d9 because
it broke many clang tests.
2022-05-30 17:13:09 +08:00
Rui Ueyama e895351481 Use bool bitfields instead of uint8_t
`bool foo : 1` is better `u8 foo : 1` because

  struct {
    bool foo : 1 = 0;
  } bar;

  bar.foo = 0xf000;

sets `bar.foo` to 1 while

  struct {
    u8 foo : 1 = 0;
  } bar;

  bar.foo = 0xf000;

does _not_ set `bar.foo` to 1 because it just truncates a given
integer to one bit and assign it to `bar.foo`.
2022-05-30 16:04:51 +08:00
Rui Ueyama 1eac1e6cb4 [Mach-O] Fix clang build 2022-05-30 14:58:41 +08:00
Rui Ueyama 0fab94639f [Mach-O] Parallelize resolve_symbols() 2022-05-30 13:58:07 +08:00
Rui Ueyama 348f2bb9da Refactor 2022-05-30 13:39:53 +08:00
Rui Ueyama 2f78d2eb94 [Mach-O] Parallelize a part of merge_cstring_sections() 2022-05-30 13:04:37 +08:00
Rui Ueyama 4826d393d1 [Mach-O] Set a LC_UUID even if -no_adhoc_codesign is given 2022-05-30 12:46:00 +08:00
Rui Ueyama b82aa99bca [Mach-O] Do not create LC_CODE_SIGNATURE if -no_adhoc_codesign is given 2022-05-30 12:26:05 +08:00
Rui Ueyama 080ebb9ee4 [Mach-O] Fix timer probers 2022-05-29 20:01:30 +08:00
Rui Ueyama 4f77af8e76 [Mach-O] Make export table size computation a bit faster 2022-05-29 19:51:02 +08:00
Rui Ueyama cffcea8d44 [Mach-O] Parallelize __LINKEDIT segment members size computation 2022-05-29 19:19:18 +08:00
Rui Ueyama 4622b6b14c Revert "[Mach-O] Use SHA1 instead of SHA256 for code signature"
This reverts commit 395b962c3d because
it broke CI.
2022-05-29 16:57:50 +08:00
Rui Ueyama 395b962c3d [Mach-O] Use SHA1 instead of SHA256 for code signature
It looks like SHA1 is slightly faster than SHA256 on a 2021 ARM Mac mini.
SHA1 is not recommended anymore, but for ad-hoc code signing, it should
be enough because anyone can just recompute an ad-hoc code signature for
any arbitrary binary.
2022-05-29 15:10:02 +08:00
Rui Ueyama f0f194e373 [Mach-O] Do not compute code signatures twice 2022-05-29 14:35:00 +08:00
Rui Ueyama 45615c9d81 [Mach-O] Speed up code signature computation
It looks like calling msync with MS_ASYNC can save ~130 ms per 1 GiB
output on an ARM Mac Mini 2021.
2022-05-29 14:29:26 +08:00
Rui Ueyama d9e2669063 [Mach-O] Parallelize copy_buf even more 2022-05-29 12:58:58 +08:00
Rui Ueyama d31b63e48b Refactor 2022-05-28 21:40:41 +08:00
Rui Ueyama 5612636fe4 Refactor 2022-05-28 21:06:28 +08:00
Rui Ueyama be19241630 Revert "[Mach-O] Parallelize resolve_symbols"
This reverts commit 4aeee88ef8 because
it has made mold unstable.
2022-05-28 15:38:35 +08:00
Rui Ueyama 2f243d2f52 Refactor 2022-05-28 15:34:33 +08:00
Rui Ueyama 8911458961 [Mach-O] Add -thread_count 2022-05-28 14:03:06 +08:00
Rui Ueyama 4aeee88ef8 [Mach-O] Parallelize resolve_symbols 2022-05-28 12:54:36 +08:00
Rui Ueyama 936d3b3c30 [Mach-O] Improve export table construction 2022-05-28 12:05:34 +08:00
Rui Ueyama 0a89a07e6d [Mach-O] Parallelize remove_unreferenced_subsections 2022-05-28 10:53:03 +08:00
Rui Ueyama 79654bfde0 [Mach-O] Parallelize file parsing
`make test-tsan` started failing with this change, but I believe it
is an internal failure of Intel TBB itself.
2022-05-28 09:47:36 +08:00
Rui Ueyama 379ff3d781 Refactor 2022-05-27 16:15:09 +08:00
Rui Ueyama c797408167 Refactor 2022-05-27 14:07:20 +08:00
Rui Ueyama 20ad945fbf Fix CI 2022-05-27 14:02:30 +08:00
Rui Ueyama 702ec961ff [Mach-O] Paralelize data copy 2022-05-27 13:25:11 +08:00
Rui Ueyama 5e4f8924fd [Mach-O] Parallelize code signature computation 2022-05-27 12:02:06 +08:00
Rui Ueyama f55fd7d9f2 [Mach-O] Compute LC_UUID as a tree hash of ad-hoc code signatures
We need to compute SHA256 hashes for a __code_signature section,
so recomputing a SHA256 hash of an entire file for an LC_UUID is
a waste of time. We can instead compute it as a tree hash.
2022-05-27 11:57:27 +08:00
Rui Ueyama ae29091aa6 Tidy up a script
Fixes https://github.com/rui314/mold/issues/525
2022-05-26 21:46:18 +08:00
Rui Ueyama e9f6715c6e [ELF] Support --package-metadata
Fixes https://github.com/rui314/mold/issues/505
2022-05-26 21:04:36 +08:00
Rui Ueyama 7730cb3d25 Revert "[Mach-O] Parallelize file parsing and output section writing"
This reverts commit c36291be60 to unbreak CI.
2022-05-26 17:40:51 +08:00
Rui Ueyama c36291be60 [Mach-O] Parallelize file parsing and output section writing 2022-05-26 17:19:12 +08:00
Rui Ueyama c1164cda77 Attempt o fix CI 2022-05-26 15:42:57 +08:00
Rui Ueyama e770df42d9 [Mach-O] Merge string constants in __TEXT,__cstring 2022-05-26 15:30:28 +08:00
Rui Ueyama 14c717d698 Refactor 2022-05-26 10:10:23 +08:00
Rui Ueyama b32bc66901 Revert "Refactor"
This reverts commit 9e09a21eac to unbreak CI.
2022-05-25 18:51:02 +08:00
Rui Ueyama 9e09a21eac Refactor 2022-05-25 18:38:06 +08:00
Rui Ueyama f5c8d7509e Fix CI 2022-05-25 14:10:51 +08:00
Rui Ueyama 95164b3556 Refactor 2022-05-25 14:09:11 +08:00
Rui Ueyama 4d06199e0d [Mach-O] Add time probers 2022-05-25 14:05:32 +08:00
Rui Ueyama bd292ef782 [Mach-O] Support LC_LINKER_OPTION
Fixes https://github.com/rui314/mold/issues/523
2022-05-25 13:50:05 +08:00
Rui Ueyama b626d74a5f Do not crash if a symbol has not been resolved 2022-05-25 13:01:13 +08:00
Rui Ueyama e7d4d2c39b Format 2022-05-25 12:25:59 +08:00
Rui Ueyama 48c9157fb1 Refactor 2022-05-24 20:39:13 +08:00
Rui Ueyama e37fe163b7 Fix CI 2022-05-24 20:04:41 +08:00
Rui Ueyama 4ca2d82da8 Fix CI 2022-05-24 19:56:54 +08:00
Rui Ueyama 2850c5cfe6 Fix CI 2022-05-24 19:48:13 +08:00
Rui Ueyama 75df1c82f1 [Mach-O] Implement range extension thunks
mold can now link LLVM/Clang 15 on macOS.
2022-05-24 18:25:21 +08:00
Rui Ueyama 754b995e1c Refactor 2022-05-24 16:58:19 +08:00
Rui Ueyama bafa43d4c7 Refactor 2022-05-24 16:39:54 +08:00
Rui Ueyama 760f39d129 Refactor 2022-05-24 15:52:33 +08:00
Rui Ueyama 99b622ffd1 Refactor 2022-05-24 15:01:29 +08:00
Rui Ueyama 7b097e51c9 Refactor 2022-05-24 14:19:22 +08:00
Rui Ueyama 16735e1e68 [ELF] Simplify range extension thunk algorithm
We eliminate unneeded symbols at the end of the algorithm, but that
didn't save too much space. In fact, I didn't observe any difference
by eliminating that last step from the algorithm.
2022-05-24 11:19:32 +08:00
Rui Ueyama 18e24a6e4d [ELF][ARM32] Handle a displacement larger than 2^24 2022-05-23 20:47:52 +08:00
Rui Ueyama 29e15384ed [ELF] Use an alternative instructions for PLT0
Previously, .plt must be within 128 MiB of .got.plt. The PLT0
instruction sequence in this commit does not have such limitation.
2022-05-23 19:27:40 +08:00
Rui Ueyama 229f610825 Revert "[Mach-O] Report relocation overflow error"
This reverts commit f844179fd3 because
it broke the build.
2022-05-23 13:48:09 +08:00
Rui Ueyama e9def90e9a Refactor 2022-05-23 13:47:32 +08:00
Rui Ueyama f844179fd3 [Mach-O] Report relocation overflow error 2022-05-22 18:40:23 +08:00
Rui Ueyama ccf6b0aa33 Revert "[Mach-O] Add mach-o symbols to the internal object"
This reverts commit ca3cd7c3fa because
it broke CI.
2022-05-22 18:40:10 +08:00
Rui Ueyama ca3cd7c3fa [Mach-O] Add mach-o symbols to the internal object 2022-05-22 18:36:00 +08:00
Rui Ueyama b5587d930e [Mach-O] Deduplicate comdat sections 2022-05-22 16:37:14 +08:00
Rui Ueyama 4c034da565 Refactor 2022-05-22 13:42:20 +08:00
Rui Ueyama a1711b97b3 [Mach-O] Demangle symbols 2022-05-21 20:31:11 +08:00
Rui Ueyama e293d56cc1 [Mach-O] Add -sectcreate 2022-05-21 15:56:36 +08:00
Rui Ueyama 7f84e4242c [Mach-O] Add -export_dynamic 2022-05-21 15:16:51 +08:00
Rui Ueyama ffb18422c1 Add comments 2022-05-21 14:06:56 +08:00
Rui Ueyama 33e00f2fb5 [Mach-O] Make output reproducible 2022-05-21 12:54:54 +08:00
Rui Ueyama 5c3bbb801d Refactor 2022-05-21 12:36:41 +08:00
Rui Ueyama def3c95b7f Merge pull request #522 from jacob-abraham/ignore-ld-flags
Ignore --no-keep-memory
2022-05-21 13:09:33 +09:00
Jacob Abraham bd3fa9a3db Pass through of -no-keep-memory of ld
Signed-off-by: Jacob Abraham <[email protected]>
2022-05-20 12:19:27 -07:00
Rui Ueyama ef053c41fe Revert "[CI] Always upload test results as artifacts"
This reverts commit 03cda81af6.
2022-05-20 17:07:05 +08:00
Rui Ueyama 03cda81af6 [CI] Always upload test results as artifacts 2022-05-20 16:28:08 +08:00
Rui Ueyama 51f99db269 Attempt to fix CI 2022-05-20 14:52:03 +08:00
Rui Ueyama 94c100c211 Attempt to fix CI 2022-05-20 14:28:56 +08:00
Rui Ueyama 943cb99a84 Attempt to fix CI 2022-05-20 14:23:28 +08:00
Rui Ueyama eb90d1bcbb [Mach-O] Fix x86-64 CI 2022-05-20 14:18:31 +08:00
Rui Ueyama 7156ef7daa Attempt to fix CI 2022-05-20 13:36:12 +08:00
Rui Ueyama fb89e06e2b Upload build artifacts 2022-05-20 13:31:58 +08:00
Rui Ueyama 6b77349b4a [Mach-O] Fix thread-local variables
With this change, mold can now link mold itself on macOS!
2022-05-20 13:12:58 +08:00
Rui Ueyama 2c5582b9e9 [Mach-O] Fix references to dyld_stub_binder 2022-05-19 18:14:34 +08:00
Rui Ueyama 7ce2c7edb5 [Mach-O] Ignore __eh_frame input sections 2022-05-18 17:19:08 +08:00
Rui Ueyama b5bfe4c607 Revert "[Mach-O] Deduplicate comdat sections"
This reverts commit 55eb8dee4d to unbreak CI.
2022-05-18 14:28:31 +08:00
Rui Ueyama b9827f29e7 [Mach-O] Define ___dso_handle symbol 2022-05-18 14:25:55 +08:00
Rui Ueyama 3ec1e8d9df Refactor 2022-05-18 14:04:48 +08:00
Rui Ueyama 55eb8dee4d [Mach-O] Deduplicate comdat sections 2022-05-18 13:39:02 +08:00
Rui Ueyama da22677bf9 Refactor 2022-05-18 13:08:57 +08:00
Rui Ueyama c654d42c14 Merge pull request #520 from tapthaker/macho-tbd-files
[Mach-O] Adds support for objc and weak symbols in TBD files
2022-05-18 12:03:11 +08:00
Rui Ueyama 4b945c839f Extend a test 2022-05-18 11:41:37 +08:00
Rui Ueyama e4b8fa3c26 [ELF] Do not ovewrite .so files
Fixes https://github.com/rui314/mold/issues/188
2022-05-18 11:38:53 +08:00
Tapan Thaker 6d67614004 [Mach-O] Adds support for objc and weak symbols in TBD files
Signed-off-by: Tapan Thaker <[email protected]>
2022-05-17 20:16:27 -07:00
Rui Ueyama 1052b93c4f [Mach-O] Deduplicate comdat symbols 2022-05-17 20:08:29 +08:00
Rui Ueyama 0692db3481 Merge elf/output-file.cc and macho/output-file.cc into a single file 2022-05-17 16:22:17 +08:00
Rui Ueyama 68f4891107 Merge pull request #518 from tapthaker/absolute-type
[macho] Fix checking for absolute address symbol type
2022-05-17 09:48:37 +08:00
Tapan Thaker 37a50f8996 [macho] Fix checking for absolute address symbol type
Signed-off-by: Tapan Thaker <[email protected]>
2022-05-16 14:04:39 -07:00
Rui Ueyama 352ab1a3f9 [Mach-O][ELF] Add a cleanup handler 2022-05-16 20:14:52 +08:00
Rui Ueyama 519de432c7 [Mach-O][LTO] Pass -mllvm to CodeGen 2022-05-16 19:47:25 +08:00
Rui Ueyama 4d380ec645 [Mach-O] Add tests 2022-05-16 19:34:24 +08:00
Rui Ueyama 0326d66b24 Refactor 2022-05-16 19:34:22 +08:00
Rui Ueyama f392b4aeb3 Refactor 2022-05-16 18:57:16 +08:00
Rui Ueyama a21a79e846 Refactor 2022-05-16 18:31:44 +08:00
Rui Ueyama ca6d4a53c4 Update a CI config file 2022-05-16 16:23:03 +08:00
Rui Ueyama 66e585eebe Fix CI 2022-05-16 16:06:28 +08:00
Rui Ueyama deebb497d3 [Mach-O][LTO] Add a basic support of LTO
mold/macOS can now link a "hello world" program with LTO.
2022-05-16 15:07:09 +08:00
Rui Ueyama 466e93ea46 [ELF] Change a variable name for consistency
We use the same spelling for a variable name and a command line option.
2022-05-16 10:20:36 +08:00
Rui Ueyama 3008879d23 Merge pull request #516 from ishitatsuyuki/icf
ICF: explain, implement icf=safe and ignore-data-address-equality.
2022-05-16 10:08:33 +08:00
Tatsuyuki Ishi e8166bcb1b [elf] Implement ignore-data-address-equality.
Closes: https://github.com/rui314/mold/issues/485
Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-05-15 21:54:58 +09:00
Tatsuyuki Ishi 27908af67d [elf] Implement icf=safe.
Closes: https://github.com/rui314/mold/issues/484
Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-05-15 21:35:25 +09:00
Tatsuyuki Ishi c9288c5b92 [elf] icf: explain.
Add comments to give more insights to the design of the algorithm and
optimizations.

Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-05-15 21:35:04 +09:00
Rui Ueyama 188f17524f [Mach-O] Add a header and a stub cc file for LTO 2022-05-15 19:31:21 +08:00
Rui Ueyama 2b86786419 Move a file 2022-05-15 16:43:22 +08:00
Rui Ueyama bcc8375958 Refactor 2022-05-14 17:47:42 +08:00
Rui Ueyama f0bb588e32 Revert "[ELF][LTO] Restart the linker when get_symbols_v2 is called for the first time"
This reverts commit 38f2b965db.

I'd like to wait for GCC to provide some way to identify whether
or not a given LTO plugin supports the v3 API.
2022-05-14 17:47:19 +08:00
Rui Ueyama 3cf8fc4b35 [Mach-O] Add -no_uuid and -uuid_random and -final_output 2022-05-14 15:51:42 +08:00
Rui Ueyama 64f0ba4a9a Update README 2022-05-14 14:47:38 +08:00
Rui Ueyama 611fa3c7a4 Silence a -Wunused-result warning 2022-05-14 14:36:32 +08:00
Rui Ueyama 69d23bc10f Update dependencies 2022-05-14 14:26:41 +08:00
Rui Ueyama a6c3f3c082 Add more dependencies 2022-05-14 14:11:18 +08:00
Rui Ueyama 64b8168916 Fix tests for OpenSUSE Leap
Fixes https://github.com/rui314/mold/issues/515
2022-05-14 13:47:35 +08:00
Rui Ueyama 27409530d7 Add rules for OpenSUSE 2022-05-14 13:47:10 +08:00
Rui Ueyama b1c0a13386 [ELF] Add --rosegment and --no-rosegment
Fixes https://github.com/rui314/mold/issues/514
2022-05-13 19:41:32 +08:00
Rui Ueyama fcb3bedf0d Refactor 2022-05-13 19:28:15 +08:00
Rui Ueyama e68fdc396e Refactor 2022-05-13 19:08:20 +08:00
Rui Ueyama a98a19acfa Refactor 2022-05-13 14:09:41 +08:00
Rui Ueyama 1a8ebf89db Fix CI 2022-05-13 14:07:19 +08:00
Rui Ueyama f086145fc4 Fix CI 2022-05-13 13:16:51 +08:00
Rui Ueyama 8cbcd9777f [ELF] Support SHF_GNU_RETAIN
https://github.com/rui314/mold/issues/511
2022-05-13 13:09:16 +08:00
Rui Ueyama 2e47fe5815 Do not create a .gdb_index section if there's no debug info section 2022-05-13 11:45:32 +08:00
Rui Ueyama 61d19e65e2 Merge pull request #510 from llunak/no-gdb-index-abort
don't abort with --gdb-index if there's no .debug_info
2022-05-13 11:31:03 +08:00
Rui Ueyama c64fc2ea6d Add a rule for Gentoo Linux 2022-05-13 10:50:18 +08:00
Rui Ueyama 5b4c698a9c Refactor 2022-05-12 20:47:12 +08:00
Rui Ueyama 7f3a05ad0f [Mach-O] Add -hidden-l 2022-05-12 20:15:26 +08:00
Rui Ueyama a5c7c98af8 [Mach-O] Add -stack_size 2022-05-12 19:07:04 +08:00
Rui Ueyama 00148f4d5e [Mach-O] Add -install_name 2022-05-12 18:55:56 +08:00
Rui Ueyama 9459b0f4f5 Refactor 2022-05-12 18:05:01 +08:00
Rui Ueyama ee96875fcc [Mach-O] Add -macos_version_min 2022-05-12 17:48:14 +08:00
Rui Ueyama 4bc287ff48 [Mach-O] Add -search_paths_first and -search_dylibs_first 2022-05-12 16:49:10 +08:00
Luboš Luňák 73a9b6ec7d don't abort with --gdb-index if there's no .debug_info
This is an unusual scenario, but it can happen on Arch Linux, where
apparently even crt1.o has no .debug_info . So if one for whatever
reason omits -g for all compilations and then uses --gdb-index,
mold aborts.

Signed-off-by: Luboš Luňák <[email protected]>
2022-05-12 10:37:29 +02:00
Rui Ueyama 5cf365b4f5 Refactor 2022-05-12 16:34:29 +08:00
Rui Ueyama 5a239ef4b2 [Mach-O] Fix ARM64_RELOC_ADDEND and PAGEOFF relocs
With this fix, mold can now link git and successfully run all
git test suites.
2022-05-12 14:28:04 +08:00
Rui Ueyama 344c027a91 Refactor 2022-05-12 09:35:50 +08:00
Rui Ueyama c1409d95a4 Refactor 2022-05-12 09:30:02 +08:00
Rui Ueyama adb1ee4c0a Refactor 2022-05-11 20:17:47 +08:00
Rui Ueyama 5e389f99d4 Use mold to build mold 2022-05-11 17:34:36 +08:00
Rui Ueyama c054e3d197 Fix CI 2022-05-11 17:23:29 +08:00
Rui Ueyama 53fd03e115 Fix a bug found by AddressSanitizer 2022-05-11 16:36:40 +08:00
Rui Ueyama 99155920af Remove unnecessary dependency 2022-05-11 15:54:09 +08:00
Rui Ueyama 05acf9da2c Add test-asan, test-tsan and test-ubsan targets 2022-05-11 15:51:44 +08:00
Rui Ueyama 4ef90d4316 Do not use pkg-config
We are not using pkg-config for zlib, so I think we can live without
it for libcrypto too.
2022-05-11 15:32:51 +08:00
Rui Ueyama 4d61d462ef Refactor 2022-05-11 10:55:51 +08:00
Rui Ueyama d68c7eb5e4 Refactor 2022-05-11 10:32:30 +08:00
Rui Ueyama 3c284f09ab [ELF] Skip a failing test on RV64
https://github.com/rui314/mold/issues/503
2022-05-10 22:20:28 +08:00
Rui Ueyama f59bd5ea23 [ELF] Fix an unsafe memory access
Fixes https://github.com/rui314/mold/issues/506
2022-05-10 21:42:12 +08:00
Rui Ueyama b6e9c6da66 [Mach-O] Add -U 2022-05-10 20:02:48 +08:00
Rui Ueyama f8296ba0fc Disable a few tests for RV64
Fixes https://github.com/rui314/mold/issues/503
2022-05-10 19:23:33 +08:00
Rui Ueyama 90e0228601 Refactor 2022-05-10 17:19:31 +08:00
Rui Ueyama 15eb278ab1 Refactor 2022-05-10 16:35:36 +08:00
Rui Ueyama c1ba1707fc [Mach-O] Add -force_load 2022-05-10 14:17:41 +08:00
Rui Ueyama 4ae6091442 Refactor 2022-05-10 14:15:16 +08:00
Rui Ueyama 5c63d2e031 Remove an unused variable 2022-05-10 14:01:05 +08:00
Rui Ueyama 166a67d5ee Refactor 2022-05-10 13:54:43 +08:00
Rui Ueyama 6b5c47882a [ELF] Fix mold-wrapper's execle
Fixes https://github.com/rui314/mold/issues/501
2022-05-10 12:43:17 +08:00
Rui Ueyama b8b6d0d3ae Allow to take an arbitrary pointer type 2022-05-10 11:34:06 +08:00
Rui Ueyama 144c156dc6 Fix a test
Fixes https://github.com/rui314/mold/issues/502
2022-05-09 19:34:00 +08:00
Rui Ueyama edc1c68efb Relax a test
Fixes https://github.com/rui314/mold/issues/500
2022-05-09 19:20:41 +08:00
Rui Ueyama e6446b3931 Merge pull request #499 from marxin/docs-gcc
README: GCC 12.1 is already released
2022-05-09 17:14:22 +08:00
Martin Liska d1ade871f0 README: GCC 12.1 is already released
Signed-off-by: Martin Liska <[email protected]>
2022-05-09 11:11:08 +02:00
Rui Ueyama 72ef8fc73a [Mach-O] Support -all_load 2022-05-09 16:48:12 +08:00
Rui Ueyama abaceb458f Update comments 2022-05-09 16:09:00 +08:00
Rui Ueyama d22cdf8540 Rename a file 2022-05-09 14:44:11 +08:00
Rui Ueyama 7f9d16e971 [Mach-O] Fix unaligned accesses 2022-05-09 14:15:42 +08:00
Rui Ueyama f48895cbf3 Update .gitignore 2022-05-09 14:13:32 +08:00
Rui Ueyama bd12a98533 Remove duplicate code 2022-05-09 14:13:16 +08:00
Rui Ueyama ab63994c97 Fix symlink name 2022-05-09 14:02:20 +08:00
Rui Ueyama 537a062d25 Remove unnecessary shell variable 2022-05-09 13:56:48 +08:00
Rui Ueyama 5d7064c01e [Mach-O] Remove absolute addresses from tests 2022-05-09 11:57:42 +08:00
Rui Ueyama f822898c2f [Mach-O] Remove a hook to run executables under Qemu
Qemu does not suport user process emulation for macOS, so we'll
never use it.
2022-05-09 11:44:38 +08:00
Rui Ueyama b2cf48de33 [Mach-O] Fix test for GitHub Actions 2022-05-09 11:43:09 +08:00
Rui Ueyama 188a0f1b3c Remove an unused variable 2022-05-09 11:37:10 +08:00
Rui Ueyama e4d6c8c382 [Mach-O] Fix test runner
If one of the test scripts fail, the entire test should fail.
2022-05-09 11:35:18 +08:00
Rui Ueyama f787e99f16 [Mach-O] Suppress pre-alpha warnings on GitHub Actions 2022-05-08 20:27:00 +08:00
Rui Ueyama 128b345b9a [Mach-O] Enable ASan, UBSan and TSan on GitHub Actions 2022-05-08 20:21:27 +08:00
Rui Ueyama 4c758a62b1 [Mach-O] Fix bugs found by ASAN 2022-05-08 20:03:13 +08:00
Rui Ueyama 2a672254a2 [Mach-O] Fix unaligned acccesses 2022-05-08 20:03:13 +08:00
Rui Ueyama 159d89036e [Mach-O] Enable conditional compilation for debugging 2022-05-08 18:38:39 +08:00
Rui Ueyama 407846a8c6 Use staging setup-mold GitHub action 2022-05-08 11:08:31 +08:00
Rui Ueyama d8a8877875 Retry if pthread_create returns EAGAIN
Looks like on many Unix-like systems, `pthread_create` can spuriously
fail for various reasons even if we have enough resources one more
thread. So we need to retry if EAGAIN is returned.

Without this, mold occasionally fails due to a pthread_create failure.

I'll test this logic for a while in this repo and upstream to OneTBB.

This logic is borrowed from Go's this patch:
https://go-review.googlesource.com/c/go/+/33894/

https://github.com/rui314/mold/issues/353
https://github.com/rui314/mold/issues/410
2022-05-07 19:04:48 +08:00
Rui Ueyama 448a9ec4e3 Fix a signal handler
Pointed out in a post-commit review at
https://github.com/rui314/mold/commit/4819d3dc53e057e4cdb345829f5181fcc6d7d0a4
2022-05-07 16:29:33 +08:00
Rui Ueyama 4819d3dc53 Show a disk full error message only when a write failed
Suggested by @X547 in a post-commit review at
https://github.com/rui314/mold/commit/596926008a4042b94a6901e53236ab1856a29e1a

`puts` is replaced with `write` as suggested by @Alcaro.
2022-05-07 13:42:10 +08:00
Rui Ueyama f8361f6389 Update comments 2022-05-06 18:25:17 +08:00
Rui Ueyama 596926008a Print out a user-friendly error on output filesystem full error
Fixes https://github.com/rui314/mold/issues/497
2022-05-06 18:15:32 +08:00
Rui Ueyama 9fbd71ec6b Update README 2022-05-06 12:38:34 +08:00
Rui Ueyama 727d34d727 Do not show "skipped" if valgrind is not available 2022-05-05 18:59:48 +08:00
Rui Ueyama 6d1f67fc59 Merge pull request #496 from marxin/tests-valgrind
tests: print skipped if valgrind is missing
2022-05-05 18:57:23 +08:00
Martin Liska 6910f8e590 tests: print skipped if valgrind is missing
Signed-off-by: Martin Liska <[email protected]>
2022-05-05 12:42:17 +02:00
Rui Ueyama ca25f1fd20 [ELF] Redefine --color-diagnostics as an alias for --color-diagnostics=auto
It was accidentally mapped to --color-diagnostics=always, but it
was a bug. For the sake of compatibility with other tools such as
clang or lld, it should be defined as an alias for `auto`.
2022-05-05 18:01:04 +08:00
Rui Ueyama 0dc5ed38ed Simplify 2022-05-05 18:00:42 +08:00
Rui Ueyama 3694ffe61d Fix execl-family wrappers
Previously, we didn't terminate an argv with a null pointer.

Fixes https://github.com/rui314/mold/issues/495
2022-05-05 17:37:57 +08:00
Rui Ueyama 2d3b410a3c Remove unnecessary packed attribute 2022-05-05 17:17:24 +08:00
Rui Ueyama 38f2b965db [ELF][LTO] Restart the linker when get_symbols_v2 is called for the first time
Previously, we detected if a given linker plugin supports get_symbols_v3
or not and restart the process if only get_symbols_v2 is supported.

Now, mold restart itself wehn get_symbols_v2 is called for the first time,
eliminating the need for the feature detection.

https://github.com/rui314/mold/issues/454
2022-05-04 10:38:02 +08:00
Rui Ueyama cde4b0fb45 Move a function 2022-05-04 10:01:41 +08:00
Rui Ueyama ed9a29b713 Refactor 2022-05-03 20:23:18 +08:00
Rui Ueyama 06cdd7e951 Refactor 2022-05-03 20:04:01 +08:00
Rui Ueyama 232dafa8d0 [ELF] Do not allow -- for a single-letter option 2022-05-03 19:35:48 +08:00
Rui Ueyama 31ba99a7cd Refactor 2022-05-03 19:25:30 +08:00
Rui Ueyama 885b5c0e10 Fix possible unaligned accesses 2022-05-03 18:59:04 +08:00
Rui Ueyama cd54cacb1b Refactor 2022-05-03 18:35:09 +08:00
Rui Ueyama eb7433f3ac Avoid heap allocation in mold-wrapper 2022-05-03 14:48:24 +08:00
Rui Ueyama 86ad2c5b4d Simplify 2022-05-03 14:35:49 +08:00
Rui Ueyama 68bcc8ea40 Remove dependency to /dev/urandom 2022-05-03 13:59:55 +08:00
Rui Ueyama 44228d91b0 Refactor 2022-05-03 13:34:03 +08:00
Rui Ueyama dbf1040245 Fix possible unaligned accesses 2022-05-02 19:54:25 +08:00
Rui Ueyama f223b9c292 Refactor 2022-05-02 19:39:24 +08:00
Rui Ueyama 3e18883b4b Refactor 2022-05-02 19:09:39 +08:00
Rui Ueyama 5090ad6111 Refactor 2022-05-02 19:04:35 +08:00
Rui Ueyama 11cbf9571b Revert "Style fix"
This reverts commit 433a222f907b9d0c7ce5a2d46b84768652017af7 because
it broke non-x86-64 targets.
2022-05-02 18:50:24 +08:00
Rui Ueyama a15f387526 Simplify 2022-05-02 16:12:56 +08:00
Rui Ueyama d56ba46cb2 Remove dead code 2022-05-02 16:10:25 +08:00
Rui Ueyama dd8e15952f [ELF] Fix --omagic 2022-05-02 15:52:29 +08:00
Rui Ueyama 22a8b3095c Fix possible unaligned accesses 2022-05-02 14:56:34 +08:00
Rui Ueyama 5d68c800ed Update comments 2022-05-02 09:03:28 +08:00
Rui Ueyama a5ff3c8287 Fix relocations 2022-05-01 19:31:05 +08:00
Rui Ueyama 06405073a9 Style fix 2022-05-01 17:33:26 +08:00
Rui Ueyama 0abd0a40db [ELF] Do not set wrong tombstone values to debug info sectinos
Previously, if a relocation in an non-alloc section refers a section
fragment, it gets a tombstone value instead of a real value.

Fixes https://github.com/rui314/mold/issues/490
2022-05-01 17:30:58 +08:00
Rui Ueyama 7cfc894914 [ELF] Do not use uninitialized members 2022-05-01 16:11:46 +08:00
Rui Ueyama 230976a139 Avoid casting to E::WordTy 2022-05-01 15:56:38 +08:00
Rui Ueyama 74ad5da477 Update comments 2022-05-01 15:10:14 +08:00
Rui Ueyama d0d7f948f0 Enable UBSan on GitHub CI 2022-05-01 14:32:25 +08:00
Rui Ueyama da7b5db350 Fix all undefined behaviors found by UBsan 2022-05-01 14:27:53 +08:00
Rui Ueyama bf902e1dd2 Fix -Wc++11-narrowing 2022-05-01 14:27:53 +08:00
Rui Ueyama 12cfddc611 Refactor
- Rename data types so that we have LittleEndian and BigEndian types.

- Do not assume that "base" integral types are aligned to 2 bytes
  boundaries, because that doesn't make much difference in terms of
  performance.

- Remove `pu8` type
2022-05-01 14:27:53 +08:00
Rui Ueyama 1d8c0567a8 Merge pull request #486 from yurai007/add-ubsan-support
Add UBSan support
2022-05-01 12:09:49 +08:00
Rui Ueyama a9f2a8ddfe Merge pull request #487 from sicherha/i686-skip-static-pie-tests
Skip `-static-pie` tests on i686, not just on i386
2022-05-01 10:45:02 +08:00
Christoph Erhardt b5a1d3ace2 Skip -static-pie tests on i686, not just on i386
Signed-off-by: Christoph Erhardt <[email protected]>
2022-05-01 00:31:27 +02:00
Dawid Jurczak 3499ee6ac7 Add UBSan support
Core part of this change is cleaning up Mold from UBSan alignment errors.
Following approach inspired by LLVM's ELFTypes is done here:

    1. Introduce generic Packed class acting as proxy for unaligned aggregated value.
       Every access to such value through proxy is secured by memcpy call.
    2. Replace plain struct members with Packed members wherever it matters.
    3. Use explicit castings through Packed type for misaligned loads.

For more background please check: https://github.com/rui314/mold/discussions/477

Signed-off-by: Dawid Jurczak <[email protected]>
2022-04-30 17:37:14 +02:00
Rui Ueyama eae062f815 [ELF] Fix ICF so that all tests pass with ICF 2022-04-30 19:37:29 +08:00
Rui Ueyama 2ce5e22193 Refactor
This commit makes it clear that Header, Output Section and Synthetic
Section are distinctive.
2022-04-30 17:07:39 +08:00
Rui Ueyama c1c20aa427 refactor 2022-04-30 16:40:05 +08:00
Rui Ueyama af592f303c Simplify 2022-04-30 16:09:05 +08:00
Rui Ueyama d0fc8fb005 Simplify 2022-04-30 15:07:29 +08:00
Rui Ueyama a85b1f539a [ELF] Remove --preload 2022-04-30 15:03:24 +08:00
Rui Ueyama d3130f3648 Replace int with int32_t or uint32_t 2022-04-30 12:43:08 +08:00
Rui Ueyama f48825decb Simplify 2022-04-30 12:38:06 +08:00
Rui Ueyama 920266bce4 [ELF][LTO] Fix LTO on 32-bit hosts
`off_t` is either an alias for `off32_t` or for `off64_t` on a 32-bit
machine. `off32_t` is the default. But it looks like LLVM gold plugin
is always compiled with `off64_t`.

Because of this difference, the offset of the `handle` member in
`PluginInputFile` differed between mold and LLVMgold.so. mold thought
that the member was at offset 16 of the struct, while LLVMgold.so
thought that it's at offset 24.

That caused a mysterious crash when LLVMgold tries to access the
`handle` member.

Fixes https://github.com/rui314/mold/issues/483
2022-04-30 12:10:59 +08:00
Rui Ueyama d714819759 Rename a test 2022-04-29 20:06:48 +08:00
Rui Ueyama 517cce0371 Add a tsan test 2022-04-29 19:53:48 +08:00
Rui Ueyama e5bcbdf487 [ELF] Remove extraneous guards 2022-04-29 19:53:48 +08:00
Rui Ueyama 62b3a3dca9 Fix tests for ASAN and TSAN 2022-04-29 19:53:48 +08:00
Rui Ueyama fafb75b0e5 [ELF] Fix race condition found by ThreadSanitizer 2022-04-29 19:53:48 +08:00
Rui Ueyama 43cd7a4035 Add an asan test 2022-04-29 19:37:52 +08:00
Rui Ueyama 708ad63474 [ELF][LTO] Fix non-v2 LTO build
If a given linker LTO plugin does not support the v3 API, we resolve
all symbol names to identify the set of object files that are actually
needed for linking and then restart the linker to do the same thing
again from scratch, excluding the unneeded files from the beginning.

We do this because the v2 API does not provide a way to "unload" an
object file once it is read.

To identify an unneeded object file on the second run, we serialize
its name in the form of `<archive-name>:<offset-in-archive>` or just
a filename. If an object file is in a thin archive, we simply used
its filename.

But if the same file is directly given to a linker as well as as a
thin archive member, the file would accidentally be excluded on the
second run.

This change fixes that issue. With this change, it looks like we can
build GCC 12 with LTO using mold.

Fixes https://github.com/rui314/mold/issues/454
2022-04-29 12:09:25 +08:00
Rui Ueyama 3f545317c9 Update README 2022-04-28 20:23:55 +08:00
Rui Ueyama c8d8f86a52 Bump mold version to 1.2.1 2022-04-28 17:51:29 +08:00
Rui Ueyama f1f2d40469 [ELF] Support object files with more than 2^19 symbols
Previously, Symbol::sym_idx overflows if there are more than 524,288
symbols in a single file. That's a very large number but is not impossible.

Fixes https://github.com/rui314/mold/issues/405
2022-04-28 17:08:42 +08:00
Rui Ueyama a15b73a6ee [ELF] Parallelize a loop 2022-04-28 13:40:11 +08:00
Rui Ueyama bcac1a3c53 [ELF][LTO] Do not internalize weak/common symbols
Previously, if a symbol in a non-IR object is weak or common and
is resolved to an IR symbol, mold internalized that symbol. That
resulted in having two separate definitions for the same symbol
and caused a mysterious error.

Fixed https://github.com/rui314/mold/issues/479
2022-04-28 13:37:16 +08:00
Rui Ueyama a63c25b020 [ELF] Respect --as-needed for LTO
Previously, we accidentally create DT_NEEDED entries for all DSOs
even if it is guaraded by --as-needed and is not used.
2022-04-28 11:40:31 +08:00
Rui Ueyama 668b17b3fa Merge pull request #480 from ishitatsuyuki/thinlto
ThinLTO option fixes
2022-04-28 11:19:06 +08:00
Tatsuyuki Ishi 3b9dc73210 [ELF] Remove support for thinlto-single-module
This is a LLD exclusive option that is not supported by LLVMgold. It
will be broken, so remove it for now.

Fixes: 7ebd0712 ("[ELF] Recognize --thinlto-{single-module,cache-dir,cache-policy}")
Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-04-28 12:02:57 +09:00
Tatsuyuki Ishi 1bd48be605 [ELF] Fix LLVMgold ThinLTO cache option names
These options needs to be passed without the thinlto- prefix.

See also: https://github.com/llvm/llvm-project/blob/6365bde6585651b7813010dc63df7984a5b8ad41/llvm/tools/gold/gold-plugin.cpp#L263-L266

Fixes: 7ebd0712 ("[ELF] Recognize --thinlto-{single-module,cache-dir,cache-policy}")
Signed-off-by: Tatsuyuki Ishi <[email protected]>
2022-04-28 12:02:57 +09:00
Rui Ueyama eca94d9081 [mold-wrapper] Allow arbitrary long argv for execl, execlp and execle 2022-04-28 10:32:25 +08:00
Rui Ueyama 615687b2ed [ELF] Fix crash of programs that runs under mold -run
We cannot always write to argv safely becasue mold-wrapper's functions
run in other program's context, and we have no idea about the assumption
that the underlying program has on this vector.

So, we should not write to argv.

This commit is based on @ishitatsuyuki's patch.

Fixes https://github.com/rui314/mold/issues/478
2022-04-28 09:53:48 +08:00
Rui Ueyama ee95df673b [ELF] Remove a test for a feature that is deprecated 2022-04-27 22:30:00 +08:00
Rui Ueyama e429773794 Update a comment 2022-04-27 21:40:58 +08:00
Rui Ueyama e89ec11427 [ELF] De-duplicate .debug_gnu_pubtypes entries
Fixes https://github.com/rui314/mold/issues/472
2022-04-27 21:39:41 +08:00
Rui Ueyama 43ab68b95d Simplify 2022-04-27 18:11:11 +08:00
Rui Ueyama 3455e8bd82 Include popular large libs to the base Docker image
So that each test doesn't have to compile them individually.
2022-04-27 16:36:45 +08:00
Rui Ueyama 9899769713 Merge pull request #476 from llunak/gdb-index-debug-types
[ELF] the --gdb-index code does not handle .debug_types
2022-04-27 15:04:04 +08:00
Luboš Luňák 8b584f8297 [ELF] the --gdb-index code does not handle .debug_types
And there is probably little need to do so, since it's DWARF4-only
and requires explicit -fdebug-types-section, but at least detect
and abort in this case.
2022-04-27 07:55:48 +02:00
Rui Ueyama e088db72e0 [ELF] Do not set PLT addresses to .symtab
Fixes https://github.com/rui314/mold/issues/473
2022-04-27 13:31:47 +08:00
Rui Ueyama 8298c0ad16 [ELF] Fix symbol resolution for versioned symbols
My last commit d391fd9a59 changes how we
resolve versioned symbols, but that affected too many programs.
In particular it broke GCC build, so reverted in
f378fdc495.

This commit is an attempt to fix the same issue with a minimal change.

Fixes https://github.com/rui314/mold/issues/475
2022-04-27 13:13:14 +08:00
Rui Ueyama f378fdc495 Revert "[ELF] Fix regression in symbol name resolution"
This reverts commit d391fd9a59 because
it broke GCC builds.
2022-04-27 12:57:22 +08:00
Rui Ueyama 897f969017 [ELF] Handle --print-dependencies early
So that the option can be used to investigate why some symbol is
reported as a duplicated one.
2022-04-27 12:11:10 +08:00
Rui Ueyama 17907964ac Merge pull request #474 from llunak/gdb-index-size-3
[ELF] handle also DW_FORM_addrx3 and DW_FORM_strx3
2022-04-26 19:31:51 +08:00
Luboš Luňák 9431704230 [ELF] handle also DW_FORM_addrx3 and DW_FORM_strx3
Apparently these also may get used with large enough binaries,
despite being somewhat tricky with regard to endianess.

Signed-off-by: Luboš Luňák <[email protected]>
2022-04-26 13:23:31 +02:00
Rui Ueyama 1b5735543f Merge pull request #470 from llunak/gdb-index-address-size
Gdb index address size
2022-04-26 18:48:56 +08:00
Luboš Luňák 886695d914 [ELF] check DWARF address size
The current code assumes the debuginfo address size is equal to the
native address size, which should be the case, but check that just
in case it isn't.
2022-04-26 11:17:02 +02:00
Rui Ueyama 0fd6a6ca90 [ELF] Interpret DW_RLE_ DWARF record correctly
Fixes https://github.com/rui314/mold/issues/467
2022-04-26 16:29:20 +08:00
Rui Ueyama d391fd9a59 [ELF] Fix regression in symbol name resolution
This fix is needed to build Gentoo's net-fs/fuse package.
2022-04-26 15:26:52 +08:00
Luboš Luňák face536c39 launch gdb with -nx (ignore all .gdbinit)
Otherwise the test may fail simply because .gdbinit setup does
something strange (I happen to have 'set auto-solib-add off', which
disables loading debug info by default).
2022-04-26 09:12:29 +02:00
Rui Ueyama 3015f5e418 Fix typo
Pointed out by @llunak.
2022-04-25 16:07:05 +08:00
Rui Ueyama fc9f9e570e Simplify 2022-04-25 14:26:22 +08:00
Rui Ueyama f1e925d416 Update comments 2022-04-25 13:31:12 +08:00
Rui Ueyama a761f6a75c Improve documents 2022-04-25 13:14:45 +08:00
Rui Ueyama ea600a752b Do not run ./dist.sh on every invocation 2022-04-24 16:36:17 +08:00
Rui Ueyama fa6d0c33d7 [ELF] Hide an unversioned symbol if a versioned one exists
An object file can contain both unversioned and versioned symbols for
the same symbol. For example, the following piece of code will be
compiled to an object file that will contain `foo` and `foo@VERSION`.

  void foo() {}
  asm(".symver foo, foo@VERSION");

If this object file is given to GNU BFD linker, it exports only
`foo@VERSION` and suppresses `foo`. I believe the rationale for doing
that is, if a symbol is versioned, all of its versions must be
versioned. In other words, `foo@VER1`, `foo@VER2` and `foo@@VER3` can
co-exist, but `foo@VER1` and `foo` can't. In the latter case, if you
want to provide `foo` as the default version, it should be exported
not as `foo` but as `foo@@SOME_VERSION` (with double at-signs).

Fixes https://github.com/rui314/mold/issues/426
2022-04-24 12:09:50 +08:00
Rui Ueyama b516828b37 Add a script to install build dependencies 2022-04-23 18:34:40 +08:00
Rui Ueyama 5a2589bd94 Upgrade the bundled mimalloc to v2.0.6 2022-04-23 17:16:25 +08:00
Rui Ueyama 4f4bfdbba0 [ELF] Fix a regression
`read_pubnames` uses `compunits_idx`, so we can't move this piece of
code above the loop that computes `compunits_idx`.
2022-04-23 17:12:56 +08:00
Rui Ueyama a830fcdb58 Simplify 2022-04-23 17:01:24 +08:00
Rui Ueyama fd8a6a2c5d Simplify 2022-04-23 16:44:47 +08:00
Rui Ueyama ac244ede10 [ELF] Make .gdb_index contents reproducible
Previously, our output for .gdb_index depended on the iteration order of
ConcurrentMap. Since the iteration order varies on every run of the linker
 due to thread scheduling randomness, our .gdb_index were different on
 every lihnker invocation.

In mold, we guarantee that our output is the same as long as the same
command line options and input files are given to the same version of mold.
So the situation clearly violated the rule.

This commit fixes that issue.
2022-04-23 15:36:21 +08:00
Rui Ueyama 5d4e7a9e31 Update comments 2022-04-23 15:36:21 +08:00
Rui Ueyama 1cce39f113 Merge pull request #455 from llunak/gdb-zero-address-crash
[ELF] do not add 0 addresses to .gdb_index
2022-04-23 11:50:12 +08:00
Rui Ueyama f9768c6352 [ELF] Set _TLS_MODULE_BAES_ to 0 if there's no TLS segment 2022-04-22 17:10:23 +08:00
Rui Ueyama fe134ab3ab Simplify 2022-04-22 16:04:45 +08:00
Rui Ueyama f97ff51a72 [ELF] Assume all output is in little-endian
Currently, is_le is always true, so this is essentially dead code.
2022-04-22 15:45:27 +08:00
Rui Ueyama b05bf30e57 Simplify 2022-04-22 15:41:23 +08:00
Rui Ueyama 6baef60a48 [ELF] Fix .debug_rnglists reader
Fixes https://github.com/rui314/mold/issues/453
2022-04-22 15:00:02 +08:00
Rui Ueyama b101bfbf5f Update comments 2022-04-22 15:00:02 +08:00
Rui Ueyama f3adbe7c8f Update comments 2022-04-22 13:42:35 +08:00
Rui Ueyama a8c4c71dd7 Simplify 2022-04-22 13:24:26 +08:00
Rui Ueyama eb5de9c12f [ELF] Recognize DW_FORM_udata
Fixes https://github.com/rui314/mold/issues/453
2022-04-22 13:11:06 +08:00
Rui Ueyama 23218e7ae2 [ELF] Fix output of --perf 2022-04-22 12:35:05 +08:00
Rui Ueyama 8c5e4df741 [ELF] Ignore comdat groups GCC emits for .debug_macro
GCC creates a .debug_macro section if -g3 is given. That section
is in a comdat group, but the section is directly referred by another
section, which is a violation of the ELF spec.

If a section is deduplicated, we handle any references to that section
as if they had value 0. But that causes a mysterious gdb slowdown.
So we can't set 0 for a dead .debug_macro section.

In this commit, we simply stop deduplicating .debug_macro sections.
This will bloat up debug info, but that's better than producing an
effectively non-debuggable binary.

Fixes https://github.com/rui314/mold/issues/357
Fixes https://github.com/rui314/mold/issues/438
2022-04-22 12:24:22 +08:00
Rui Ueyama 92505f4aea [ELF] Do not fail if a debug info record contains only DW_AT_low_pc 2022-04-22 11:40:55 +08:00
Rui Ueyama d1a723a53a Add inline a hot function 2022-04-22 11:37:23 +08:00
Rui Ueyama de45e4af6d Refactor 2022-04-22 11:33:19 +08:00
Rui Ueyama ad3487376c Imrpove tests 2022-04-22 11:10:45 +08:00
Rui Ueyama 3b3333a27f [ELF] Make --gdb-index work with compressed output debug sections
Previously, we read compressed bogus data from the .debug_info section.

Fixes https://github.com/rui314/mold/issues/440
2022-04-22 08:55:16 +08:00
Luboš Luňák 9c865b976b [ELF] do not add 0 addresses to .gdb_index
GDB crashes in that case in dw2_find_pc_sect_compunit_symtab()
for a reason I do not understand. This is presumably what I was
trying to avoid already in e0dd53b4ad
but didn't quite manage (so reverting that part).

Signed-off-by: Luboš Luňák <[email protected]>
2022-04-21 17:52:05 +02:00
Rui Ueyama 494b28cfb3 Merge pull request #452 from llunak/fix-dw-rle-start-length
[ELF] fix DW_RLE_start_length
2022-04-21 21:01:46 +08:00
Rui Ueyama d4d1f2c697 Simplify 2022-04-21 20:59:48 +08:00
Luboš Luňák 00381ea64b [ELF] fix DW_RLE_start_length
Signed-off-by: Luboš Luňák <[email protected]>
2022-04-21 14:53:40 +02:00
Rui Ueyama 9781d35aba Simplify 2022-04-21 20:50:38 +08:00
Rui Ueyama ead0c96187 Style changes 2022-04-21 20:30:15 +08:00
Rui Ueyama eed62bd9d4 Update a test 2022-04-21 20:05:52 +08:00
Rui Ueyama 6d5c44ab58 Merge pull request #451 from llunak/gcc-dwarf5
[ELF] handle DW_FORM_implicit_const in .debug_abbrev
2022-04-21 20:03:28 +08:00
Luboš Luňák 5b28bfd6c8 [ELF] handle DW_FORM_implicit_const in .debug_abbrev
This one form has an extra uleb field directly in .debug_abbrev,
so it needs to be skipped too. This is not a problem with Clang,
as that one seems to always put DW_TAG_compile_unit first
in .debug_abbrev, but GCC with DWARF5 doesn't and this code
didn't find it.
Another stylistic minor problem in this code was that abbrev_code
and has_children weren't skipped over, although that got silently
handled by the first iteration where the 1-byte has_children
flag was read as 1-byte uleb.
2022-04-21 13:49:41 +02:00
Rui Ueyama bad0cbc72a Revert "Remove a test that doesn't work yet"
This reverts commit bd65e0908f
because --gdb-index should now work with DWARF5.
2022-04-21 19:23:51 +08:00
Rui Ueyama b6fb244f14 Merge pull request #448 from llunak/gdb-index-fixes
Gdb index fixes
2022-04-21 19:20:36 +08:00
Rui Ueyama 1c84145810 Remove an unnecessary command
`make install` now creates /usr/local/libexec/ld as a a relative
symbolic link, so this `ln` is not needed.
2022-04-21 19:11:09 +08:00
Rui Ueyama f945077e42 Merge pull request #450 from marxin/gdb-tests-batch-mode
Use -batch mode for gdb tests.
2022-04-21 18:18:40 +08:00
Luboš Luňák e0dd53b4ad [ELF] use better gdb index address dummy values
If start of the previous is used, gdb crashes for me, but end seems
to be fine. I'm not sure why, but I think end is better because
that is an address that is one beyond the end, so it shouldn't match
anything, or maybe end shouldn't be 0.
Also set some CU index, otherwise those random bogus values look
strange when dumping the content.

Signed-off-by: Luboš Luňák <[email protected]>
2022-04-21 11:04:16 +02:00
Luboš Luňák 267a1ff5b7 [ELF] handle properly DW_FORM_rnglistx
The value is an index (offset by DW_AT_rnglists_base) into the first
part of .debug_rnglists, which is a list of offsets into the second
part of .debug_rnglists, which lists ranges, each entry starting
with a value describing how to interpret the data.

Signed-off-by: Luboš Luňák <[email protected]>
2022-04-21 11:04:16 +02:00
Luboš Luňák 93cefc5280 [ELF] handle properly DW_FORM_addrx*
The value is not the address, it's an index into .debug_addr
that's additionally offset by DW_AT_addr_base.

Signed-off-by: Luboš Luňák <[email protected]>
2022-04-21 11:04:16 +02:00
Martin Liska b3e0955d88 Use -batch mode for gdb tests.
Use the mode, otherwise one can be asked things like:
Quit anyway? (y or n)

which make the test stuck.

Signed-off-by: Martin Liska <[email protected]>
2022-04-21 10:15:45 +02:00
Luboš Luňák c7339c33e0 [ELF] separate reading and skipping of DW_FORM_* data
Handling properly e.g. DW_FORM_loclistx is non-trivial and
actually not needed at all for .gdb_index, so it's enough to know
how to skip it. For the reading function it's enough to handle
only those forms that are needed by DW_AT_low_pc, DW_AT_high_pc
and DW_AT_ranges (and AFAICT the function now includes all of those,
although for some of them the implementation is incorrect).

Signed-off-by: Luboš Luňák <[email protected]>
2022-04-21 10:14:38 +02:00
Luboš Luňák 1ac4030556 [ELF] support DWARF5 split debug compile unit info
For DWARF5 split debug .o's get a slightly different .debug_info
entry that's larger, but for the purpose here it's otherwise
the same.

Signed-off-by: Luboš Luňák <[email protected]>
2022-04-21 10:02:47 +02:00
Luboš Luňák 478871c06e [ELF] do not include base selection range entry in gdb index
DWARF4 2.17.3 says that an entry where start address is the max
possible offset is a base selection entry and the end address
is actually a value to add to all addresses. The gdb_index spec
doesn't say if this entry is allowed in the address list, but
gold doesn't include it, so apply and drop it too.

Signed-off-by: Luboš Luňák <[email protected]>
2022-04-21 10:02:43 +02:00
Luboš Luňák d18d971962 [ELF] detect and bail out on DWARF64
It uses different sizes for some fields, and the dwarf mold code
is not ready to read it (it'd need converting those relevant calls
from reading u32 to optionally reading u64 instead).

Signed-off-by: Luboš Luňák <[email protected]>
2022-04-21 10:02:39 +02:00
Rui Ueyama b26e1a3c32 Fix -Wc++-narrowing errors on a 32 bits host 2022-04-21 15:44:29 +08:00
Rui Ueyama f12a9bb5ff Fix possible "recompile with -fPIC" errors
Fixes https://github.com/rui314/mold/issues/449
2022-04-21 15:38:12 +08:00
Rui Ueyama cf850f8993 [ELF] Handle TLS common symbols
Fixes https://github.com/rui314/mold/issues/447
2022-04-21 13:58:43 +08:00
Rui Ueyama ec062f7241 [ELF] Accept DWARF 2 and 3 for --gdb-index 2022-04-21 10:21:53 +08:00
Rui Ueyama fc798bc4ea Refactor 2022-04-21 09:59:36 +08:00
Rui Ueyama bd65e0908f Remove a test that doesn't work yet 2022-04-21 09:59:36 +08:00
Rui Ueyama 8a5a9e1ffe Revert "[ELF] Do not emit address ranges for --gdb-index"
This reverts commit d4cc0ed3fb
because it broke gdb's stacktrace.
2022-04-21 09:59:36 +08:00
Rui Ueyama c6dace2335 Merge pull request #446 from marxin/fix-warning-for-execstack-if-needed
Fix assembler warnings for a testcase.
2022-04-20 17:09:52 +08:00
Martin Liska 32e0863675 Fix assembler warnings for a testcase.
Fixes:

Testing execstack-if-needed ... {standard input}: Assembler messages:
{standard input}:4: Warning: setting incorrect section type for .note.GNU-stack
{standard input}:4: Warning: setting incorrect section attributes for .note.GNU-stack

Signed-off-by: Martin Liska <[email protected]>
2022-04-20 10:56:23 +02:00
Rui Ueyama 8398d592de [ELF] Add -z execstack-if-needed
Fixes https://github.com/rui314/mold/issues/427
2022-04-20 15:17:55 +08:00
Rui Ueyama fa2ff3b9e9 [ELF] Align .gdb_index to a 4 bytes boundary
.gdb_index contains lots of 4 bytes integers, so we should align
them to 4 bytes boundaries.
2022-04-20 13:59:56 +08:00
Rui Ueyama 3fb93c7cc8 Simplify 2022-04-20 10:21:39 +08:00
Rui Ueyama 8dddd98dfd Update README 2022-04-20 10:14:42 +08:00
Rui Ueyama 17f16d016c Update README 2022-04-20 10:00:48 +08:00
Rui Ueyama 21e1a80cec Add a test 2022-04-19 13:51:38 +08:00
Rui Ueyama d4cc0ed3fb [ELF] Do not emit address ranges for --gdb-index
.gdb_index contains two maps: a map from identifiers (type names,
function names or variable names) to compunits, and a map from
function address ranges to compunits. The latter is harder to create
because we needed to parse DWARF debug records to read function
address ranges. We generally don't want to do that.

This commit stops emitting address ranges. Now, .gdb_index sections
created by our linker contains the zero-length map as address ranges.
Though I'm not 100% sure if this is actually OK, it looks like gdb
works fine with that. It's at least worth a try.

https://github.com/rui314/mold/issues/439
https://github.com/rui314/mold/issues/396
2022-04-19 13:38:25 +08:00
Rui Ueyama a4398c7c32 [ELF] Factor out DWARF-related code to dwarf.cc 2022-04-19 12:43:51 +08:00
Rui Ueyama 7ebd071273 [ELF] Recognize --thinlto-{single-module,cache-dir,cache-policy}
They are defined as aliases for
--plugin-opt=thinlto-{single-module,cache-dir,cache-policy}.

https://github.com/rui314/mold/issues/336
2022-04-18 12:53:59 +08:00
Rui Ueyama 369e8a19c5 Simplify 2022-04-17 19:25:22 +08:00
Rui Ueyama d73587033f Simplify 2022-04-17 19:07:17 +08:00
Rui Ueyama 70bd1adbab [ELF] Handle --print-dependencies early
So that the dependency info is printed out even if the link will
eventually fail.
2022-04-17 19:06:58 +08:00
Rui Ueyama f675faade2 Fix typo 2022-04-17 19:06:58 +08:00
Rui Ueyama 3c895abefa Fix -Wc++11-narrowing
Fixes https://github.com/rui314/mold/issues/437
2022-04-17 16:05:28 +08:00
Rui Ueyama ff1b97bcdb [ELF] Recognize more DW_FORM tags
We don't need values of hte se DW_FORM tags, but we have to be
able to skip them in order to read a .debug_info section.
2022-04-17 16:00:15 +08:00
Rui Ueyama 19ad74ac52 Use python3 instead of python
If a system has only Python 3, it may not have `python` command.
2022-04-17 15:12:35 +08:00
Rui Ueyama 45df585268 Remove test for executable DSO
This test fails on some Linux systems, and it is essentially testing
not the mold's capabilities but the running platform's capabilities.
I don't think there's a portable, guaranteed way to create an
executable shared object on Linux, so even if it happens to work,
I don't think we can guarantee that.
2022-04-17 15:01:28 +08:00
Rui Ueyama deb212bbfc Fix for a compiler that does not support -gz=zlib-gnu 2022-04-17 14:51:23 +08:00
Rui Ueyama 1fa6b3cd17 [ELF] Allow to build only for x86-64 or ARM64
mold is usually built for all supported tagets, namely, x86-64, i386,
ARM32, ARM64 and RISCV64. This is a good thing because it makes cross
compilation easy. That is, as long as you have a copy of the mold linker,
it is guaranteed to work as a cross linker.

However, during a quick debug session in which you build mold many
times, you may want to build mold only for your native target. That
greatly reduces build time because it reduces the amount of code
after template instantiation.

Therefore, in this commit, I introduced new macros,
MOLD_DEBUG_X86_64_ONLY and MOLD_DEBUG_ARM64_ONLY, to build mold for
x86-64 and ARM64 only, respectively.

These flags should never be used for production. They are solely for
debugging purpose.
2022-04-17 13:02:19 +08:00
Rui Ueyama b0596ab8fb Run only for native target 2022-04-17 12:32:42 +08:00
Rui Ueyama 1e59bb518a Add comments 2022-04-17 12:01:15 +08:00
Rui Ueyama efcbb02e83 Remove unnecessary build dependency 2022-04-17 11:55:08 +08:00
Rui Ueyama d8a12490f5 [ELF] Do not exit with 0 if errors occured 2022-04-17 11:46:19 +08:00
Rui Ueyama b5a75c4215 [ELF] Support DWARF5 for --gdb-index
mold used to support only DWARF4.

Fixes https://github.com/rui314/mold/issues/436
2022-04-17 10:19:58 +08:00
Rui Ueyama 5803c3c200 Make /usr/local/libexec/ld really relative
Pointed out by Kévin Le Gouguec in https://github.com/rui314/mold/pull/425.
2022-04-16 17:14:55 +08:00
Rui Ueyama c90801e629 [ELF] Make --gdb-index work for compressed input debug sections
Previously, --gdb-index tries to read bogus compressed data from
input sections if input debug sections are compressed.

Fixes https://github.com/rui314/mold/issues/431
2022-04-16 15:00:21 +08:00
Rui Ueyama 8073a92614 Make /usr/local/libexec/ld a relative symlink
I didn't want to write a Python one-liner in the Makefile, but it
looks like it is in practice one of the most portable way to compute a
relative path.

https://github.com/rui314/mold/pull/425
2022-04-16 11:48:35 +08:00
Rui Ueyama c4c7e45886 Remove the logo from README
Sensitivity to this kind of image varies and could be an unneeded
friction to adopt the mold linker.
2022-04-16 11:00:17 +08:00
Rui Ueyama 6a6ae217a3 Merge pull request #433 from sicherha/suppress-debuginfod-prompt
Fix hanging unit test `gdb-index`
2022-04-16 10:38:11 +08:00
Rui Ueyama 30a0fac952 Merge pull request #434 from sicherha/skip-test-if-dwarfdump-unavailable
Skip test if `dwarfdump` is unavailable
2022-04-16 10:34:22 +08:00
Christoph Erhardt 133946af0c Skip test if dwarfdump is unavailable
Fixes #430.

Signed-off-by: Christoph Erhardt <[email protected]>
2022-04-15 20:34:04 +02:00
Christoph Erhardt c6ae4234b8 Fix hanging unit test gdb-index
This affects Fedora >= 35, where debuginfod is enabled by default. On
such systems, gdb shows the following interactive prompt and then waits
forever:
```
This GDB supports auto-downloading debuginfo from the following URLs:
https://debuginfod.fedoraproject.org/
Enable debuginfod for this session? (y or [n])
```

Unsetting the `DEBUGINFOD_URLS` environment variable disables the prompt
as documented here: https://fedoraproject.org/wiki/Debuginfod#Disabling

Signed-off-by: Christoph Erhardt <[email protected]>
2022-04-15 19:08:15 +02:00
Rui Ueyama 1f55e40a8a Canonicalize the tar file name for ARM64 2022-04-15 20:02:37 +08:00
Rui Ueyama f86868cb38 Bump mold version to 1.2.0 2022-04-15 17:08:14 +08:00
Rui Ueyama 421289445a Remove dist.sh's output on make clean 2022-04-15 17:08:14 +08:00
Rui Ueyama 100922b650 [ELF] Fix section file offsets
Previously, if a section has a very large alignment requirement,
that section and the following sections may get wrong file offsets.

Fixes https://github.com/rui314/mold/issues/405
2022-04-15 14:59:09 +08:00
Rui Ueyama 0daf6233fb [ELF] Fix R_RISCV_ALIGN relocations
Fixes https://github.com/rui314/mold/issues/419
2022-04-15 14:37:55 +08:00
Rui Ueyama d0e4eee204 [ELF] Print out a warning for .note.GNU-stack
https://github.com/rui314/mold/issues/427
2022-04-14 11:47:54 +08:00
Rui Ueyama a7475dd5e3 [ELF] Support --gdb-index
This is a tough one because .gdb_index, .debug_gnu_pubnames,
.debug_gnu_pubtypes and DWARF are underdocumented, and DWARF is
complicated even if you have a right documentation. But, I believe I
managed to create a correct .gdb_index section.

Just like ld.lld, mold's --gdb-index needs all input object files to
have been compiled with -ggnu-pubnames. We read symbol names and type
names from the sections generated by -ggnu-pubnames.

Unlike ld.gold and ld.lld, we do not use an external library to read
DWARF debug info records.

As always, this feature is implemented with speed in mind. For Clang
15 which is built with -ggnu-pubnames, mold takes ~150 ms to create a
~300 MiB .gdb_index section on a simulated 16-core machine.

Fixes https://github.com/rui314/mold/issues/396
2022-04-13 19:01:17 +08:00
Rui Ueyama c4af13889d Refactor 2022-04-10 11:03:53 +08:00
Rui Ueyama 7aaa4afce7 Refactor 2022-04-10 10:06:41 +08:00
Rui Ueyama 2fb96ad83f Ignore tar file for mold binary distribution 2022-04-10 09:09:29 +08:00
Rui Ueyama a2fa4e5ecc Update README 2022-04-10 09:08:05 +08:00
Rui Ueyama 68877ab6ca Use mold in our CI 2022-04-10 08:51:51 +08:00
Rui Ueyama f62777e606 Merge pull request #424 from yurai007/fix-memory-leak
Fix memory leak caught by Memcheck
2022-04-09 19:52:07 +08:00
Dawid Jurczak c80e316649 Fix memory leak caught by Memcheck
This patch fix memory leak reported by Memcheck while running some tests.
The problem happen even with --no-quick-exit option.
Before change there are blocks definitely and indirectly lost seen in Memcheck summary:

==1202== LEAK SUMMARY:
==1202==    definitely lost: 1,120 bytes in 14 blocks
==1202==    indirectly lost: 633 bytes in 12 blocks
==1202==      possibly lost: 56,408 bytes in 46 blocks
==1202==    still reachable: 128 bytes in 1 blocks
==1202==         suppressed: 0 bytes in 0 blocks

After change number of such blocks drops to zero:

==2137== LEAK SUMMARY:
==2137==    definitely lost: 0 bytes in 0 blocks
==2137==    indirectly lost: 0 bytes in 0 blocks
==2137==      possibly lost: 56,408 bytes in 46 blocks
==2137==    still reachable: 128 bytes in 1 blocks
==2137==         suppressed: 0 bytes in 0 blocks

Signed-off-by: Dawid Jurczak <[email protected]>
2022-04-09 13:30:21 +02:00
Rui Ueyama d1b9549817 [ELF] Do not ignore --dynamic-linker even if --shared is given
It is very rare, but technically you can create a shared object that
can also be executed directly. You can do that by giving a dynamic
linker path to the linker.

https://github.com/rui314/mold/issues/422
2022-04-09 18:35:04 +08:00
Rui Ueyama 01d2dd8dd9 Allow to pass extra CXXFLAGS 2022-04-09 15:39:32 +08:00
Rui Ueyama 6109154a07 Refactor 2022-04-09 15:24:51 +08:00
Rui Ueyama 49d4dac7e6 Push a build environment to DockerHub 2022-04-09 14:43:16 +08:00
Rui Ueyama 87a5f238dd Fix CI 2022-04-09 13:18:22 +08:00
Rui Ueyama e448e0eb2b [ELF] Write tombstone values to dead debug info records
This is an attempt to fix https://github.com/rui314/mold/issues/357.
2022-04-09 10:40:25 +08:00
Rui Ueyama 4df5d6497a Break down test-all into smaller targets 2022-04-09 10:21:18 +08:00
Rui Ueyama e90ad9be16 Build OpenSSL 3 only once
dist.sh compiles OpenSSL 3 for a license reason. We don't need to
build it every time the script is run.
2022-04-08 19:04:19 +08:00
Rui Ueyama b5788e0caa [ELF] Document new command line options 2022-04-08 18:37:29 +08:00
Rui Ueyama 9178e43681 Add comments 2022-04-08 14:36:59 +08:00
Rui Ueyama 5feab826de [ELF] Fix _TLS_MODULE_BASE_ relocations
Fixes https://github.com/rui314/mold/issues/421
2022-04-08 13:34:43 +08:00
Rui Ueyama 2fc0231348 Update comments 2022-04-07 16:22:07 +08:00
Rui Ueyama 804ae412ed [ELF][ARM64] Do not create a canonical PLT for PIE
Position-independent executable shouldn't have a canonical PLT.
2022-04-07 16:00:27 +08:00
Rui Ueyama f0a030cbcd [ELF] Add --disable-new-dtags
Fixes https://github.com/rui314/mold/issues/420
2022-04-07 15:26:59 +08:00
Rui Ueyama ba6347996b [ELF] Implement a workaround for libbacktrace
This commit enables mold to work with libbacktrace before 2022-04-06.

https://github.com/rui314/mold/issues/402
2022-04-07 14:35:01 +08:00
Rui Ueyama a151f4180f Refactor 2022-04-07 14:21:49 +08:00
Rui Ueyama 2c947ce2a9 [ELF][X86_64] Allow GOTPC32_TLSDESC to take registers other than %rax 2022-04-07 11:26:06 +08:00
Rui Ueyama 63b7102a4c [ELF] Define _TLS_MODULE_BASE_
This symbol is used by some object files that use TLSDESC.

Fixes https://github.com/rui314/mold/issues/421
2022-04-07 11:25:17 +08:00
Rui Ueyama 731dd0ed25 [ELF] Support --oformat=binary
With this change, you can link a simple bootloader using mold.
To do so, compile bootloader source files to object files with
the `-fno-PIC` flag and then invoke mold on the object files with
`-Ttext=<bootloader-start-address>` and `--oformat=binary`.

The .text segment is usually at the beginning of the output file if
the file is created that way. By passing the startup code as the first
file argument to the linker, you can place that startup code at the
beginning of the file.

Fixes https://github.com/rui314/mold/issues/418
2022-04-06 19:13:43 +08:00
Rui Ueyama 3105195364 [ELF] Make -Map to output address in hex 2022-04-06 19:13:43 +08:00
Rui Ueyama 23045c6f95 [ELF] Do not create synthetic sections if not necessary 2022-04-06 18:04:42 +08:00
Rui Ueyama 2d29f234e2 [ELF] Change output section layout 2022-04-06 16:35:38 +08:00
Rui Ueyama 4edaf82691 Fix CI 2022-04-06 15:03:37 +08:00
Rui Ueyama 49aa10318c [ELF] Add --section-start 2022-04-06 14:45:31 +08:00
Rui Ueyama 2c03ed5673 Add comments 2022-04-06 11:08:29 +08:00
Rui Ueyama e0bc74ad8a [ELF] Create canonical PLTs only when needed
Previously, we make all PLT entries canonical if we are creating
a position dependent executable, because I was thinking that promoting
usual PLT entries to canonical ones is harmless; symbol equality still
holds.

However, it looks like Qt depends on the usual linker's behavior not
to make PLT canonical if not necessary. I believe they are maintaining
some hidden symbol as aliases for exported symbols and compare their
addresses at runtime.

Of course this doesn't work if your program is not compiled with -fPIC,
but qt5/QtCore/qglobal.h has a macro to abort compilation if PIC is
disabled. (They check for __PIC__ and __PIE__ macros.) So, all object
files are guaranteed to be compiled with -fPIC if they are using QT
functions, and they assume that the linker doesn't create a canonical
PLT for Qt functions.

This commit makes mold to create canonical PLTs only when needed.
That is, if an address of a function is directly taken (i.e. not via
GOT), then mold makes its PLT canonical.

Fixes https://github.com/rui314/mold/issues/352
2022-04-05 21:02:42 +08:00
Rui Ueyama 3768ca612e [ELF] Deprecate --preload
It looks like no one is using --preload, so there's no point to
maintain this feature.

https://github.com/rui314/mold/issues/414
2022-04-05 12:41:50 +08:00
Rui Ueyama 86d59c29eb [ELF][ARM32] Handle TLS_LDO32 relocations in non-alloc sections
Fixes https://github.com/rui314/mold/issues/417
2022-04-05 04:22:16 +00:00
Rui Ueyama 96a4a1b635 [ELF][ARM64] Support non-NC variant of MOVW_UABS relocations
We need to implement an overflow check for non-NC relocations,
but for now they are just aliases for NC variants.

Fixes https://github.com/rui314/mold/issues/416
2022-04-05 02:50:43 +00:00
Rui Ueyama 006b13aec1 Refactor 2022-04-04 17:26:11 +08:00
Rui Ueyama 91947405fe Attempt to silence CI 2022-04-04 17:06:47 +08:00
Rui Ueyama b7123bded5 [ELF] Fix tests for non-x86-64 targets 2022-04-04 16:36:43 +08:00
Rui Ueyama 0884f279e0 [ELF][x86] Always create .got.plt
glibc's -static-pie implementation expect that _GLOBAL_OFFSET_TABLE_
is at the beginning of .got.plt, as it uses the address of _DYNAMIC
which is stored at _GLOBAL_OFFSET_TABLE_[0].

In this patch, we always create .got.plt for x86-64 and i386.
2022-04-04 16:35:22 +08:00
Rui Ueyama 615a24d1dd Add comments 2022-04-03 19:12:10 +08:00
Rui Ueyama e1e4e9fd9e Fix data races found by ThreadSanitizer 2022-04-03 15:08:57 +08:00
Rui Ueyama ceed69ff49 [ELF] Fix crash bug in ICF
Fixes https://github.com/rui314/mold/issues/398
2022-04-03 13:41:13 +08:00
Rui Ueyama d90f7e162b [ELF] Improve error message
Fixes https://github.com/rui314/mold/issues/412
2022-04-03 12:31:31 +08:00
Rui Ueyama 340528bdc3 Update mimalloc to v2.0.5
Fixes https://github.com/rui314/mold/issues/281
2022-04-03 12:00:23 +08:00
Rui Ueyama 392781a0e2 [ELF][i386] Sort .ctors and .dtors sections 2022-04-03 10:43:22 +08:00
Rui Ueyama 4e10ee7e50 [ELF] Run tests for all targets on CI 2022-04-02 21:27:45 +08:00
Rui Ueyama 8d94fd6ca3 [ELF][ARM64] Fix a test 2022-04-02 18:05:05 +08:00
Rui Ueyama 358f244247 [ELF][RISCV64] Fix a test 2022-04-02 18:00:23 +08:00
Rui Ueyama 7a1cbb9b34 [ELF][ARM32] Support R_ARM_THM_JUMP11 2022-04-02 17:35:55 +08:00
Rui Ueyama e6d4154688 [ELF] Generalize tests
With this change, you can now cross compile test cases and run
them on qemu-user. Here is an example to run our test suits in
an emulated ARM32 environment.

$ CC=arm-linux-gnueabihf-gcc \
  CXX=arm-linux-gnueabihf-g++ \
  GCC=arm-linux-gnueabihf-gcc \
  GXX=arm-linux-gnueabihf-g++ \
  OBJDUMP=arm-linux-gnueabihf-objdump \
  MACHINE=arm \
  QEMU='qemu-arm -L /usr/arm-linux-gnueabihf' \
  make -j16 test
2022-04-02 16:53:41 +08:00
Rui Ueyama 60eae9ed20 [ELF][ARM32] Support R_ARM_GOT_PREL 2022-04-02 01:46:48 +00:00
Rui Ueyama 7fb1b1b9ec Merge pull request #399 from alois31/r_aarch64_ld_prel_lo19
[ELF][ARM64] Support R_AARCH64_LD_PREL_LO19 relocations
2022-04-01 13:44:39 +08:00
Rui Ueyama 0ecd72900e Attempt to fix CI 2022-04-01 13:32:01 +08:00
Rui Ueyama 9eb4e76daf Attempt to fix CI 2022-04-01 13:20:17 +08:00
Rui Ueyama b6876b5640 Update comment 2022-04-01 13:12:27 +08:00
Rui Ueyama f4753b34bf [ELF] Fix use-after-free found by ASAN 2022-04-01 13:12:10 +08:00
Rui Ueyama 8196199cac Refactor 2022-04-01 12:52:21 +08:00
Rui Ueyama 2a3ee11b7d Merge pull request #400 from nick-rawlings/parse_unsigned_number
image-base i64 to u64 parse_unsigned_number
2022-04-01 12:36:44 +08:00
Rui Ueyama 68f2a26987 Refactor 2022-04-01 02:49:57 +00:00
Rui Ueyama 227a6c8a88 [ELF][ARM32] Fix TLSDESC relocations 2022-04-01 02:47:29 +00:00
Rui Ueyama fe617c3618 [ELF][ARM32] Support R_ARM_MOVW_ABS_NC and R_ARM_MOVT_ABS 2022-04-01 02:47:29 +00:00
Rui Ueyama e3a7c9e017 [ELF][RISCV] Disable a test that doesn't work with RISCV64 2022-03-31 13:24:34 +00:00
Rui Ueyama 5ee6f89544 Revert "Attempt to fix a build issue with libc++14"
This reverts commit 8e3cee958b
because it broke the RISC-V target.
2022-03-31 13:24:19 +00:00
Rui Ueyama 40c2ad7839 [ELF][RISCV64] Fix tests 2022-03-31 08:16:07 +00:00
Rui Ueyama 5edd07efd9 Refactor 2022-03-31 01:47:56 +00:00
Rui Ueyama 8e5def28ce Refactor 2022-03-31 00:46:33 +00:00
Rui Ueyama b534d5af27 Add comments 2022-03-30 14:11:34 +00:00
Rui Ueyama 673f531adb Add comments 2022-03-30 13:57:17 +00:00
Rui Ueyama 66d3de438c Attempt to fix CI 2022-03-30 09:36:38 +00:00
Rui Ueyama d9ea875677 [ELF][ARM32] Implement many relocations
With this change, most tests in test/elf/ directory pass on ARM32.
2022-03-30 09:26:32 +00:00
Rui Ueyama 577361478a Fix CI
This reverts commit 408e2bfee8.
2022-03-29 11:23:30 +00:00
Rui Ueyama 408e2bfee8 Improve tests 2022-03-29 06:47:17 +00:00
Rui Ueyama 9ac23730b7 Merge pull request #408 from yurai007/fix-some-ubsan-errors
[ELF] Fix issues caught by UBSan
2022-03-28 16:39:24 +08:00
Dawid Jurczak bf26753bbd [ELF] Fix issues caught by UBSan
While running tests on UBSan instrumented mold binary 2 separated problems are reported:

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior elf/main.cc:592:15 in
elf/output-chunks.cc:1866:24: runtime error: member call on null pointer of type 'mold::elf::VerdefSection<mold::elf::X86_64> *'

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior elf/output-chunks.cc:1866:24 in
elf/input-files.cc:1000:8: runtime error: load of value 190, which is not a valid value for type 'bool'

This change fixes both of them.

Signed-off-by: Dawid Jurczak <[email protected]>
2022-03-28 09:43:28 +02:00
Rui Ueyama 8e3cee958b Attempt to fix a build issue with libc++14
https://github.com/rui314/mold/issues/407
2022-03-27 08:15:25 +00:00
Rui Ueyama 05f4a43c8f [ELF][ARM64] Allow TLSGD relocations in statically-linked executables 2022-03-27 07:48:42 +00:00
Rui Ueyama ca227fb8da Refactor 2022-03-27 06:58:28 +00:00
Rui Ueyama 78e4b06cb8 Fix a regression 2022-03-26 01:19:28 +00:00
Rui Ueyama 94cace7fc1 Refactor 2022-03-25 11:46:34 +00:00
Rui Ueyama 812c59fd5c Refactor 2022-03-23 15:00:29 +00:00
Rui Ueyama 8770bd775b [ELF][ARM] Fix test 2022-03-23 14:54:26 +00:00
Rui Ueyama 89d43f2673 Fix test
So that this test works on ARM32.
2022-03-23 14:41:40 +00:00
Rui Ueyama 632a2ec1b4 [ELF][ARM] Set e_flags to EABI version 5
All binaries should have this version now. GNU binutils do not allow
users to link EABI version 5 object fiels to EABI version 0 DSOs.
2022-03-23 14:38:06 +00:00
Rui Ueyama 6af78bf17b [ELF][ARM32] Do not keep .ARM.attributes sections
ARM32 object files usually contain a .ARM.attributes section.
We need to parse and merge .ARM.attributes sections.
But for now, we just remove them from inputs.
2022-03-23 14:11:14 +00:00
Rui Ueyama 9360267cc3 Refactor 2022-03-23 11:18:27 +00:00
Rui Ueyama 66b995b5a9 [ELF][ARM32] Remove unsupported relocations 2022-03-23 09:11:31 +00:00
Rui Ueyama 94e2d7d6dc [ELF][ARM32] Fix R_ARM_THM_CALL relocation 2022-03-23 08:43:27 +00:00
Rui Ueyama 759aa95618 [ELF][ARM32] Fix R_ARM_THM_MOVT_ABS relocation 2022-03-23 03:12:29 +00:00
Rui Ueyama 575a604d5d [ELF][ARM32] Handle relocations against non-alloc sections 2022-03-23 01:44:19 +00:00
Rui Ueyama ac9a1c4048 [ELF][ARM32] Add a link to a documentation 2022-03-23 00:50:26 +00:00
Rui Ueyama d5cf590498 [ELF][ARM32] Support basic relocations
With this change, mold can link dynamically-linked "Hello world"
program for ARM32.
2022-03-22 12:52:07 +00:00
Rui Ueyama 18656091f6 Rename a test 2022-03-22 12:24:10 +00:00
Rui Ueyama ead32811b3 Fix a test for AArch64
Currently, we do not support relaxations of TLS GD/LD relocations
for ARM64. This is in practice not a problem because TLSDESC is used
on ARM64 by default.

However, there's one situation in which not supporting TLS GD/LD
relaxation becomes an issue; static linking. If an executable is
statically-linked, relaxation is mandatory because we can't generate
dynamic relocations for GD/LD relocations.

In this patch, we simply report an error if an object file compiled
with TLS GD/LD is used for creating a statically-linked executable.

This commit fixes all tests on ARM64.
2022-03-21 02:49:50 +00:00
Rui Ueyama 7cdfa31e6c Refactor 2022-03-20 14:21:46 +00:00
Rui Ueyama a6e4676a71 Merge pull request #401 from yurai007/do-not-hardcode-GCC-version-in-tests
[ELF][RISC-V] Do not hardcode GCC version in tests
2022-03-20 09:25:43 +08:00
Dawid Jurczak 0c88d323c8 [ELF][RISC-V] Do not hardcode GCC version in tests
Signed-off-by: Dawid Jurczak <[email protected]>
2022-03-19 17:22:03 +01:00
Rui Ueyama 326150a182 Merge pull request #390 from mrichtarsky/main
Improve help
2022-03-19 22:39:52 +08:00
nick-rawlings 339816702d Update cmdline.cc
use stoul for unsigned long

image-base i64 to u64 parse_unsigned_number

Signed-off-by: nick-rawlings <[email protected]>
2022-03-17 21:28:10 -05:00
Alois Wohlschlager 146ddd711c [ELF][ARM64] Support R_AARCH64_LD_PREL_LO19 relocations
Implement support for the R_AARCH64_LD_PREL_LO19 relocation type. Since
this actually behaves the same way as R_AARCH64_CONDBR19, reuse the
relevant code.

Signed-off-by: Alois Wohlschlager <[email protected]>
2022-03-17 15:44:49 +01:00
Martin Richtarsky 32d1006e29 Improve help
Signed-off-by: Martin Richtarsky <[email protected]>
2022-03-10 16:06:42 +00:00
Rui Ueyama 66a057cce7 [ELF][ARM64] Add a stub for ARM32 2022-03-10 16:27:31 +09:00
Rui Ueyama 619ff869e4 [ELF][i386] Implement GD → LE and LD → LD relaxations
This commit implements TLS relocation relaxations.

Fixes https://github.com/rui314/mold/issues/388
2022-03-10 15:18:43 +09:00
Rui Ueyama e7c071ea36 [ELF] Improve an error message 2022-03-10 13:54:16 +09:00
Rui Ueyama 3d68824dea [ELF][ARM64] Fix IFUNC relocations in -static-pie executables
For a static position-independent executable, a libc's intitialization
routine reads the dynamic relocation table and apply them. It looks like
on ARM64, they simply apply relocations from the begining of the table
to end. Therefore, if an IFUNC relocation appears before RELATIVE relocs,
the IFUNC resolver would see an unrelocated value. So, we need to place
RELATIVE relocs before IFUNCs.

Fixes https://github.com/rui314/mold/issues/382
2022-03-09 18:04:34 +09:00
Rui Ueyama c98d276916 [ELF][ARM64] Fix a test
For some reason, readelf doesn't like a build-id if it's very short.
2022-03-09 17:00:53 +09:00
Rui Ueyama 446c461201 [ELF][ARM64] Fix debug info section
This fixes a regression introduced in 92876820cb.
Until now, mold set bogus addresses to non-alloc sections and
as a result emitted corrupted debug info.

Fixes https://github.com/rui314/mold/issues/387
2022-03-09 16:04:03 +09:00
Rui Ueyama 98edd441ce [ELF] Do not print out an error of ldd --version
Some `ldd` impls don't support the --version option. We do not
want to show the error message but instead just skip the test
entirely.

https://github.com/rui314/mold/pull/385
2022-03-09 14:53:10 +09:00
Rui Ueyama 37f6ef2081 [ELF] Fix a crash bug for -noinhibit-exec
After a certain point, it is not expected that there's a remaining
undefined symbol. -noinhibit-exec did not respect that invariant,
which caused a crash bug on ARM64.

This change forces all symbols to be resolved if --noinhibit-exec
is given.

Fixes https://github.com/rui314/mold/issues/383
2022-03-09 11:38:46 +09:00
Rui Ueyama 41cf6d7814 [ELF][ARM64] Avoid -mcmodel=large and -no-PIC
Such combination is not supported by GCC.

Fixes https://github.com/rui314/mold/issues/384
2022-03-09 11:36:44 +09:00
Rui Ueyama bb5a596bc5 Set LC_ALL=C to get consistent output from shell comands
We unset `LANG`, but it looks like `LC_ALL` takes precedence over `LANG`,
so we should set `LC_ALL` to `C`.

Reported at https://github.com/rui314/mold/pull/385
2022-03-09 09:03:22 +09:00
Rui Ueyama 1b6f301644 Merge pull request #381 from Scrumplex/ignore-dy
[ELF] Add --dy and --dn aliases
2022-03-08 20:43:08 +09:00
Sefa Eyeoglu 8a089fee45 [ELF] Move --static option in helpmsg
Signed-off-by: Sefa Eyeoglu <[email protected]>
2022-03-08 10:53:32 +01:00
Sefa Eyeoglu 82e80721ac [ELF] Add --dy and --dn aliases
GNU ld aliases these to -Bdynamic and -Bstatic respectively.

Signed-off-by: Sefa Eyeoglu <[email protected]>
2022-03-08 10:53:27 +01:00
Rui Ueyama d3dea2f435 Merge pull request #380 from sicherha/static-pie-glibc-version-requirement
Increase required glibc version for `-static-pie` tests
2022-03-08 18:37:21 +09:00
Christoph Erhardt a20e3b8004 Increase required glibc version for -static-pie tests
mold 1.1.1 generates `-static-pie` code that works with glibc 2.35 but
segfaults with glibc 2.34 or older.

Signed-off-by: Christoph Erhardt <[email protected]>
2022-03-08 10:13:49 +01:00
Rui Ueyama c1af9c97e7 Bump mold version to 1.1.1 2022-03-07 19:38:14 +09:00
Rui Ueyama 3999aa8b18 [ELF] Fix -static-pie
Previously, mold did not work with the -static-pie compiler flag.
In order to support static PIE, we need the following:

1. Create a .dynamic section even if it is not a dynamic executable, and
2. do not define __rel_iplt_start/end symbols.

The second part is required to workaround a glibc issue.

Even with these changes, mold-generated executable doesn't work with
old glibc versions. But I think it's OK because -static-pie is relatively
new option and you need a newer toolchain anyway.
2022-03-06 17:14:13 +09:00
Rui Ueyama b4d9db9db8 [ELF] Do not emit DT_RELCOUNT
It looks like the glibc loader does not use this field in the dynamic
section. GNU ld, gold and LLVM lld don't create this. So I think we
can just follow suit.
2022-03-06 14:43:24 +09:00
Rui Ueyama 95c7871c6e Fix documentation 2022-03-06 14:23:22 +09:00
Rui Ueyama 3f7bffe93c Add a comment 2022-03-06 13:48:31 +09:00
Rui Ueyama ec473c74d7 Refactor 2022-03-06 13:24:01 +09:00
Rui Ueyama 9e11b40a99 [ELF] Do not allocate a byte for an empty class
In C++, the size of an empty class is 1 rather than 0 because every
object is guaranteed to have a unique address. But if we do not need
the unique address guarantee, we can add `[[no_unique_address]]` to
a class member to save 1 byte. This is a new C++20 feature.
2022-03-06 12:20:31 +09:00
Rui Ueyama a4fd7e3819 [ELF] Remove redundant foo/.. from library paths 2022-03-05 21:28:43 +09:00
Rui Ueyama aae3dc3c1e Refactor 2022-03-05 20:27:10 +09:00
Rui Ueyama ba7967152d Refactor 2022-03-05 20:14:43 +09:00
Rui Ueyama d6dae3be6d [ELF] Report errors more strictly for unrepresentable relocations 2022-03-05 14:59:31 +09:00
Rui Ueyama 83aaa63a49 [ELF][i386] Make GOT-relative relocs relative to .got instead of .got.plt
We used to compute offsets from .got.plt for GOT-relative relocations,
but according to the i386 psABI, they should be relative to .got.
2022-03-05 12:13:04 +09:00
Rui Ueyama b0d91b9967 [ELF] Add -warn-shared-textrel
Fixes https://github.com/rui314/mold/issues/377
2022-03-05 10:59:04 +09:00
Rui Ueyama 4ea052591a Merge pull request #378 from gruenich/main
input-files: Remove unused variable size
2022-03-05 09:49:57 +09:00
Christoph Grüninger 2f03e46bb3 input-files: Remove unused variable size
Removed code has no effect.
Left-over from code removal in 4dae896726.

Signed-off-by: Christoph Grüninger <[email protected]>
2022-03-05 00:30:30 +01:00
Rui Ueyama 6205a1edc3 Update the man page 2022-03-04 14:54:10 +09:00
Rui Ueyama 4dea134949 [ELF] Do not compute the contents of .eh_frame twice 2022-03-03 20:07:45 +09:00
Rui Ueyama eb79859ea2 [ELF] Always set _GLOBAL_OFFSET_TABLE_ to the beginning of .got
Previously, we set the address of `_GLOBAL_OFFSET_TABLE_` to `.got.plt`
on i386 and x86-64 and to `.got` on other targets. But it looks like
this special treament of x86 isn't necessary. The x86-64 psABI said
that the symbol can even be in the middle of `.got` (*1). If `.got.plt`
is missing, GNU linker set it to `.got`.

This commit unconditionally set the symbol value to `.got`.

(*1) x86-64 psABI 1.0 p.77: "The symbol _GLOBAL_OFFSET_TABLE_ may
reside in the middle of the .got section, allowing both negative and
non-negative offsets into the array of addresses."
2022-03-03 12:10:26 +09:00
Rui Ueyama 8714b78d48 [ELF] Reduce memory usage a bit 2022-03-03 10:28:27 +09:00
Rui Ueyama 86b142e555 [ELF] Do not create DT_INIT/DT_FINI if _init/_fini are in a .so
Fixes https://github.com/rui314/mold/issues/372
2022-03-02 21:12:41 +09:00
Rui Ueyama e5549c73f0 Remove an unused class 2022-03-02 17:37:38 +09:00
Rui Ueyama 4dae896726 [ELF] Reduce the size of InputSection from 88 bytes to 72 bytes 2022-03-02 17:27:31 +09:00
Rui Ueyama 83e05dae28 [ELF] Reduce the size of FdeRecord from 24 bytes to 16 bytes
It saves 8 bytes for each input function.
2022-03-02 16:25:17 +09:00
Rui Ueyama 99a0aaf133 [ELF] Add a test for -init 2022-03-02 10:35:32 +09:00
Rui Ueyama 7068c0cd0f [ELF] Reduce the size of InputSection from 120 bytes to 88 bytes 2022-03-01 17:49:17 +09:00
Rui Ueyama f49e4024e9 Rename a variable 2022-03-01 17:08:14 +09:00
Rui Ueyama 567a78dbd5 [ELF] Do not directly read st_shndx
If st_shndx is 0xffff, the actual section index value is in a
SHT_SYMTAB_SHNDX section.
2022-03-01 14:47:51 +09:00
Rui Ueyama f2d27d8d24 [ELF] Shrink the size of Symbol from 56 bytes to 48 bytes
This is a second attempt to reduce the size of the Symbol class.
2022-03-01 12:03:35 +09:00
Rui Ueyama dc9573989c Refactor 2022-03-01 11:37:49 +09:00
Rui Ueyama e469b04f0d Revert "[ELF] Shrink the size of Symbol from 56 bytes to 48 bytes"
This reverts commit 32e158d340
because it broke some tests when mold is built with itself.
2022-03-01 07:49:57 +09:00
Rui Ueyama 32e158d340 [ELF] Shrink the size of Symbol from 56 bytes to 48 bytes 2022-02-28 20:53:40 +09:00
Rui Ueyama 18b6f96756 Refactor 2022-02-28 19:42:01 +09:00
Rui Ueyama 2b7dbb01c4 Rename a file 2022-02-28 16:20:37 +09:00
Rui Ueyama c1c9bdf363 Optimize BigEndian class
Despite its comment, gcc sometimes failed to optimize the loop into
single `bswap` instruction. So it looks like we should explicitly use
`__builtin_bswap` functions.
2022-02-28 16:17:11 +09:00
Rui Ueyama d4bbf31db2 [ELF] Add the --noinhibit-exec option
Fixes https://github.com/rui314/mold/issues/370
2022-02-28 13:03:35 +09:00
Rui Ueyama 9b5d404d1e Simplify 2022-02-27 20:59:59 +09:00
Rui Ueyama 4caadefac6 Refactor 2022-02-27 15:21:06 +09:00
Rui Ueyama 8f21cc386e [ELF] Merge --shuffle-sections-seed into --shuffle-sections 2022-02-27 14:25:10 +09:00
Rui Ueyama f7de9571f8 Refactor 2022-02-27 14:24:14 +09:00
Rui Ueyama e413433752 [ELF][LTO] Add lld-compatible LTO-related command line options
Fixes https://github.com/rui314/mold/issues/367
2022-02-27 09:28:51 +09:00
Rui Ueyama e67f460bfd [ELF][LTO] Fix "too many open files" issue for GCC
Fixes https://github.com/rui314/mold/issues/362
2022-02-26 16:34:51 +09:00
Rui Ueyama e281ed88bb Fix minor memory leak 2022-02-26 16:24:25 +09:00
Rui Ueyama 41986279de [ELF] Do not create multiple .init_array output sections
Usually, init_array is readable and writable, but it looks like rustc
with `-C lto=fat` create a read-only .init_array. mold used to create
two output .init_array sections for read/write and read-only
init_array input sections. That caused one of them are not executed
on startup.

Now, mold create read/write .init_array output section even if an
input .init_array section is read-only.

Fixes https://github.com/rui314/mold/issues/363
2022-02-25 22:54:55 +09:00
Rui Ueyama 480efdedf0 [ELF] Fix IBT-enabled PLT
We used to emit the following sequence for each PLT entry.

    0xf3, 0x0f, 0x1e, 0xfa, // endbr64
    0xff, 0x25, 0, 0, 0, 0, // jmp *foo@GOTPLT
    0xe8, 0, 0, 0, 0,       // call PLT[0]

In the above instruction sequence, `jmp` was expected to jump to the
following `call` instruction if the PLT entry is executed for the
first time. However, it wouldn't work because we needed another
`endbr64` before `call`.

This problem should be fixed in this commit. Now, the PLT header is
32 bytes long and each entry is 16 bytes.
2022-02-25 12:43:43 +09:00
Rui Ueyama 99e3f959fc [ELF] Make IBTPLT header a bit shorter 2022-02-24 19:56:41 +09:00
Rui Ueyama 4ec0bbf048 [ELF] Shrink the size of IBTPLT entry from 32 bytes to 16 bytes
IBT-enabled PLT section is sparse as 2/3 of the section contents are
NOP instructions. In this patch, I implemented alternative instruction
sequences for IBTPLT, so that each IBTPLT entry occupies only 16 bytes
instead of 32 bytes.

In return, our new IBTPLT section needs a 64 bytes header instead of a
16 bytes one, but it's overall a good deal because we usually have many
PLT entries.
2022-02-24 17:55:17 +09:00
Rui Ueyama f4c0e321db [ELF] Do not use BND JMP
BND JMP instruction is a part of of Intel MPX instructions.
Intel MPX instructions are deprecated by Intel now.
2022-02-24 14:26:40 +09:00
Rui Ueyama 31a5cdf86f [ELF] Verify a relocation after TLSGD or TLSLD 2022-02-24 12:32:02 +09:00
Rui Ueyama a44de89991 Fix CI
`-m32` doesn't work on CI for some reason, so I'll remove the test
file for now.
2022-02-24 11:32:00 +09:00
Rui Ueyama 30683645c2 [ELF] Do not corrupt compressed debug sections on i386
Previously, if an input debug section is compressed, mold produced
corrupted output debug section on i386.

Fixes https://github.com/rui314/mold/issues/361
2022-02-24 11:05:54 +09:00
Rui Ueyama ac3ae60184 Format 2022-02-24 11:05:54 +09:00
Rui Ueyama 9f34830882 [ELF] Relax TLSLD followed by GOTPCREL, GOTPCRELX or REX_GOTPCRELX 2022-02-23 23:53:57 +09:00
Rui Ueyama 4aa4bfa4a6 [ELF] Fix TLSGD/TLSLD relaxation
When we relax R_X86_64_TLSGD or R_X86_64_TLSGD, we rewrite two
instructions (the one referred by TLSGD/TLSLD and the following one
referred by the following relocation). The second instruction is
usually 5 bytes, but if it can be longer than that, and if that's the
case, we need to emit a nop to fill the gap at the end of the longer
instruction.

We didn't do that. As a result, the remaining garbage of the second
instruction is executed and caused an unpredictable result (illegal
instruction or segv).

This patch fixes the issue.

Fixes https://github.com/rui314/mold/issues/360
2022-02-23 16:16:53 +09:00
Rui Ueyama fb6967c0cf Update a document 2022-02-22 19:26:28 +09:00
Rui Ueyama 385c1c494d Update a document 2022-02-22 18:57:15 +09:00
Rui Ueyama 4667be6134 [ELF] Change the size of ibtplt from 24 bytes to 32 bytes 2022-02-22 16:14:27 +09:00
Rui Ueyama 3f9868238b [ELF] Add the --shuffle-sections-seed=NUMBER option 2022-02-22 15:41:51 +09:00
Rui Ueyama 3e8c519d4e [ELF] Add the --reverse-sections option
This option reverse input sections before assigning offsets to them.
This is useful to detect an unintended dependency between static
initializers in different translation units. C++ only guarantees that
static initializers are invoked from top to bottom in a single
translation unit, and it doesn't guaratee anything about the order of
initialization between translation units.

By (partially) reversing the contents of .init_array using
--reverse-sections, you can run your program with a completely
reversed initialization order.
2022-02-22 15:41:51 +09:00
Rui Ueyama aa27d674c1 Merge pull request #356 from sicherha/aarch64-skip-reloc-rodata-test
Skip reloc-rodata test on aarch64
2022-02-22 15:00:23 +09:00
Christoph Erhardt 3cbc57f9af Skip reloc-rodata test on aarch64
The test expects an error when an object compiled with `-fno-PIC` is
linked with `-pie`, but that doesn't happen on aarch64.

Signed-off-by: Christoph Erhardt <[email protected]>
2022-02-22 06:41:01 +01:00
Rui Ueyama a1e6d8e8df Add comments 2022-02-22 13:18:09 +09:00
Rui Ueyama a054bcd4ff [ELF] Add the --dependency-file=FILE option 2022-02-22 13:18:04 +09:00
Rui Ueyama e47c67727c Update README 2022-02-22 11:50:54 +09:00
Rui Ueyama 16bdf4009a Pass -O2 to the compiler 2022-02-22 11:49:17 +09:00
Rui Ueyama c173f9c0ab Simplify 2022-02-21 18:26:51 +09:00
Rui Ueyama 89612b7096 Bump mold version to 1.1 2022-02-20 16:40:17 +09:00
Rui Ueyama d258140d54 Inline a default constructor 2022-02-20 16:04:00 +09:00
Rui Ueyama 6ce142d73a Remove redundant default destructors 2022-02-20 16:02:05 +09:00
Rui Ueyama 3a15c54f10 [ELF][LTO] Check for the return value of all_symbols_read_hook 2022-02-19 21:57:36 +09:00
Rui Ueyama 4a6e71096c Fix Gentoo build script as build-static.sh is gone 2022-02-19 21:57:36 +09:00
Rui Ueyama ec9ac181f8 [ELF] Improve comments 2022-02-19 18:24:21 +09:00
Rui Ueyama ccd475e41d [Mach-O] Show a notice on startup 2022-02-19 16:49:20 +09:00
Rui Ueyama 7dc6ce72dd Refactor 2022-02-19 12:13:23 +09:00
Rui Ueyama 064be343f5 Remove build-static.sh as the statically-linked mold can't do LTO
This commit removes build-static.sh because statically-linked mold
executable can't generally dlopen a shared library and therefore can't
load the linker LTO plugin.

Now, build-dynamic.sh is renamed dist.sh and recommended for general
use.
2022-02-19 12:00:51 +09:00
Rui Ueyama c8853223a3 Add a script to create a tar file for binary distribution
I think we don't need to create a tar file for binary distribution
for each Linux distro. Instead, we can create mold executable that
works on most Linux machines.

The new script, build-dynamic.sh, creates a mold executable with
libmimalloc, libtbb, libstdc++ and libcrypto begin linked statically.
I don't have a concern as to the availability of other libraries
(libc, libm, libz and librt) because they essentially exists on any
system.
2022-02-19 11:26:18 +09:00
Rui Ueyama 0b7d210f99 Improve build scripts 2022-02-18 22:35:59 +09:00
Rui Ueyama b22e6f80fc Add scripts to create binary packages
https://github.com/rui314/mold/issues/351
2022-02-18 22:11:34 +09:00
Rui Ueyama 15fa05eff6 [ELF][LTO] Clear symbols after LTO
This commit ensure that all symbol resolution results are cleared
after LTO, so that the following second symbol resolution will not
be affected by the previous results.
2022-02-18 22:05:14 +09:00
Rui Ueyama 61e0311889 Refactor 2022-02-18 20:18:07 +09:00
Rui Ueyama 825b918146 Do not use dlopen only when built with ./build-static.sh
This commit fixes a regression in f4a9b05114
that mold crashed when it tried to dlopen a linker plugin shared library.
2022-02-18 15:18:56 +09:00
Rui Ueyama 19587d43ee Rename a variable 2022-02-18 12:53:34 +09:00
Rui Ueyama f4a9b05114 Do not call dloepn() if built with ./build-static.sh
It looks like setting __TBB_DYNAMIC_LOAD_ENABLED to 0 is not enough
to make TBB not to call dlopen(). We need to unset __TBB_WEAK_SYMBOLS_PRESENT
as well.

Fixes https://github.com/rui314/mold/issues/348
2022-02-18 12:17:24 +09:00
Rui Ueyama 7735cf5b95 Style change 2022-02-17 20:29:28 +09:00
Rui Ueyama fcb28161b1 Merge pull request #349 from dmantipov/use-explicit-mimalloc-new-delete-overrides-if-system-mimalloc
Use explicit mimalloc new/delete overrides if SYSTEM_MIMALLOC
2022-02-17 20:26:27 +09:00
Rui Ueyama b57da5413c [ELF][LTO] Restart mold if a LTO plugin does not support get_symbols v3 API 2022-02-17 19:14:05 +09:00
Dmitry Antipov 630b262d2b Use explicit mimalloc new/delete overrides if SYSTEM_MIMALLOC
When building with SYSTEM_MIMALLOC=1, linking with (assuming
shared) '-lmimalloc' is not enough to override C++ new/delete
with mimalloc versions, and 'mimalloc-new-delete.h' should be
included from one (and the only) translation unit as well.

Signed-off-by: Dmitry Antipov <[email protected]>
2022-02-17 10:44:58 +03:00
Rui Ueyama 8f0acbf413 [ELF][LTO] Move LTO to the symbol resolution pass
ELF object files returned by do_lto() may contain unforeseen undefined
symbols, so we can't call that function after the symbol resolution pass
because it can cause undefined symbol errors.
2022-02-17 16:14:11 +09:00
Rui Ueyama a3f2a5c7ec Format 2022-02-17 13:54:15 +09:00
Rui Ueyama b5db63f4bb [ELF] Allow relative relocs against absolute symbols
In the previous commit (c325cc039a),
I argued that PC-relative relocations are not representable if they
refer absolute symbols, and I made a change so that such relocations
are handled as errors.

Even though what I did is technically correct, that results in a failure
of an important use case of the weak undefined symbol. Here is why.

If you have an weak undefined symbol `foo`, you would use it as follows:

  if (foo)
    foo();

If `foo` is defined (i.e. has an address other than 0), `foo` is called.

If `foo` is undefined (i.e. has the address 0), the subsequent CALL
instruction will have an offset from the CALL instruction to address 0.
That displacement is computed at link-time. If the output is position-
independent, the call instruction may not have a correct displacement
from address 0 to the instruction at runtime due to base relocation.

However, that's not a problem in practice, because the function call
is guarded by `if (foo)`, and that will always evaluated to false
if `foo` is undefined. Therefore, the faulty `CALL` instruction will
never be executed.

So, that means we need to relocate PC-relative relocations against
absolute symbols even if doing so results in an incorrect result.
This patch implement that.
2022-02-17 12:07:48 +09:00
Rui Ueyama c325cc039a [ELF] Report an error for an unrepresentable reloc against abs symbol
PC-relative relocations against absolute symbols are not representable
in position-independent code. In order to support such relocations,
someone has to compute `S + A - P` or subtract `B` as a base relocation,
but such dynamic relocations don't exist.

This is contrary to non-PC-relative relocations against non-absolute
symbols. In this case, we can simply use the base relocation (e.g.
R_X86_64_RELATIVE).

https://github.com/rui314/mold/issues/348
2022-02-17 11:21:52 +09:00
Rui Ueyama 0b7edc07f4 Format 2022-02-17 10:30:20 +09:00
Rui Ueyama da48efe63b Update the man page 2022-02-16 19:36:26 +09:00
Rui Ueyama 3f1b071ae5 [ELF] Remove --warn-shared-textrel
It looks like the option is supported only by gold, and it doesn't
make much sense to me to have this option along with more generic
--warn-textrel. So I want to remove this before the next release.
2022-02-16 19:36:26 +09:00
Rui Ueyama 444cb7a566 [ELF] Improve the man page 2022-02-16 18:54:08 +09:00
Rui Ueyama 889f9f3a36 Simplify 2022-02-16 16:53:23 +09:00
Rui Ueyama e4c4ab053e [ELF] Remove --shuffle-sections=N
This patch removes the --shuffle-sections option that takes an
argument as I'm still thinking about a better name for the option.

You can still use `--shuffle-sections` that doesn't take an argument.
2022-02-16 15:55:47 +09:00
Rui Ueyama 10ff2d705c Fix CI 2022-02-16 15:26:39 +09:00
Rui Ueyama 31f7427859 Rename a test file 2022-02-16 15:04:09 +09:00
Rui Ueyama c338540885 [ELF] Handle relocations with r_sym == 0 correctly
If a relocation's r_sym value is 0 (i.e. it refers the undefined symbol
at the beginning of the symbol table), it has to handled as if S were 0.
We used to handle as if S were -1.

In addition to that, even if a relocation needs a dynamic base relocation,
it doesn't mean its expression is always S+A. For example, calling an
absolute address needs a dynamic relocation but its expression is S+A-P.

Fixes https://github.com/rui314/mold/issues/348
2022-02-16 13:18:22 +09:00
Rui Ueyama d908d4c61c [ELF] Handle global symbols in mergeable sections correctly
Prior to this patch, mold computeed a wrong address for a global
symbol in a mergeable section. believe it was a regression in
60d0900496.

Fixes https://github.com/rui314/mold/issues/347
2022-02-16 12:05:40 +09:00
Rui Ueyama b94dd6dbeb Revert "[ELF] add method to check whether an input file is shared object"
This reverts commit ddcb7b4197. `is_dso`
is used by hot functions such as `Symbol::get_addr()`, so we want to
eliminate the cost of virtual function dispatch.
2022-02-16 09:51:07 +09:00
Rui Ueyama a7333bdb4e Merge pull request #343 from dmantipov/fix-annoying-unused-variable-warnings
[ELF] Fix -Wunused-variable warnings
2022-02-14 21:27:57 +09:00
Dmitry Antipov 881b55d691 [ELF] Fix -Wunused-variable warning
Fix the following -Wunused-variable warning as reported by gcc:

elf/input-sections.cc:116:8: warning: unused variable ‘is_code’
[-Wunused-variable]
  116 |   bool is_code = (shdr().sh_flags & SHF_EXECINSTR);

Signed-off-by: Dmitry Antipov <[email protected]>
2022-02-14 15:22:00 +03:00
Rui Ueyama 28236b1b34 [ELF][LTO] Report an error if an IR file wasn't claimed
And remove an unused variable. Found by Dmitry Antipov.
2022-02-14 20:59:32 +09:00
Rui Ueyama 7e62ce4bd8 Improve an error message 2022-02-14 13:59:01 +09:00
Rui Ueyama b0d75f8957 [ELF] Document --start-lib and --end-lib
Also extends the description of --push-state and --pop-state.

Fixes https://github.com/rui314/mold/issues/339
2022-02-13 19:57:06 +09:00
Rui Ueyama 68a35bfa03 Fix CI 2022-02-13 16:52:54 +09:00
Rui Ueyama 70ec56f8bb [ELF][LTO] Export symbols from DSOs correctly
With this change, mold can now build Clang with LTO and all Clang tests pass.
2022-02-13 15:34:37 +09:00
Rui Ueyama e18eaac3eb Update README 2022-02-13 15:18:08 +09:00
Rui Ueyama 5f17da80d0 [ELF][LTO] Mark IR objects as alive 2022-02-13 12:57:28 +09:00
Rui Ueyama 1663bcf932 Rename test files 2022-02-13 12:22:18 +09:00
Rui Ueyama 16a3c9491f [ELF][LTO] Fix "too many open files" issue
read_lto_object is called on each archive member, so if an archive file
contains lots of members, it can exhaust the pool of file descriptors.
This patch fixes the issue by opening an archive only once.
2022-02-13 12:22:18 +09:00
Rui Ueyama bab74c0c7e Merge pull request #342 from sylvestre/wording
Readme: Improve the wording
2022-02-13 11:41:57 +09:00
Sylvestre Ledru 5c5d50929e Improve the wording
Patch by Josh Triplett
https://salsa.debian.org/pkg-llvm-team/mold/-/merge_requests/8/diffs

Signed-off-by: Sylvestre Ledru <[email protected]>
2022-02-12 22:53:19 +01:00
Rui Ueyama ce744aeca4 Refactor 2022-02-12 20:34:49 +09:00
Rui Ueyama 0222dc6f39 [ELF] Drop SHF_GROUP flag from section header
SHF_GROUP is sometimes set to comdat group members. Since we process
comdat groups and uniquify them, that flag doesn't make sense in the
output file.
2022-02-12 20:17:57 +09:00
Rui Ueyama 46f954d23d [ELF][LTO] Returns a more precise value from get_symbols callback 2022-02-12 20:06:44 +09:00
Rui Ueyama 42b3038463 [ELF][LTO] Factor out LTO type definitions to lto.h 2022-02-12 17:50:36 +09:00
Rui Ueyama c9612d3120 Refactor 2022-02-12 17:36:38 +09:00
Rui Ueyama 60d0900496 [ELF][LTO] Fix "concurrent hash table full" error
Since compiled IR objects may contain mergeable string sections, we
don't know the estimated number of items in output mergeable sections.
Previously, we created the concurrent hash tables for output mergeable
sections before compiling IR objects, so there was a chance to see
the "concurrent hash table full" error.

This commit moves the code to add section pieces to output mergeable
sections after `do_lto`.
2022-02-12 16:53:36 +09:00
Rui Ueyama c1963ce2ac [ELF][LTO] Recognize IR files generated by GCC 11 2022-02-12 16:28:38 +09:00
Rui Ueyama 1dcd20b401 Fix CI 2022-02-12 15:39:28 +09:00
Rui Ueyama 7e91897154 [ELF] Add the --shuffle-sections option
If the --shuffle-sections is given, mold now randomize the output by
shuffling input sections randomly. This feature is compatible with lld's
--shuffle-sections=SEED option introduced in
https://reviews.llvm.org/D74791.

This feature is useful when you want to equalize the conditions of
benchmarks. That is, some particular memory layout can produce a very
good benchmark number due to hardware-level cache hit rate or something
like that. Therefore, even if you get a good benchmark number after
changing code, there's a chance that that's caused by the layout change
and not by the new code itself. With --shuffle-sections, you can isolate
that.

The other use case I can think of is to enhance security. If you build
your program as a position-independent executable, the kernel
automatically enables ASLR (Address Space Layout Randomization), but ASLR
only shift the entire program image in memory by some random offset;
Relative offsets between sections remain the same. If you compile programs
from source, by using --shuffle-sections, you can make the offsets
unpredictable to attackers.
2022-02-12 15:32:37 +09:00
Rui Ueyama 61eb265cf4 [ELF][LTO] Report an error if -plugin was not given 2022-02-12 10:17:21 +09:00
Rui Ueyama 46995bcfc3 [ELF] Support LTO plugin API
The LTO plugin API support is still in progress, but with this change,
mold can link itself with `-flto` with both GCC and Clang.

Since mold now supports LTO natively, I removed the fallback mechanism
to ld.bfd or ld.lld that I implemented in
a5029d19a8.

Fixes https://github.com/rui314/mold/issues/181
2022-02-11 21:09:28 +09:00
Rui Ueyama dd8002f092 [ELF] Detect GCC LTO object files early 2022-02-11 20:57:19 +09:00
Rui Ueyama 6ee5aea1bf Add a comment about how to build mold with AddressSanitizer 2022-02-11 18:16:20 +09:00
Rui Ueyama 81cf1171a9 Simplify 2022-02-10 18:23:59 +09:00
Rui Ueyama 955c6d1fe4 Fix ODR violation 2022-02-10 15:26:26 +09:00
Rui Ueyama 7546b44111 [ELF] Add --print-dependencies=full
This is an experimental feature. We haven't decided as to whether we'll
include this flag into the next release.

This is an example output of the flag when linking mold with mold:
https://gist.github.com/rui314/3f5d226814bb1188c535f1f86706cea5
2022-02-09 13:52:37 +09:00
Rui Ueyama d4679063fc Make virtual destructor public
I believe if you make the destructor a protected function, you can't
destruct it through a pointer to the base type. All destruction has
to be called through a pointer to a derived type.

There's no difference at the moment, but I think it is more conventional
to make a virtual destructor public.
2022-02-09 11:33:19 +09:00
Rui Ueyama e8c72767fa Merge pull request #334 from dmantipov/macho-add-compiler-suggested-virtual-destructor
[MACHO] add compiler-suggested virtual destructor
2022-02-09 11:32:19 +09:00
Dmitry Antipov 440e4c4ade [MACHO] add compiler-suggested virtual destructor
Add 'mold::macho::InputFile()::~InputFile()' as suggested by
clang++-13's '-Wdelete-non-abstract-non-virtual-dtor':

/usr/include/c++/11/bits/unique_ptr.h:85:2: warning: delete
called on non-final 'mold::macho::ObjectFile<mold::macho::ARM64>'
that has virtual functions but non-virtual destructor
[-Wdelete-non-abstract-non-virtual-dtor]

Signed-off-by: Dmitry Antipov [email protected]
2022-02-08 20:14:30 +03:00
Rui Ueyama 70afbd1ca7 [ELF] Discard local symbols if EM_RISCV
RISC-V object files contain a large number of local symbols. This is
because all branches are explicitly represented by relocations and
symbols even their branch targets are of the same input section.
RISC-V psABI requires such relocations and symbols to allow sections
to be shrinked by linker relaxation.

GNU ld by default discard local symbols if RISC-V. We do the same
in this patch.
2022-02-08 23:23:20 +09:00
Rui Ueyama 5e9238e3f0 Merge pull request #333 from dmantipov/macho-add-method-to-check-whether-an-input-file-is-shared-object
[MACHO] add method to check whether an input file is shared object
2022-02-08 21:54:11 +09:00
Dmitry Antipov 7f6bfc1bdb [MACHO] add method to check whether an input file is shared object
Prefer pure virtual 'mold::macho::InputFile::is_dylib()' (actually
implemented in 'mold::macho::ObjectFile' and 'mold::macho::DylibFile')
over the field of the same name, adjust related code. This is Mach-O
counterpart of 249c331117.

Signed-off-by: Dmitry Antipov [email protected]
2022-02-08 15:40:43 +03:00
Rui Ueyama ebc2bfafdd [ELF] Fix ICF crash bug
`-icf=all` couldn't handle very small programs that has no sections
to process in the main loop. This commit fixes that crash bug.

Fixes https://github.com/rui314/mold/issues/332
2022-02-08 16:34:25 +09:00
Rui Ueyama 249c331117 Refactor 2022-02-08 16:30:41 +09:00
Rui Ueyama 818c59e4dd Merge pull request #328 from dmantipov/elf-add-method-to-check-whether-an-input-file-is-shared-object
[ELF] add method to check whether an input file is shared object
2022-02-08 16:28:06 +09:00
Dmitry Antipov ddcb7b4197 [ELF] add method to check whether an input file is shared object
Prefer pure virtual 'mold::elf::InputFile::is_dso()' (actually
implemented in 'mold::elf::ObjectFile' and 'mold::elf::SharedFile')
over the field of the same name, adjust related code.

Signed-off-by: Dmitry Antipov [email protected]
2022-02-08 10:19:56 +03:00
Rui Ueyama 4a0eef3b14 [ELF] Do not inline .copyrel.rel.ro if RELRO is disabled 2022-02-08 10:33:37 +09:00
Rui Ueyama 5850f237fe [ELF] Do not set .copyrel.rel.ro to NOBITS if it's small 2022-02-08 10:09:57 +09:00
Rui Ueyama 0f8bf23bcf [ELF] Rename .dynbss -> .copyrel
Currently, the sections we create for copy relocations are named .dynbss
and .dynbss.rel.ro. Section names shouldn't be significant in ELF
executables, so we should be able to name them as we want.

However, in practice, valgrind treat a section with the name .dynbss
in a special way and crashes if an executable contains both .bss and
.dynbss due to the following assertion failure:

  $ valgrind ./prog
  ==1960252== Memcheck, a memory error detector
  ==1960252== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
  ==1960252== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
  ==1960252== Command: ./prog
  ==1960252==

  valgrind: m_debuginfo/readelf.c:2271 (vgModuleLocal_read_elf_debug_info): Assertion 'di->bss_svma + di->bss_size == svma' failed.
  Segmentation fault (core dumped)

This commit is a workaround for the valgrind issue. We simply rename
dynbss and .dynbss.rel.ro to .copyrel and .copyrel.rel.ro, respectively.

Fixes https://github.com/rui314/mold/issues/159
2022-02-08 10:09:54 +09:00
Rui Ueyama a2fa0934d0 Refactor 2022-02-08 07:06:44 +09:00
Rui Ueyama 214c35e05d Refactor 2022-02-08 07:02:30 +09:00
Rui Ueyama e5f4b967ed Do not link against libxxhash.so at all
Ensure that all xxhash functions are inlined. Since it eliminates
external dependencies, we no longer have to link against libxxhash.a
or libxxhash.so at all.

`SYSTEM_XXHASH` Makefile variable has been removed because it is
no longer relevant.
2022-02-07 20:06:59 +09:00
Rui Ueyama 73159e241d [ELF] Add .got.plt to PT_GNU_RELRO if -z now
If external symbols are resolved eagerly on process startup, .got.plt
can be read-only and therefore can be in the PT_GNU_RELRO segment.
2022-02-07 17:12:53 +09:00
Rui Ueyama a1287c26b9 [ELF] Add --print-dependencies
This is a mold-only experimental feature. If the flag is given,
mold prints out dependencies between input files as tab-separated
tuples of (`source-file`, `dest-file`, `symbol`). Each line of the
output means `source-file` depends on `dest-file` to use `symbol`.

With the dependency information, you can analyze for example why
some archive file member is included in a linker's output.
You can also for example know what symbols have to be removed
to eliminate the dependency to some shared library file.

I'm not sure if I'll include this flag in the next release or
document this feature, but it looks promising so far. If you like
or dislike this feature, please leave a comment on GitHub.

This is an example of the output when linking mold with mold:
https://gist.github.com/rui314/e1d70bbdebfabb881be7167314b58f48
2022-02-07 11:53:38 +09:00
Rui Ueyama 36fe7511f1 Do not link against librt if not necessary 2022-02-07 11:32:23 +09:00
Rui Ueyama 4551fffe69 Do not link against libxxhash.so if not necessary
We use only `XXH3_64bits` from libxxhash, and it looks like the function
is an inline function, so there's actually no runtime dependency against
libxxhash.so.
2022-02-07 11:29:02 +09:00
Rui Ueyama bef545bdb9 [ELF] Improve a hint for -b binary 2022-02-07 09:53:16 +09:00
Rui Ueyama ab2db49fbe Refactor 2022-02-07 08:37:35 +09:00
Rui Ueyama e65c5d2a1c [ELF] Handle ABI incompatibility between -fgnu-unique and -fno-gnu-unique
GCC creates symbols in comdat groups as STB_GNU_UNIQUE instead of STB_WEAK
if it was configured to do so at build time or the -fgnu-unique option was
given. If mold is given two object files with and without STB_GNU_UNIQUE,
it could end up selecting a sybmol that is in a de-duplicated comdat group.

This is arguably just an ABI incompatibility. Two comdat groups must
contain the same contents if their identifiers are the same. But we
can't handle it as an error because it is not uncommon to link object
files compiled using Clang (or GCC without -fgnu-unique) to static
libraries built with GCC that produces STB_GNU_UNIQUE symbols.

This patch gives the same priority to STB_GNU_UNIQUE as STB_WEAK so that
mold won't select symbols in discarded comdat groups.

Frankly, the situation around STB_GNU_UNIQUE is a mess. That GNU extension
shouldn't have been added to the GNU toolchain in the first place.
It looks like GCC shipped with Linux distros are nowadays do not produce
STB_GNU_UNIQUE symbols by default, but we still need to handle them.

Fixes https://github.com/rui314/mold/issues/324
2022-02-07 07:53:58 +09:00
Rui Ueyama 27c50e8158 [ELF] Report an error for an unresolved hidden undef correctly
Previously, if a protected/hidden undef symbol is resolved to a DSO
symbol,  mold didn't report a symbol undefined error.

Fixes https://github.com/rui314/mold/issues/329
2022-02-06 13:49:17 +09:00
Rui Ueyama 07a480c43c [ELF] Make .relr.dyn construction a bit more efficient
Relocations are naturally sorted, so we don't have to sort them again.
This change makes Chrome link time ~1% faster when --pack-dyn-relocs=relr
is specified.
2022-02-05 16:39:51 +09:00
Rui Ueyama 6ffcae4286 [ELF] Add --warn-textrel 2022-02-05 13:26:38 +09:00
Rui Ueyama 03e0cef726 [ELF] Add --warn-shared-textrel 2022-02-05 12:15:30 +09:00
Rui Ueyama a4d9bc7550 Fix CI 2022-02-05 12:15:17 +09:00
Rui Ueyama f24b997501 [ELF} Add --warn-once 2022-02-05 11:39:59 +09:00
Rui Ueyama f72999a1df Add an assertion 2022-02-05 10:49:05 +09:00
Rui Ueyama b02c8cb8f5 Add Coding Guidelines 2022-02-05 10:28:08 +09:00
Rui Ueyama 579fafc04b Refactor 2022-02-05 09:31:43 +09:00
Rui Ueyama 77716836be Refactor 2022-02-05 08:58:20 +09:00
Rui Ueyama 017082f22f Refactor 2022-02-05 00:22:52 +09:00
Rui Ueyama 1abc1f9275 Refactor 2022-02-04 22:39:03 +09:00
Rui Ueyama 12df85ad8c [ELF] Add time probes
For the record, here is the log when I was trying to cross-link
clang-14 (~4.6 GiB) for RISC-V on a 64-core Threadripper machine.

     User   System     Real  Name
   83.719   29.444    3.828  all
    9.512   18.175    0.887    read_input_files
   21.853    0.329    0.747    register_section_pieces
   52.363   10.939    2.194    total
   30.359    1.384    1.044      before_copy
    0.000    0.000    0.000        apply_exclude_libs
    0.638    0.000    0.021        resolve_symbols
    0.310    0.032    0.011        eliminate_comdats
    0.001    0.001    0.000        convert_common_symbols
    0.000    0.000    0.000        apply_version_script
    0.076    0.044    0.004        compute_import_export
    2.303    0.000    0.077        compute_merged_section_sizes
    0.962    0.000    0.034          MergedSection assign_offsets
    0.165    0.016    0.008        bin_sections
    0.022    0.012    0.002        claim_unresolved_symbols
    0.134    0.003    0.004        check_duplicate_symbols
    0.001    0.001    0.002        sort_init_fini
    0.070    0.000    0.003        compute_section_sizes
    4.316    0.000    0.143        scan_rels
    0.082    0.000    0.005        DynsymSection::finalize
    0.000    0.000    0.000        fill_verdef
    0.001    0.000    0.001        fill_verneed
    7.275    0.000    0.232        compute_symtab
    0.001    0.000    0.000        eh_frame
    0.000    0.000    0.000        set_osec_offsets
   14.951    1.276    0.529        riscv_resize_sections
    3.921    0.009    0.125          align_contents
    0.076    0.028    0.004          compute_section_sizes
    0.000    0.000    0.000          set_osec_offsets
    4.279    0.000    0.145          relax_call
    0.096    0.000    0.004          compute_section_sizes
    0.000    0.000    0.000          set_osec_offsets
    0.000    0.000    0.000      open_file
   22.004    9.555    1.150      copy
   19.026    9.315    0.894        copy_buf
    0.004    0.001    0.000          (header)
    0.003    0.001    0.000          .dynamic
    0.002    0.000    0.000          .shstrtab
    0.004    0.001    0.000          .eh_frame_hdr
    0.006    0.002    0.002          .rela.dyn
   12.586    7.233    0.621          .debug_frame
    0.285    0.484    0.026          .dynsym
    0.002    0.001    0.000          .interp
    0.003    0.001    0.000          .got.plt
    0.003    0.001    0.000          .comment
    0.003    0.001    0.000          .rela.plt
    0.003    0.001    0.000          .rodata.cst
    0.003    0.001    0.000          .gnu.version
    0.304    0.597    0.031          .gnu.hash
    0.002    0.001    0.000          .tm_clone_table
    1.048    1.255    0.075          .data
    0.002    0.001    0.000          .fini_array
    0.002    0.001    0.000          .note.gnu.build-id
    0.002    0.001    0.000          (header)
   15.103    8.296    0.733          .symtab
    0.301    0.596    0.030          .data.rel.ro
    0.002    0.001    0.000          .note.ABI-tag
    0.554    0.979    0.049          .debug_abbrev
    0.060    0.068    0.006          .init_array
    4.335    4.488    0.279          .debug_ranges
    8.505    6.198    0.461          .text
   19.024    9.315    0.894          .debug_info
    0.002    0.001    0.000          .gnu.version_r
    0.002    0.001    0.000          .tbss
    0.298    0.595    0.029          .dynstr
    0.002    0.000    0.000          .bss
    6.122    5.254    0.357          .debug_str
   11.593    6.945    0.583          .debug_line
    1.594    1.981    0.112          .rodata
    0.000    0.000    0.000          .plt
    0.000    0.000    0.000          .strtab
    0.001    0.000    0.000          .eh_frame
    0.086    0.167    0.011          .got
    0.000    0.000    0.000          (header)
    5.561    5.046    0.333          .debug_aranges
    0.000    0.000    0.000          .plt.got
    0.000    0.000    0.000          .preinit_array
    0.068    0.026    0.005        sort_dynamic_relocs
    0.000    0.000    0.000        clear_padding
    2.911    0.214    0.250        build_id
    0.000    0.000    0.000      close_file
2022-02-04 21:20:45 +09:00
Rui Ueyama 1b2b20423e [ELF] Document --emit-relocs 2022-02-04 20:26:07 +09:00
Rui Ueyama afca9d55aa [ELF] Fix RISC-V code for -O2 2022-02-04 20:11:50 +09:00
Rui Ueyama 043449125d [ELF] Fix --emit-reloc relocation values
With this change, `ninja check-bolt` in LLVM passes. I'm not sure if
that really means mold is usable with Bolt, but I guess it is.

Fixes https://github.com/rui314/mold/issues/177
2022-02-04 20:11:48 +09:00
Rui Ueyama 26fe71d64c [ELF] Support --emit-relocs
This commit adds the `--emit-relocs` option to mold. If the flag is
given, mold copies relocation sections from input files to an output
file. This option is used by some binary post-processing tools such
as Facebook's Bolt.

It looks like the relocations emitted by `--emit-relocs` are correct,
but I didn't do extensive testing. If you find any problem, please
let me know.

Fixes https://github.com/rui314/mold/issues/177
2022-02-04 18:42:08 +09:00
Rui Ueyama 354d1b7d2f [ELF] Fix CI 2022-02-04 18:34:57 +09:00
Rui Ueyama dca8d58b51 Refactor 2022-02-04 18:26:41 +09:00
Rui Ueyama 1550b5afff [ELF] Copy symbols from DSOs to an output file
Previously, mold didn't copy symbols from .so input files to the
output .symtab.
2022-02-04 18:03:17 +09:00
Rui Ueyama e4c03c238e [ELF] Write section symbols to .symtab 2022-02-04 17:05:06 +09:00
Rui Ueyama 0542a2254b Refactor 2022-02-04 17:05:05 +09:00
Rui Ueyama d0ab7d9e17 Refactor 2022-02-04 16:14:00 +09:00
Rui Ueyama dbe99c2884 [ELF] Make the contents of .dynsym deterministic 2022-02-04 07:39:35 +09:00
Rui Ueyama c6ddcc4344 Merge pull request #325 from dmantipov/elf-use-parallel-sort-for-dynsym
Use parallel sort for .dynsym
2022-02-03 22:02:51 +09:00
Dmitry Antipov bfa4ac2ef8 Use parallel sort for .dynsym
Prefer 'tbb::parallel_sort()' over 'std::sort()' in
'DynsymSection<E>::finalize()'. Although being highly
dependent from '--thread-count', this is expected to
achieve up to ~8x speedup for huge (>20M entries)
symbol tables, as shown with '--perf', e.g.
from:
  1.651    0.000    1.662        DynsymSection::finalize
to:
  0.488    0.000    0.198        DynsymSection::finalize

Signed-off-by: Dmitry Antipov <[email protected]>
2022-02-03 14:46:36 +03:00
Rui Ueyama 818971841f Update documents 2022-02-03 20:17:10 +09:00
Rui Ueyama 5c123e2c68 [ELF] Reduce the size of Symbol<E> from 64 to 54 bytes 2022-02-03 20:12:19 +09:00
Rui Ueyama dc7eedee74 Refactor 2022-02-03 17:31:34 +09:00
Rui Ueyama 2359222723 [ELF][RISC-V] Support more relocations 2022-02-02 21:55:19 +09:00
Rui Ueyama 9b90f642a1 [ELF][RISC-V] Support relocation relaxation.
RISC-V psABI defines a mechanism for a linker to shrink a section
by rewriting instructions in it. This patch implements that feature.
2022-02-02 20:40:17 +09:00
Rui Ueyama 0acd4b9d2f [ELF] Reduce the size of InputSection by 8 bytes 2022-02-02 15:03:22 +09:00
Rui Ueyama 7fcff98f29 [ELF] Directly uncompress debug sections into the output mmap'ed buffer
Previously, we always uncompress compressed debug sections to
in-memory buffer before copying them to the final output buffer.
This patch eliminates that redundant copy whenever possible.
2022-02-02 14:18:48 +09:00
Rui Ueyama 3c25434202 Fix clang buildbot 2022-02-01 14:02:25 +09:00
Rui Ueyama e98aab7ea9 [ELF] Reimplement --repro
`--repro` is a hidden command flag for debugging.

Previously, if the flag was given, mold would create a `.repro`
section in an output file with all input files as its contents.
The flaw of the design is that when mold fails to create an output
file, no .repro section would be created.

So I changed the behavior in this commit. Now, the tar file is
created as an independent file.
2022-02-01 13:47:44 +09:00
Rui Ueyama a380c1675f Update README 2022-02-01 10:00:03 +09:00
Rui Ueyama 3232c1f884 Specify the SHA256 ID instead of ubuntu:20.04
`ubuntu:20.04` is a rolling docker tag, so the image pulled from it
is not guaranteed to be the same. We should speicfy the image ID
for reproducibility.

Fixes https://github.com/rui314/mold/issues/317
2022-02-01 09:56:29 +09:00
Rui Ueyama c6b34c2b77 [ELF] Do not use std::bit_ceil.
Some C++ libraries do not seem to provide that function.

Fixes https://github.com/rui314/mold/issues/308
2022-01-31 20:38:37 +09:00
Rui Ueyama d3140a25f6 Refactor 2022-01-31 20:36:43 +09:00
Rui Ueyama 5859be88b9 Merge pull request #321 from dmantipov/fix-wmissing-field-initializers
Fix -Wmissing-field-initializers
2022-01-31 20:34:54 +09:00
Dmitry Antipov 35c0d4ae9a Fix -Wmissing-field-initializers
Add 'mold::elf::GlobPattern::Element' and 'mold::macho::SplitInfo'
trivial constructors to fix all '-Wmissing-field-initializers' as
reported both by g++ and clang++.

Signed-off-by: Dmitry Antipov <[email protected]>
2022-01-31 12:50:01 +03:00
Rui Ueyama 7aa35d12c3 [ELF] Do not use std::has_single_bit
It looks like some stdlib implementations do not provide that function.

Fixes https://github.com/rui314/mold/issues/308
2022-01-31 17:52:05 +09:00
Rui Ueyama 8465438051 Merge pull request #320 from gruenich/feature/fix-warnings
Feature/fix warnings
2022-01-31 11:03:10 +09:00
Christoph Grüninger d301b8a3fe Add missing destructor to InputFile
Fixes Clang's delete-non-abstract-non-virtual-dtor warning

Signed-off-by: Christoph Grüninger <[email protected]>
2022-01-30 23:08:24 +01:00
Christoph Grüninger 3f442402f8 Fix typos in comments
Signed-off-by: Christoph Grüninger <[email protected]>
2022-01-30 22:56:43 +01:00
Christoph Grüninger 705451d21e Remove unsed variables
Signed-off-by: Christoph Grüninger <[email protected]>
2022-01-30 22:55:51 +01:00
Rui Ueyama f7b2ce278b [ELF] Reduce the size of InputSection class
This commit reduces the size of InputSection class from 144 bytes
to 120 bytes. Since we create lots of instance of the class, the
size of it matters.
2022-01-30 20:25:20 +09:00
Rui Ueyama c6e4fb56b4 Bump mold version to 1.0.3 2022-01-30 19:57:30 +09:00
Rui Ueyama e630dea2ab [ELF][RISC-V] Handle relocations against non-alloc sections 2022-01-30 13:10:04 +09:00
Rui Ueyama 2afe571c07 [RISC-V][ELF] Fix .got.plt secton contents
With this change, mold can link mold itself on RISC-V and pass all tests.
2022-01-30 11:34:32 +09:00
Rui Ueyama 1de4874478 Update README 2022-01-30 10:01:11 +09:00
Rui Ueyama 00203dbc7c [ELF][RISC-V] Implement TLS_GOT_HI20 and TLS_GD_HI20
Now all test passed on my SiFive Unmatched RISC-V PC.
2022-01-29 22:35:04 +09:00
Rui Ueyama 190003dac7 Refactor 2022-01-29 20:37:13 +09:00
Rui Ueyama dcdffbdab7 [ELF][RISC-V] Change the default page size to 4096 bytes 2022-01-29 17:39:30 +09:00
Rui Ueyama 80008796de [ELF][RISC-V] Fix segmentation fault 2022-01-29 17:28:06 +09:00
Rui Ueyama 5c89a6d08c [ELF][RISC-V] Set ELF e_flags field 2022-01-29 16:26:24 +09:00
Rui Ueyama 0c4f8bed1b [ELF][RISC-V] Do not create __global_pointer$ symbol for DSO 2022-01-29 16:26:23 +09:00
Rui Ueyama 8a0bf96f6d [ELF][RISC-V] Fix SUB6/SET6 relocations 2022-01-29 16:26:23 +09:00
Rui Ueyama 7718000dba Update a comment
Pointed out by jrtc27.
2022-01-29 16:26:22 +09:00
Rui Ueyama e061e3ca70 [ELF][RISC-V] Add a test for dynamically-linked executable 2022-01-29 14:24:46 +09:00
Rui Ueyama e06396dd79 Merge pull request #314 from kofuk/wrap-ld-bfd
mold-wrapper: Execute mold if ld.bfd is executed
2022-01-28 20:45:08 +09:00
Koki Fukuda 77d979f112 mold-wrapper: Execute mold if ld.bfd is executed
Signed-off-by: Koki Fukuda <[email protected]>
2022-01-28 20:38:01 +09:00
Rui Ueyama 57f996f806 Fix build-static.sh script
`build-static.sh` didn't create a statically-linked binary.

Fixes https://github.com/rui314/mold/issues/315
2022-01-28 19:31:49 +09:00
Rui Ueyama 81e6a88d58 Refactor 2022-01-28 18:48:17 +09:00
Rui Ueyama e76f7c0d47 Add an initial support of RISC-V
With this patch, mold can now produce a statically-link "Hello wrold"
program for RISC-V.
2022-01-28 18:08:42 +09:00
Rui Ueyama 32a7e7cb17 Suppress OpenSSL 3.0's deprecation warnings
OpenSSL deprecates the low-level crypto APIs in OpenSSL 3.0. I guess
there's a reason to do that for them, but for us, the low-level APIs
such as SHA256_CTX, SHA256_Update or SHA256_Final are exactly what we
want to use. After all, we just want to compute SHA256 checksums.

The high-level API that OpenSSL provides requires users to allocate a
context object using new_ctx(). That has some performance hit as it
requires heap allocation. And it's just complicated too.

So, I decided to stick with the deprecated functions at least for now
and just suppresss the warning message by defining
OPENSSL_SUPPRESS_DEPRECATED macro. If OpenSSL deletes these functions,
we need to do something, but it's too early to worry about it.

Fixes https://github.com/rui314/mold/issues/246
2022-01-28 08:59:45 +09:00
Rui Ueyama 379ee22af3 Refactor 2022-01-27 23:21:36 +09:00
Rui Ueyama b879bade6a Merge pull request #310 from trofi/main
Makefile: avoid calling '$(shell)' on each $(CXX) execution
2022-01-27 22:24:45 +09:00
Sergei Trofimovich bc66d9a684 Makefile: avoid calling '$(shell)' on each $(CXX) execution
Before the change calls to $(shell git rev-parse) and $(shell pkg-config)
happened on every mold's .o file (as make's "A = $(B)" performs late
expansion).

After the change $(shell) calls are evaluated once with "A := $(B)"
assignment.

Noticed by chance when 'make' was complaining about missing pkg-config
tool on each build step.

Signed-off-by: Sergei Trofimovich <[email protected]>
2022-01-27 12:29:20 +00:00
Rui Ueyama 59826c197b Merge pull request #309 from sicherha/add-missing-include
Add missing `#include <bit>`
2022-01-27 06:29:16 +09:00
Christoph Erhardt 33a5888725 Add missing #include <bit>
Fixes #308.

Signed-off-by: Christoph Erhardt <[email protected]>
2022-01-26 21:36:34 +01:00
Rui Ueyama 0d542fb3bc Simplify 2022-01-26 20:02:22 +09:00
Rui Ueyama 229ee85890 [ELF][RISC-V] Add a stub for RISCV64
As we add more targets to mold/ELF, it takes more time to compile
source files because compiler has to instantiate more templates.
I think we need to do something to fix it, but for now, I'll just
add a stub for RISC-V 64-bit ISA so that we can start working on
RV64.
2022-01-26 15:16:36 +09:00
Rui Ueyama 110a29552a Add a comment 2022-01-26 09:32:30 +09:00
Rui Ueyama 6c9bb0d7ff Use C++20 bit-twiddling functions more 2022-01-26 09:24:52 +09:00
Rui Ueyama 6a86370b0e Merge pull request #305 from sicherha/c++20-bit-operations
Use C++20 bit-twiddling functions
2022-01-26 09:08:47 +09:00
Christoph Erhardt cb94a4ab1b Use C++20 bit-twiddling functions
This replaces the GCC builtins with their portable C++20 counterparts.

Note that the C++ functions are only defined for unsigned types, so we
need to explicitly specify the appropriate template type argument in
some instances.

Signed-off-by: Christoph Erhardt <[email protected]>
2022-01-25 21:44:00 +01:00
Rui Ueyama 76b127e824 [ELF] Add RISC-V ELF constants 2022-01-25 22:39:41 +09:00
Rui Ueyama 51f7caf263 Simplify 2022-01-25 20:43:47 +09:00
Rui Ueyama e74760e780 Use yield instruction on ARM64 for spinlock 2022-01-25 17:01:06 +09:00
Rui Ueyama 614b6c0e38 Print more information for -stats 2022-01-25 17:01:05 +09:00
Rui Ueyama df75bbee0e Rename variables 2022-01-25 17:01:04 +09:00
Rui Ueyama 220161b6c6 Automatically manage source dependencies 2022-01-25 13:32:51 +09:00
Rui Ueyama b23f8e067c Update README
We now have an instruction as to how to use mold for Rust. `mold -run
cargo build` is not recommended, so remove it from our README.
2022-01-25 11:16:12 +09:00
Rui Ueyama a38111d6bb Merge pull request #301 from Keruspe/libc++
fix build with libc++
2022-01-24 22:59:49 +09:00
Rui Ueyama daccce7bb8 Merge pull request #300 from Keruspe/pkg-config
build-sys: allow overriding pkg-config
2022-01-24 22:57:23 +09:00
Marc-Antoine Perennou 4fc27d2195 fix build with libc++
Otherwise fails with:

/usr/include/c++/v1/__threading_support:370:43: error: use of undeclared identifier 'PTHREAD_MUTEX_RECURSIVE'

200809L triggers __USE_XOPEN2K8 to be defined which enables pthread.h to
define the missing identifier.

Signed-off-by: Marc-Antoine Perennou <[email protected]>
2022-01-24 14:29:03 +01:00
Marc-Antoine Perennou 708112cd16 build-sys: allow overriding pkg-config
Signed-off-by: Marc-Antoine Perennou <[email protected]>
2022-01-24 14:14:43 +01:00
Rui Ueyama 3322ff6e7c [ELF] Compress debug sections with level 1 instead of level 3
Debug sections are generally compressed pretty well with level 1,
so it is. Here is the comparison in lld: https://reviews.llvm.org/D70658
2022-01-24 11:40:07 +09:00
Rui Ueyama 42b7eb87a1 Fix libtbb.so for musl libc
musl libc doesn't provide getcontext/setcontext functions.
It also doesn't define RTLD_DEEPBIND flag.

I already sent a pull request to upstream:
https://github.com/oneapi-src/oneTBB/pull/748
2022-01-24 11:22:35 +09:00
Rui Ueyama b4fa51e981 Fix tests for musl libc 2022-01-24 10:29:31 +09:00
Rui Ueyama dc7432a6dd Avoid GNU extensions in tests 2022-01-24 10:21:08 +09:00
Rui Ueyama 0a0f9b3ad5 [ELF] Protect the last page of a RELRO segment
PT_GNU_RELRO works on page granularity. We always align the begining
of a RELRO segment to a page boundary, but the end was not. Since the
runtime conservatively align _down_ it to a page boundary, the last
page weren't be marked as read-only.

This patch makes the size of a RELRO always a multiple of the page size.
2022-01-24 09:40:21 +09:00
Rui Ueyama b2ef045c03 Style fix 2022-01-24 07:56:19 +09:00
Rui Ueyama e83d1616c8 Update the man page 2022-01-24 07:49:41 +09:00
Rui Ueyama d196ec43e6 Merge pull request #299 from sicherha/fix-glibcxx-assertion
Fix out-of-bounds assertion on aarch64 with `_GLIBCXX_ASSERTIONS` enabled
2022-01-24 07:13:12 +09:00
Christoph Erhardt 03ba8f9325 Fix out-of-bounds error on aarch64 with _GLIBCXX_ASSERTIONS enabled
While an iterator may point beyond the last element of a `std::span`, a
pointer may not.

Fixes #298.

Signed-off-by: Christoph Erhardt <[email protected]>
2022-01-23 21:48:55 +01:00
Rui Ueyama 79f83561bd Merge pull request #296 from sicherha/pass-cxxflags-to-tbb
Pass `CXXFLAGS` to bundled tbb
2022-01-24 00:36:04 +09:00
Christoph Erhardt 0653716408 Pass CXXFLAGS to bundled tbb
This makes work easier for distributions that specify custom hardened
compiler flags.

Signed-off-by: Christoph Erhardt <[email protected]>
2022-01-23 16:03:53 +01:00
Rui Ueyama 6fb64656b9 Bump mold version to 1.0.2 2022-01-23 17:19:40 +09:00
Rui Ueyama 21dd8834d3 Do not create mold as a PIE by default
It is up to packager's choice to create mold as a position-independent
executable or not. If you want, pass `LDFLAGS=-fpie` and `CXXFLAGS=-fPIE`
to `make`.
2022-01-23 16:22:15 +09:00
Rui Ueyama c6dc8da704 Tidy up Makefile
Our Makefile didn't allow overriding CFLAGS, CXXFLAGS or LDFLAGS
because we add mandatory options to these variables. It is contrary
to conventions Makefile conventions explained here.
https://www.gnu.org/prep/standards/html_node/Command-Variables.html#Command-Variables

In this patch, I separated mandatory options to MOLD_CXXFLAGS and
MOLD_LDFLAGS so that users can freely override CFLAGS, CXXFLAGS and
LDFLAGS.

I also removed `DEBUG`, `ASAN` and `TSAN` variables from the Makefile
because we can now simply pass `CXXFLAGS="-g -O0"` or
`CXXFLAGS=-fsanitize=...` instead.
2022-01-23 15:45:48 +09:00
Rui Ueyama f8e7b157c7 Fix a test 2022-01-23 11:41:19 +09:00
Rui Ueyama 9ddc188f97 [ELF] Improve an error message 2022-01-23 11:33:23 +09:00
Rui Ueyama 6671d5b03b Style fix 2022-01-23 11:33:23 +09:00
Rui Ueyama 10e666ce0f Update the man page 2022-01-23 11:33:22 +09:00
Rui Ueyama 27f5b12ee2 Merge pull request #292 from ADKaster/posix-headers
Explicitly include sys/select and sys/time
2022-01-23 11:25:03 +09:00
Rui Ueyama f7b00b7adb Merge pull request #291 from BertalanD/relr-fix
[ELF]: Fix issues with relr relocations
2022-01-23 11:24:10 +09:00
Andrew Kaster ca3d5f49d2 Explicitly include sys/select and sys/time
The SerenityOS LibC doesn't leak the definitions of select(2) or struct
timeval into other POSIX headers. Manually include these headers in
elf/subprocess.cc where they are used for better compatibility.

Signed-off-by: Andrew Kaster <[email protected]>
2022-01-22 15:04:57 -07:00
Daniel Bertalan 1d0a854957 [ELF] Fix encoding of .relr.dyn bitmap entries
Before this change, all bitmap entries ended up containing the value
0x3 (as `pos[i] - base` is guaranteed to be a multiple of the word
size). This expression needs to produce the offset in words from the
base address, so we need to *divide* by the word size.

Signed-off-by: Daniel Bertalan <[email protected]>
2022-01-22 18:20:02 +01:00
Daniel Bertalan d1151a9528 [ELF] Create dynamic entries for .relr.dyn
If the corresponding DT_RELR, DT_RELRSZ and DT_RELRENT dynamic entries
are not present, dynamic linkers won't pick up the relocations encoded
in .relr.dyn.

Signed-off-by: Daniel Bertalan <[email protected]>
2022-01-22 18:19:55 +01:00
Rui Ueyama 1ae6c55c52 Update man page 2022-01-22 20:59:28 +09:00
Rui Ueyama f7ce2f6748 Remove a useless assignment 2022-01-22 20:59:28 +09:00
Rui Ueyama c6b89f9766 Remove unnecessary #include 2022-01-22 13:11:21 +09:00
Rui Ueyama 8eae808223 Revert "[ELF] Compile an Aho-Corasick tree into a DFA"
This reverts commit 31ca2cc2ae
because looks like it's slower than before.
2022-01-22 12:37:40 +09:00
Rui Ueyama 31ca2cc2ae [ELF] Compile an Aho-Corasick tree into a DFA 2022-01-22 12:35:49 +09:00
Rui Ueyama 5cf2328a8b [ELF] Support negation and range in glob pattern 2022-01-22 11:01:55 +09:00
Rui Ueyama ac93f8dfd1 Add comments 2022-01-22 10:23:11 +09:00
Rui Ueyama 28c36e58b7 Revert "Fix a build issue on Gentoo with musl libc"
This reverts commit 2cc85cc21d because
it didn't fix the Gentoo's issue.

https://github.com/rui314/mold/issues/281
2022-01-22 00:52:17 +09:00
Rui Ueyama ba6ccd109c [ELF] Do not use GlobMatcher if all version patterns are simple 2022-01-21 23:47:54 +09:00
Rui Ueyama e9a5d1cee3 [ELF] Handle glob patterns directly instead of converting them to regex
Converting a glob pattern to a regex is fragile, and std::regex is slow.
So we should handle glob patterns ourselves.
2022-01-21 23:32:27 +09:00
Rui Ueyama 4ee3062054 [ELF] Fix version pattern matching 2022-01-21 21:27:49 +09:00
Rui Ueyama 3f4e570320 Simplify 2022-01-21 20:59:19 +09:00
Rui Ueyama d0c1c4db19 [ELF] Use Aho-Corasick algo to handle version script patternsC
To process version scriots, we have to match glob patterns against
symbol strings. Sometimes, we have hundreds or thousands of glob
patterns and have to match them against millions of mangled long
C++ symbol names. This step can be very slow.

In this patch, I implemented the Aho-Corasick algorithm to match glob
patterns to symbol strings as quickly as possible. For the details
of the algorithm, see https://en.wikipedia.org/wiki/Glob_(programming).

This patch improves mold's performance for programs that uses large
version scripts. For example, linking libQt6Gui.so.6.3.0 reduced from
1.10s to 0.05s with this patch.

This patch also changes how symbol versions are applied if two or more
version patterns match to a single symbol string. Previously, the last
one in a script file took precedence. Now, the first one takes
precedence. I believe the new behavior is compatible with GNU ld.

Fixes https://github.com/rui314/mold/issues/156
Fixed https://github.com/rui314/mold/issues/287
2022-01-21 20:30:05 +09:00
Rui Ueyama 05e1054058 s/std::lock_guard/std::scoped_lock/g
It looks like you should use std::scoped_lock instead of std::lock_guard
by default since C++17 unless you have a strong opinion to prefer the
latter.
2022-01-21 15:02:47 +09:00
Rui Ueyama 036fdf0b29 Add a comment 2022-01-21 11:00:36 +09:00
Rui Ueyama 2b034335ec Use std::erase_if instead of our own
I didn't know that C++20 has this function.
2022-01-21 10:40:46 +09:00
Rui Ueyama be6ae07ac1 [ELF] Ignore an ICC-generated GNU linkonce section
If you try to link ICC-generated objects file with GCC-generated objects,
you'll get an error message that `__gxx_personality_v0` is duplicated.
This is because ICC puts a section with this symbol into a GNU linkonce
section, while GCC puts it into a COMDAT section.

ICC should stop putting that symbol into GNU linkonce because it's
superceded by COMDAT long ago.

That being said, we need to do something to make it possible to mix
ICC and GCC object files. In this patch, we simply discard the ICC-
generated section. Since `__gxx_personality_v0` is always provided by
libc (that function handles C++ exceptions), we can simply ignore ICC's
output.

Fixes https://github.com/rui314/mold/issues/271
2022-01-20 22:59:58 +09:00
Rui Ueyama e3359ea415 Fix macOS buildbot 2022-01-20 16:46:08 +09:00
Rui Ueyama 2cc85cc21d Fix a build issue on Gentoo with musl libc
libtbb.so contains undefined symbols on Gentoo with musl libc.
Because we are not using such symbols at runtime, and symbols are
resolved lazily, mold would work fine as long as we can build it.
By passing `-allow-shlib-undefined`, we can build mold.

Fixes https://github.com/rui314/mold/issues/281
2022-01-20 16:35:44 +09:00
Rui Ueyama 9c0a55a2eb [ELF] Fix off-by-one error 2022-01-20 13:45:20 +09:00
Rui Ueyama 8b1905453d [ELF] Do not use BND prefix
BND prefix is defined by Intel MPX extension which is now deprecated by Intel.
2022-01-20 13:39:31 +09:00
Rui Ueyama fa0cb30d8f Refactor 2022-01-20 13:28:16 +09:00
Rui Ueyama 2a4d8b4f72 Rename variables 2022-01-20 12:32:05 +09:00
Rui Ueyama 92876820cb [ELF/ARM64] Support range extension thunks
ARM64 branch instructions have only a 25-bit displacement. Non-thumb
instructions are always aligned to 4 byte boundaries, but with that
implicit trailing two zeros considered, they can represent only a 27-bit
displacement. That means branch instructions can jump to a location only
if it is within a ±128 MiB range.

If a branch destination is farther than that, a linker has to emit machine
code sequence that constructs a full 32-bit address in a register to jump
to the final destination, and redirect the branch to that code sequence.
Such code sequence is called a "range extension thunk" or just "thunk".

Previously, mold didn't support range extension thunks, so it couldn't link
large programs. That would fail with an "relocation out of range" error.
Now, mold gained a feature to create thunks and can link large programs.

Thunk creation is an interesting algorithmic problem. We need to insert
a thunk for at least in every 128 MiB chunk, because otherwise branch
instructions wouldn't be able to jump to a thunk. Adding an entry to a thunk
could slightly enlarge the distance between a branch instruction location
and its destination if the thunk is in between them. That could make the
branch that was previously reachable unreachable.

Usually, this problem is solved by an iterative algorithm. With the
iterative algorithm, a linker check for reachability of all relocations,
create new thunks if necessary, and repeat it until no new thunks are
created.

I implemented a different algorithm than that in this patch. The algorithm
implemented in this patch is guaranteed to work in O(n) where n is the
number of relocations. This algorithm might be novel.

And the algorithm implemented in this patch is quite fast. It can create
thunks in 80 milliseconds on a 16-core Amazon Graviton 2 machine for
clang-14 that has an ~100MB .text section.
2022-01-20 03:16:50 +00:00
Rui Ueyama 02c9fa82d4 [ELF] Ensure mold-warpper.so is linked against libdl 2022-01-20 10:23:32 +09:00
Rui Ueyama 1b01448f01 Merge pull request #286 from tklauser/test-exception-aarch64
[ELF] Pass -fno-PIC along with -mcmodel=large on aarch64
2022-01-20 09:46:42 +09:00
Rui Ueyama dfeb17a5c8 Merge pull request #285 from tklauser/ignore-fix-cortex-flag
[ELF] Ignore --fix-cortex-a53-835769 flag
2022-01-20 09:45:20 +09:00
Rui Ueyama d8e3980b86 Do not link libdl
I don't think mold uses any functionality in libdl. mold-wrapper.so
needs it for dlopen()-family functions on non-NetBSD systems though.
2022-01-20 09:28:51 +09:00
Rui Ueyama 0540f2c10b Update README
Fixes https://github.com/rui314/mold/issues/282
2022-01-20 09:10:21 +09:00
Rui Ueyama 809652d740 [ELF] Handle glob patterns other than * for local: in version scripts
Previously, we didn't handle version scripts like this correctly:

  ver {
    global: *;
    local: foo*;
  }

We didn't handle `local:` part correctly except for `*`.

Fixes https://github.com/rui314/mold/issues/277
2022-01-20 08:51:04 +09:00
Rui Ueyama be41fdbc21 [ELF] Rename variables
`ctx.arg` should contain only variables that can directly be mapped
to command line arguments.
2022-01-20 08:35:52 +09:00
Tobias Klauser fbd4e559e6 [ELF] Pass -fno-PIC along with -mcmodel=large on aarch64
The -mcmodel=large option is incompatible with -fPIC on aarch64, see
https://gcc.gnu.org/onlinedocs/gcc/AArch64-Options.html#index-mcmodel_003dlarge

This makes test/elf/exception.sh pass on linux/arm64.

Signed-off-by: Tobias Klauser <[email protected]>
2022-01-19 21:36:53 +01:00
Tobias Klauser c34c77b9a5 [ELF] Ignore --fix-cortex-a53-835769 flag
GCC passes this on my linux/arm64 machine (Pine64 Pinebook Pro).

Signed-off-by: Tobias Klauser <[email protected]>
2022-01-19 21:15:55 +01:00
Rui Ueyama a4d81fb723 [ELF] Ignore trailing garbage after a terminator in .eh_frame
Follow-up patch for https://github.com/rui314/mold/pull/278
2022-01-19 19:45:31 +09:00
Rui Ueyama 948248b732 Merge pull request #278 from depressed-pho/netbsd-compatibility
Improve compatibility with NetBSD
2022-01-19 19:35:18 +09:00
Masatake Daimon 807679cb0a Skip empty records in .eh_frame
It should be perfectly legal to have an empty CIE along with an end-of-records
marker of FDE. /usr/lib/crtend.o from NetBSD/amd64 has the following .eh_frame
but mold emits an error for the zero-length FDE:

    .section	.eh_frame, "a", @progbits
    .align 8
    .quad 0

Signed-off-by: Masatake Daimon <[email protected]>
2022-01-19 11:16:55 +09:00
Masatake Daimon 67179950d0 Ignore -dc and -dp
GCC 7.5.0 passes these flags to ld(1). Maybe mold should handle them properly,
but since common symbols are considered to be obsolete it's probably not worth
it. At least it's better to ignore them rather than to abort.

Signed-off-by: Masatake Daimon <[email protected]>
2022-01-19 11:16:55 +09:00
Masatake Daimon af05107964 Do not try to link with -ldl unconditionally
Some operating systems, like NetBSD, don't have a separate library for
dlopen(3). They have dl* functions in their libc.

Signed-off-by: Masatake Daimon <[email protected]>
2022-01-19 11:16:55 +09:00
Rui Ueyama fe209f3f4c [ELF] If we can't open an existing output file, create a new one
We try to overwrite to an existing output file if exists because
writing to a file that is already in buffer cache is much faster than
creating a new fresh file and write to it.

Previously, mold failed with the "fchmod failed" error if an existing
file is writable (so open for read-write succeeds) but owned by
someone else (so fchown fails). Now, mold ignore such existing file
and create a fresh output file.

Fixes https://github.com/rui314/mold/issues/275
2022-01-18 16:04:52 +09:00
Rui Ueyama e6d1d011ef Merge pull request #274 from akawashiro/show-errno
Show errno for ftruncate and fchmod
2022-01-18 15:07:15 +09:00
Akira Kawata fe7bc2a846 [ELF] [Mach-O] Show errno for ftruncate and fchmod
Signed-off-by: Akira Kawata <[email protected]>
2022-01-18 14:42:56 +09:00
Rui Ueyama 9453488424 [ELF] Fix test for ARM64 2022-01-18 13:28:57 +09:00
Rui Ueyama 267125e5b1 Update README 2022-01-18 13:07:34 +09:00
Rui Ueyama 43b2a1e423 [ELF] Do not scan .text for .relr.dyn 2022-01-17 20:40:22 +09:00
Rui Ueyama 04ba8f4cbd [ELF] Rename a function 2022-01-17 10:26:23 +09:00
Rui Ueyama c747162717 Simplify 2022-01-16 17:20:26 +09:00
Rui Ueyama 3ad29b230c Simplify 2022-01-16 15:23:47 +09:00
Rui Ueyama 7a8c14a634 [ELF] Do not use parallel scan to compute section offsets
A function passed to tbb::parallel_scan must be associative, but I don't
think our function satisfied that constraint. So I rewrote code without
tbb::parallel_scan.
2022-01-16 13:32:20 +09:00
Rui Ueyama 021463c628 Refactor 2022-01-16 12:55:23 +09:00
Rui Ueyama 1152b6eb38 [ELF] Remove redundant assignment 2022-01-16 08:41:26 +09:00
Rui Ueyama 27be74e800 Simplify 2022-01-15 20:18:25 +09:00
Rui Ueyama 709ed92ac0 [ELF] Rename a function 2022-01-15 16:08:10 +09:00
Rui Ueyama faa75ee9e7 [ELF] Add a comment to explain the encoding of .relr.dyn 2022-01-15 16:02:43 +09:00
Rui Ueyama 3411511a8b [ELF] Ignore i386-specific linkonce symbols
This is a follow-up to the previously commit patch
0c19046721. We needed to ignore symbols
whose address is in a discarded .gnu.linkonce sections.

Fixes https://github.com/rui314/mold/issues/270
2022-01-15 14:28:34 +09:00
Rui Ueyama 12fcc76ff0 Install missing tools to a docker environment
We need `git` and `pkg-config` because we are using them in our
Makefile.
2022-01-15 14:02:40 +09:00
Rui Ueyama 0c19046721 [ELF] Ignore .gnu.linkonce sections in old glibc i386 CRT files
Fixes https://github.com/rui314/mold/issues/270
2022-01-15 00:06:15 +09:00
Rui Ueyama bd6afa1b23 [ELF] Add -pack-dyn-relocs=relr
.relr.dyn is a new section that has been implemented in other linkers
recently. That section contains only the RELATIVE-type dynamic
relocations (i.e. base relocations). Compared to the regular
.rela.dyn, a .relr.dyn's size is typically less than 1/10 because the
section is compressed.

Since PIEs (position-independent executables) tend to contain lots of
RELATIVE-type relocations and PIEs are now the default on many Linux
distributions for security reasons, .relr.dyn is more effective than
it was. It can reduce binary size by a few percent or more.

Note that the runtime support is catching up, so binaries built with
`-pack-dyn-relocs=relr` may not work on your system unless you are
running a very recent version of Linux.
2022-01-14 20:54:37 +09:00
Rui Ueyama 5fc0e503e1 Do not use CPPFLAGS for C++ compiler flags
The correct variable name is `CXXFLAGS`. `CPPFLAGS` is for C preprocessor
flags in the Makefile.
2022-01-14 15:34:55 +09:00
Rui Ueyama 8e709d2b62 Refactor 2022-01-14 11:34:38 +09:00
Rui Ueyama 7fa15fd17e Ignore /SYM64/ pseudo members in thin archives 2022-01-14 11:06:39 +09:00
Rui Ueyama a80524b478 Refactor 2022-01-14 10:57:01 +09:00
Rui Ueyama 2ee2243c63 Refactor 2022-01-13 23:53:53 +09:00
Rui Ueyama bba506d6b4 Ignore /SYM64/ pseudo member inar
I believe this pseudo member is relatively new to support archive
files larger than 4 GiB. I'm not sure if mold can handle such large
archives, but first of all, mold crashes when an archive with this
pseudo member is given.

This commit fixes the crash bug.

I don't know how to create an archive with this pseudo member, so
this commit does not have a testcase.

Reported by sina-ht at https://github.com/rui314/mold/pull/269.
2022-01-13 23:35:11 +09:00
Rui Ueyama d8dc8a6787 [ELF] Optimize relocation processing for non-alloc sections
In mold, a relocation refers either a symbol or a section piece.
A section piece is a segment of a mergeable section such as
.rodata.str.1 or .debug_str.

Previously, we preprocessed all relocations referring mergeable
sections to find their corresponding section pieces. We did this
because we want to find a relocation target as quickly as possible
for `gc_sections` and `scan_rels`.

However, we didn't actually have to do that for non-alloc sections,
as non-alloc sections are not subject to neither `gc_sections` nor
`scan_rels`. So, we could skip relocation preprocessing for non-alloc
sections. This commit implement that optimization.

It looks like this is an effective optimization for programs that have
large debug info because debug sections tend to contain a lot of
relocations referring a .debug_str which is a mergeable section.
Here is a few notable examples.

            Output size  Before  After
  clang-14  2.2 GiB      1.455s  1.396s  (4% faster)
  mongodb   4.8 GiB      2.341s  1.925s  (17% faster)

These nubmers were measured on a simulated 16-core 32-thread machine.
2022-01-13 23:22:03 +09:00
Rui Ueyama a9cca00933 [ELF] Fix symbol visibility
This commit fixes a regression introduced in
ce5749ce2f.
2022-01-13 22:59:04 +09:00
Rui Ueyama d3cd2e780f Remove a redundant data structure 2022-01-13 20:38:43 +09:00
Rui Ueyama 1e81c772ae Move macros to the beginning of the file 2022-01-13 20:31:03 +09:00
Rui Ueyama d2363f1819 Fix warning for the case if -DDEBUG is given 2022-01-13 16:51:12 +09:00
Rui Ueyama c3466b9021 Move a use of strerror_r to a separate file 2022-01-13 13:55:34 +09:00
Rui Ueyama 011a7d35d6 [ELF] Add a test
https://github.com/rui314/mold/issues/244
2022-01-13 13:06:37 +09:00
Rui Ueyama 9d27ee0839 [ELF] Skip incompatible files specified by linker script GROUP command
Fixes https://github.com/rui314/mold/issues/260
2022-01-13 10:42:13 +09:00
Rui Ueyama 299078aefe [ELF] Improve R_X86_64_PC64 and R_386_PC32 handlings
I believe they can be represented using dynamic relocations at runtime.
Since they are used rarely and there even seem to have no assembler
syntax to generate such relocations, I can't write tests for them.
2022-01-13 00:23:25 +09:00
Rui Ueyama 74e0e4f6d0 [ELF] Resurrect a file that was deleted by accident 2022-01-12 22:40:04 +09:00
Rui Ueyama 60c134893c [ELF] Create DT_DEBUG dynamic entry only for executables
gdb uses this field only if it is an executable. Having an extra
dynamic entry is usually harmless, but unfortunately, RPM's `rpmdeps`
tool uses the presence of this entry to distinguish executables from
shared object files. So, it is better not to create a DT_DEBUG entry
for shared object files.

Fixes https://github.com/rui314/mold/issues/254
2022-01-12 22:13:13 +09:00
Rui Ueyama e78608a37a [ELF] Rename a file
We collectively call .o and .so files as input files, so we should
name this file input-files.cc.
2022-01-12 20:41:49 +09:00
Rui Ueyama d2c57e99ca Refactor 2022-01-12 20:35:41 +09:00
Rui Ueyama bb18b29e13 [ELF] Fix --trace-symbol for DSO
Previously, --trace-symbol didn't work for shared object files.
2022-01-12 17:30:51 +09:00
Rui Ueyama 4b6ed1dbf7 Refactor 2022-01-12 17:11:48 +09:00
Rui Ueyama cea6a569af [ELF] Remove "GNU gold" from the --version string
That substring was introduced in de7ba9014f
to appease Gentoo's dev-libs/jansson-2.13.1-r1 package. But I think I
shouldn't done that from the beginning to avoid the sitaution of the
"User-Agent" string of the web browser, which everybody claims they
are Mozilla, AppleWebKit, Chrome and Safari simultaneously.
2022-01-12 16:38:04 +09:00
Rui Ueyama 205138f16e Refactor SharedFile class
This change factors out `elf_syms` and `first_global` from SharedFile
and move them into the base class.
2022-01-12 15:58:33 +09:00
Rui Ueyama 342ab00ac3 Fix typo 2022-01-12 14:11:20 +09:00
Rui Ueyama 24b629a216 Add information about compiler and standard library versions
Fixes https://github.com/rui314/mold/issues/265
2022-01-12 13:47:07 +09:00
Rui Ueyama cafc57fa65 Simplify 2022-01-12 11:16:21 +09:00
Rui Ueyama ce5749ce2f [ELF] Make symbol resolution deterministic
Previously, our parallel symbol resolution algorithm was not
deterministic in edge cases. As an example, consider the following two
source files:

  foo.c:
    inline void fn1() { ... }

  bar.c:
    inline void fn1() { ... }
    void fn2() { ... }

Let's say you compile these files and put them into an archive file.
If mold decided to pull out `foo.o` first for `fn1` and then `bar.o`
for `fn2`, then both `foo.o` and `bar.o` are included into a result.
However, if mold pulled out `bar.o` first, then there's no chance for
`foo.o` to be pulled out, so only `foo.o` would be included into a
result.

The algorithm implemented in this commit should be deterministic.
We do not override symbols when we mark live objects.
2022-01-12 11:16:21 +09:00
Rui Ueyama b6316ef085 Fix build-static.sh
The script was failing becuase CXX defaulted to `c++`.
2022-01-11 22:38:45 +09:00
Rui Ueyama 2464a5551a Update README 2022-01-11 00:20:23 +09:00
Rui Ueyama cf7cc2bd52 Fix comment 2022-01-10 11:12:11 +09:00
Rui Ueyama b18d488104 Refactor 2022-01-09 23:23:59 +09:00
Rui Ueyama 9ca6a9dc5e [ELF] Add -z ibt
Fixes https://github.com/rui314/mold/issues/229
2022-01-09 12:38:38 +09:00
Rui Ueyama 17bdd95936 Simplify 2022-01-09 12:34:35 +09:00
Rui Ueyama 31a43a7ba6 [ELF] Add -z cet-report
Fixes https://github.com/rui314/mold/issues/229
2022-01-09 12:34:32 +09:00
Rui Ueyama 778f8629eb Refactor 2022-01-09 12:34:32 +09:00
Rui Ueyama e29bd8f42b [ELF] Add -z shstk
Fixes https://github.com/rui314/mold/issues/229
2022-01-09 12:34:24 +09:00
Rui Ueyama 013e6ea06e [ELF] Fix .got.plt for IBTPLT
Previously, the `bnd jmp` instruction in a IBTPLT entry jumps to the
middle of an instruction due to an incorrect GOTPLT value. That happened
to work because a value that was there after the jump can be interpreted
as an `add` instruction and the control falled through the next `pushq`.
2022-01-09 10:14:35 +09:00
Rui Ueyama 27d836180f [ELF] Make an undefined symbol to be resolved to a common symbol in an archive
Previously, mold ignored common symbols in an archive when resolving
symbols. As a result, even if an undefined symbol could be resolved
using a common symbol in an archive, mold would end up with an undefined
symbol error.

This commit changes the behavior. Now, an undefined symbol is resolved
to a common symbol in an archive if exists.

Fixes https://github.com/rui314/mold/issues/256
2022-01-08 20:44:22 +09:00
Rui Ueyama 9b710cf832 Refactor 2022-01-08 15:11:25 +09:00
Rui Ueyama 0370e7f1b3 [ELF] Emit a compact PLT section if -z now is passed
Each entry in the regular PLT section takes 16 bytes.
This new PLT section reduces it to 8 bytes.
2022-01-08 14:57:50 +09:00
Rui Ueyama fbfa01dcd1 [ELF] Implement -z ibtplt
https://github.com/rui314/mold/issues/229
2022-01-08 14:09:12 +09:00
Rui Ueyama 18367e69a8 Refactor 2022-01-08 13:24:29 +09:00
Rui Ueyama badc733488 [ELF] Report an error if an incompatible object file is given
Previously, mold would crash if an incompatible object file was given.
https://github.com/rui314/mold/issues/260
2022-01-07 23:04:08 +09:00
Rui Ueyama 54e71f43d4 [ELF] Use .got.plt instead of .got to compute GOT-relative reloc values 2022-01-07 22:27:48 +09:00
Rui Ueyama 329e382c6d Simplify 2022-01-07 20:56:36 +09:00
Rui Ueyama 644fdc8a2f Simplify 2022-01-07 20:42:25 +09:00
Rui Ueyama c9352710f7 Fix clang buildbot 2022-01-07 18:53:01 +09:00
Rui Ueyama f4a37b2e95 Do not use clang/clang++ as the default compilers
mold does not have to be built with clang/clang++, so don't use
these compiler frontends.

mold also doesn't have be built with g++ (GNU C++ compiler).
We use `c++` command instead.

Fixes https://github.com/rui314/mold/issues/261
2022-01-07 18:45:05 +09:00
Rui Ueyama 3dd76cd953 Attempt to fix buildbots 2022-01-07 18:18:00 +09:00
Rui Ueyama d86a774ebf Fix Mach-O tests 2022-01-07 18:12:40 +09:00
Rui Ueyama e7decd2c77 Use relative paths in tests 2022-01-07 18:08:06 +09:00
Rui Ueyama 4324cb2998 Use cc and c++ instead of clang, gcc, clang++ or g++ in tests 2022-01-07 18:02:35 +09:00
Rui Ueyama 4348417dd8 [ELF] Do not convert .ctors/.dtors to .init_array/.fini_array
The .ctors section contains a list of pointers that have to be run
before `main`. It usually contains pointers to global constructors.
The .dtors are for global destructors.

The .init_array and .fini_array serve the same purpose as .ctors and
.dtors. The former sections are newer than the latter sections, and
most programs have already migrated to .{init,fini}_array.

.ctors/.dtors are very similar to .{init,fini}_array, but the order
in which pointers are executed is different. .ctors/.dtors are executed
from the end to the beginning, while .{init,fini}_array are executed
from the beginning to the end.

Previously, we converted .ctors/.dtors sections into .{init,fini}_array
sections. In order to do that, we not only merge .ctors/.dtors to
.{init,fini}_array but also reverse their section contents, so that
the initialization order remains the same.

However, there was a bug in that logic. We forgot to reverse the
locations of dynamic relocations for the converted sections.
So, .ctors/.dtors sections converted to .{init,fini}_array were executed
in a wrong order.

We have two choices to "fix" the issue: (1) reverse not only section
contents but also dynamic relocations, or (2) stop converting .ctors/.dtors.
In this patch, I chose (2).

Since LLVM lld doesn't convert .ctors/.dtors, it shouldn't cause an
issue for most programs.
2022-01-07 17:47:14 +09:00
Rui Ueyama 0e17dbeda8 [ELF] Make --defsym'ed symbols absolute
If a symbol is defined in the form of --defsym=foo=0x<hexvalue>,
it should be defined as an absolute symbol with the given value.
2022-01-07 16:28:14 +09:00
Rui Ueyama 3b33420fe5 [ELF] Support R_X86_64_PLTOFF64 2022-01-07 14:44:17 +09:00
Rui Ueyama e075e622ba Fix buildbots 2022-01-07 13:24:42 +09:00
Rui Ueyama 092286fc1d [ELF] Fix tests so that they work if CC is clang 2022-01-07 12:45:20 +09:00
Rui Ueyama 9004c514da Suppress -Wformat-overflow GCC warning 2022-01-07 10:57:54 +09:00
Rui Ueyama a27c113d35 Attempt to fix i386 host build
This change cherrypicks
https://github.com/oneapi-src/oneTBB/pull/609/commits/542a27fa1cfafaf76772e793549d9f4d288d03a9

https://github.com/rui314/mold/issues/240
2022-01-07 10:09:34 +09:00
Rui Ueyama 1acabd65e3 Add a comment 2022-01-06 23:42:15 +09:00
Rui Ueyama 2f86fef3a0 [ELF] Fix assertion failure
This patch fixes a regression introduced in
43fa021d48.

Fixes https://github.com/rui314/mold/issues/259
2022-01-06 22:01:56 +09:00
Rui Ueyama 79e397ea03 Add a missing #include 2022-01-06 20:54:23 +09:00
Rui Ueyama daa88f2f06 [ELF] Handle '[]' in glob patterns
Previously, mold crashes due to an invalid regex pattern exception
when `[...]` is given as a version script pattern.

Fixes https://github.com/rui314/mold/issues/258
2022-01-06 20:45:46 +09:00
Rui Ueyama 404fa1288b [ELF] Add a test
https://github.com/rui314/mold/issues/258
2022-01-06 18:27:31 +09:00
Rui Ueyama c33df4771f Revert "[ELF] Keep SHF_MERGE and SHF_STRINGS bits"
This reverts commit 4d78510cb0.

If the SHF_MERGE bit is set, sh_entsize must have the size of the unit
for that section. In the previous commit, we changed the behavior of
mold so that it sets SHF_MERGE bits in the output file. However, we
didn't set sh_entsize. So, the resulting section is technically invalid.

We merge sections with different sh_entsize into a single output
section, so there's no easy way to "keep" the original value.

In this commit, we simply revert the previous change so that mold won't
set SHF_MERGE in the output file.

https://github.com/rui314/mold/issues/155
2022-01-06 18:19:06 +09:00
Rui Ueyama 8f23d17ece Fix macOS build 2022-01-06 17:53:40 +09:00
Rui Ueyama 09b9d0af1d [ELF] Remove redundant code 2022-01-06 17:48:46 +09:00
Rui Ueyama 43fa021d48 [ELF] Do not place non-exported symbols into .gnu.hash
Previously, mold put all global symbols into .gnu.hash. Although I
believe it was not an error, it bloated the size of .gnu.hash because
.gnu.hash needs only exported symbols.

https://github.com/rui314/mold/issues/255
2022-01-06 17:47:19 +09:00
Rui Ueyama 907f713e51 [ELF] Remove NEEDS_DYNSYM flag from symbol
I wanted to make sure that a symbol X is in .dynsym if and only if
(X.is_imported || X.is_exported).
2022-01-06 15:27:39 +09:00
Rui Ueyama 276b9d005d [ELF] Add ARM64 to --help message
Fixes https://github.com/rui314/mold/issues/251
2022-01-05 21:41:53 +09:00
Rui Ueyama fe14a08761 Make make to take EXTRA_CFLAGS and EXTRA_CXXFLAGS 2022-01-05 21:36:48 +09:00
Rui Ueyama 3865a10600 Merge pull request #252 from sicherha/fix-tests-on-aarch64
Fix test failures on aarch64
2022-01-05 21:07:26 +09:00
Christoph Erhardt df865725ed Fix test failures on aarch64
Signed-off-by: Christoph Erhardt <[email protected]>
2022-01-05 12:26:56 +01:00
Rui Ueyama be49d673a5 [ELF] Deduce emulation from input files if -m is not given 2022-01-05 19:55:32 +09:00
Rui Ueyama 31a6a1164e Merge pull request #248 from sina-ht/use-pkg-config
Use pkg-config to know where openssl header files reside
2022-01-05 18:40:55 +09:00
Hiroshi Takekawa e8bdbaab22 Use pkg-config to know where openssl header files reside
Let Makefile know how to locate openssl header files in a directory other than
the default directories by using pkg-config. If you don't have pkg-config, then
$(shell) returns empty.

Signed-off-by: Hiroshi Takekawa <[email protected]>
2022-01-05 18:25:17 +09:00
Rui Ueyama 285c9e2c32 [ELF] Attempt to fix buildbots 2022-01-04 20:59:33 +09:00
Rui Ueyama a5029d19a8 [ELF] Automatically fall back to ld.bfd or ld.lld if LTO is in use
This is very hacky but highly practical, so I couldn't resist to not
implement this. We should support LTO natively in the future. In the
meantime, this feature should work as a poor-man's replacement.

Fixes https://github.com/rui314/mold/issues/242
2022-01-04 20:50:16 +09:00
Rui Ueyama 0565a6a6ff Merge pull request #241 from sina-ht/use-pkg-config
Use pkg-config to know where libcrypto resides
2022-01-04 15:05:34 +09:00
Hiroshi Takekawa 6987f06151 Use pkg-config to know where libcrypto resides
Let Makefile know how to link libcrypto in a directory other than the default
directories by using pkg-config. If you don't have pkg-config, then $(shell)
returns empty.

Signed-off-by: Hiroshi Takekawa <[email protected]>
2022-01-04 14:16:09 +09:00
Rui Ueyama a2839f60dd [ELF] Improve an error message
Fixes https://github.com/rui314/mold/issues/233
2022-01-04 13:49:48 +09:00
Rui Ueyama 1bc7c332ab Do not link against librt on Android
Fixes https://github.com/rui314/mold/issues/231
2022-01-04 13:44:55 +09:00
Rui Ueyama 8ffe4cd472 [ELF] Ignore dead FDE entries
Looks like some CUDA object files contains FDEs whose relocation has
r_sym with value 0. Such FDEs are dead and should be ignored.

Unfortunately, there's no easy way to produce an object file containing
such relocation, so this change lacks a testcase.

Fixes https://github.com/rui314/mold/issues/235
2022-01-04 13:32:26 +09:00
Rui Ueyama 70704c7c09 Disable -Wc++11-narrowing on Android
Fixes https://github.com/rui314/mold/issues/231
2022-01-03 20:59:19 +09:00
Rui Ueyama 5029a6d044 Simplify 2022-01-03 20:56:59 +09:00
Rui Ueyama 9894b3173b [ELF] Add --default-symver
Fixes https://github.com/rui314/mold/issues/228
2022-01-03 20:29:33 +09:00
Rui Ueyama 4b2f10d009 [ELF] Improve test 2022-01-03 20:15:04 +09:00
Rui Ueyama 8590fd9947 Better way to suppress -Wint-to-pointer-cast 2022-01-03 18:15:51 +09:00
Rui Ueyama 7bb478b683 Fix macOS build 2022-01-03 18:05:33 +09:00
Rui Ueyama ce2fee10b5 Use strerror_r() instead of strerror()
I have no idea why, but 2b818dbe44 made
mold's chrome link time slower by ~8%. This patch removes the use
of std::mutex.
2022-01-03 17:46:26 +09:00
Rui Ueyama 4033b53d7f Merge pull request #232 from OctopusET/main
Fix build error on riscv64 (#222)
2022-01-03 16:39:38 +09:00
Rui Ueyama 8c0e2378c9 Update the man page 2022-01-03 16:19:43 +09:00
Moon Sungjoon 3fb54162d6 Fix build error on riscv64 (#222)
Patch from this PR: https://github.com/oneapi-src/oneTBB/pull/550

Signed-off-by: Moon Sungjoon <[email protected]>
2022-01-03 16:06:02 +09:00
Rui Ueyama 571a4f72a4 Merge pull request #230 from Cutlery-Drawer/mdoc
Rewrite manual page in `mdoc(7)`
2022-01-03 14:34:55 +09:00
Rui Ueyama 2b818dbe44 Use strerror() instead of strerror_r()
This should fix the build on Android.
Fixes https://github.com/rui314/mold/issues/231
2022-01-02 23:40:51 +09:00
Rui Ueyama 19dce5342f Fix -Wc++11-narrowing
Fixes https://github.com/rui314/mold/issues/231
2022-01-02 22:47:23 +09:00
Alhadis 632fe22240 Rewrite manual page in mdoc(7)
Signed-off-by: John Gardner <[email protected]>
2022-01-02 22:13:09 +11:00
Rui Ueyama 5618038463 [ELF] Show a better error message for the empty input file
Fixes https://github.com/rui314/mold/issues/227
2022-01-02 19:33:07 +09:00
Rui Ueyama 9178b762fc Refactor 2022-01-02 15:44:52 +09:00
Rui Ueyama fea59750ed Do not use LTO to build oneTBB as it causes link failure 2022-01-02 12:52:01 +09:00
Rui Ueyama fba4cb9114 Merge commit 'b82badd127f38f4fea6a4f1c0ec22900dd9dd8e3' as 'third-party/tbb' 2022-01-02 12:51:35 +09:00
Rui Ueyama b82badd127 Squashed 'third-party/tbb/' content from commit 3df08fe23
git-subtree-dir: third-party/tbb
git-subtree-split: 3df08fe234f23e732a122809b40eb129ae22733f
2022-01-02 12:51:35 +09:00
Rui Ueyama d3dc8a2377 Temporarily remove oneTBB to upgrade to v2021.5.0 2022-01-02 12:51:29 +09:00
Rui Ueyama df24372775 Merge pull request #220 from rmcgibbo/main
[ELF] Fix parsing of --no-dynamic-linker on command line
2022-01-02 11:54:27 +09:00
Rui Ueyama 0a8231b59d [ELF] Support R_X86_64_GOTOFF64
Fixes https://github.com/rui314/mold/issues/224
2022-01-02 11:14:33 +09:00
Rui Ueyama 1f7727975c [ELF] Improve test 2022-01-02 11:13:12 +09:00
Robert T. McGibbon 68fa44d399 [ELF] Fix parsing of --no-dynamic-linker on command line
Signed-off-by: Robert T. McGibbon <[email protected]>
2022-01-01 12:22:48 -05:00
Rui Ueyama ab83ed8691 Merge pull request #221 from sicherha/deduplicate-quick-exit
Remove duplicate code
2022-01-01 19:51:32 +09:00
Christoph Erhardt ebe982c443 Remove duplicate code
The exact same four lines of code exist a few lines below this hunk.

Signed-off-by: Christoph Erhardt <[email protected]>
2022-01-01 09:44:37 +01:00
Rui Ueyama 4ccbd24c60 Merge pull request #219 from sicherha/libcxx-13-compatibility
Compatibility for libc++ < 14, plus two additional fixes
2022-01-01 09:12:00 +09:00
Christoph Erhardt da0d0a7b52 Improve workaround for libc++ < 14
The underlying issue got fixed in libc++ 14 with
https://reviews.llvm.org/D97084, but Xcode 13.1 still ships libc++ 13.

Signed-off-by: Christoph Erhardt <[email protected]>
2021-12-31 16:09:26 +01:00
Christoph Erhardt a537509aa6 Fix errno_string() returning an empty string on GNU
Signed-off-by: Christoph Erhardt <[email protected]>
2021-12-31 16:09:26 +01:00
Christoph Erhardt 865b6fed89 Terminate argv array with nullptr
This fixes an error where the subsequent `execv()` occasionally fails
with 'Bad address'.

Signed-off-by: Christoph Erhardt <[email protected]>
2021-12-31 15:43:22 +01:00
Rui Ueyama d100a735a0 Refactor: rename a function 2021-12-31 21:28:16 +09:00
Rui Ueyama 902f23c456 Refactor 2021-12-31 21:04:07 +09:00
Rui Ueyama c92e192e56 [ELF] Remove redundant inline keywords 2021-12-31 21:02:06 +09:00
Rui Ueyama 440ff27e58 [ELF] Refactor 2021-12-31 21:01:59 +09:00
Rui Ueyama 085e3c3abe Simplify 2021-12-31 18:04:39 +09:00
Rui Ueyama 58e43633fc Revert "Revert "Use C++17 filesystem API""
This reverts commit f29a85f20a with a fix
for a build failure.
2021-12-31 16:39:54 +09:00
Rui Ueyama d743acb6cd Disable mimalloc on Android host 2021-12-31 16:14:15 +09:00
Rui Ueyama cb2b4b8f72 Bump mold version to 1.0.1 2021-12-31 14:10:03 +09:00
Rui Ueyama f0874f187a Merge pull request #214 from tklauser/macho-fatal-no-input-files
[Mach-O] Fatal if no input files are given
2021-12-31 10:45:24 +09:00
Tobias Klauser c029521b24 [Mach-O] Fatal if no input files are given
Follow the same behavior in the ELF version of read_input_files and
fatal in case no input files are given. This avoids a segfault in
successive functions when running `./ld64.mold` without any arguments.

Signed-off-by: Tobias Klauser <[email protected]>
2021-12-30 23:26:28 +01:00
Rui Ueyama 7a8beac1c2 [Mach-O] Remove homebrew paths from -L and -I flags
I added homebrew's library paths to -L and -I flags for libxxhash.
Now mold includes libxxhash as a subdirectory, we don't need it.
2021-12-31 00:45:58 +09:00
Rui Ueyama b5172caeb5 Improve test
I think `-m32` means ARM32 if this test runs on ARM64.
2021-12-31 00:13:07 +09:00
Rui Ueyama baff2948d4 Merge pull request #213 from tklauser/test-fix-i386-mergable-strings
Fix skip check in i386-mergable-strings.sh
2021-12-31 00:07:04 +09:00
Tobias Klauser 66c9659f5a Fix skip check in i386-mergable-strings.sh
Check for the ability to build 32-bit binaries like in the other i386
test cases.

Signed-off-by: Tobias Klauser <[email protected]>
2021-12-30 15:58:11 +01:00
Rui Ueyama 9697febd83 Merge pull request #212 from tklauser/macos-x86_64
Avoid infinite recursion in do_main<X86_64>
2021-12-30 22:18:58 +09:00
Rui Ueyama f29a85f20a Revert "Use C++17 filesystem API"
This reverts commit f6e91df440 because
it causes build breakages for a lot of Gentoo packages.
2021-12-30 22:15:52 +09:00
Tobias Klauser cc9f6f430b Avoid infinite recursion in do_main<X86_64>
Running mold on x86_64 macOS 11 currently leads to a segfault due to
inifinite recursion in do_main<X86_64>. Protect against this case by
only calling into do_main<X86_64> once if cputype doesn't match.

Signed-off-by: Tobias Klauser <[email protected]>
2021-12-30 14:08:16 +01:00
Rui Ueyama 7776165ef7 Fix macOS build 2021-12-30 21:40:42 +09:00
Rui Ueyama f6e91df440 Use C++17 filesystem API 2021-12-30 21:32:01 +09:00
Rui Ueyama 3f6e889449 Do not use exceptions
If a given path does not exist, std::filesystem::canonical throws an
exception unless `ec` is given.
2021-12-30 20:33:26 +09:00
Rui Ueyama 8d838e4fd1 Merge pull request #210 from sicherha/path-buffer-sizes
Fix handling of path buffer sizes
2021-12-30 16:51:02 +09:00
Christoph Erhardt 68c4b76352 Use std::filesystem to circumvent buffer-size issues
Signed-off-by: Christoph Erhardt <[email protected]>
2021-12-30 08:43:36 +01:00
Rui Ueyama f6e800655b [ELF] Add a description for --defsym to the man page 2021-12-30 15:44:08 +09:00
Rui Ueyama 35ca107361 Add a missing header 2021-12-30 15:10:07 +09:00
Rui Ueyama 3f8f2e89e5 Show "Passed all tests" message in green 2021-12-30 15:05:17 +09:00
Rui Ueyama d49c50ddaf [ELF] Add --defsym
Fixes https://github.com/rui314/mold/issues/208
2021-12-30 14:48:39 +09:00
Rui Ueyama 44ae92c4ed Remove redundant "../../" from test script paths
So that it's easier to see the output of the test script running
with `bash -x` . This change was made using sed.
2021-12-30 11:11:27 +09:00
Rui Ueyama ec628cb0bf Merge pull request #209 from sicherha/fix-shellcheck-warnings
Add lots of quotes to shell scripts
2021-12-30 07:04:09 +09:00
Christoph Erhardt 0dcc910223 Add lots of quotes to shell scripts
This makes it possible to build and test mold in a path that contains
whitespace characters - with the notable exception of the tests where
`LD_PRELOAD` is used. That's because `LD_PRELOAD` unconditionally treats
any whitespace as separator, regardless of quoting.

The following ShellCheck warnings are eliminated by this commit:
* SC2046: Quote this to prevent word splitting.
* SC2086: Double quote to prevent globbing and word splitting.

Signed-off-by: Christoph Erhardt <[email protected]>
2021-12-29 22:18:19 +01:00
Rui Ueyama 1c6c8c3479 Update README 2021-12-29 21:36:06 +09:00
Rui Ueyama 99866f01b2 Update README as GCC 12.1.0 or later accepts -fuse-ld=mold
Fixes https://github.com/rui314/mold/issues/205
2021-12-29 21:21:45 +09:00
Rui Ueyama f3766cda81 [ELF] Add -z {max,common}-page-size
Fixes https://github.com/rui314/mold/issues/203
2021-12-29 17:14:08 +09:00
Rui Ueyama 946e0c3acd Avoid uname -o
macOS's uname does not support the `-o` option.
2021-12-29 16:12:05 +09:00
Rui Ueyama e1ce8994b9 Merge pull request #204 from Ingrater/fixAndroidBuild
Fix building on Android
2021-12-29 15:55:57 +09:00
Rui Ueyama b151de6684 [ELF] Fix .tbss layout
Fixes https://github.com/rui314/mold/issues/126
2021-12-29 15:50:56 +09:00
Rui Ueyama 4bfaa964a7 Refactor 2021-12-29 12:42:51 +09:00
Rui Ueyama cfed33ee42 Revert "[ELF] Fix a layout issue for thread-local bss sections"
This reverts commit 5c35d2a41f
because it causes a regression https://github.com/rui314/mold/issues/201.

I'll fix https://github.com/rui314/mold/issues/126 in another patch.
2021-12-28 18:36:31 +09:00
Rui Ueyama aa972e5351 [ELF] Remove redundnat "mold: " from error messages 2021-12-28 12:42:25 +09:00
Rui Ueyama 27509f0408 Fix typo
https://github.com/rui314/mold/issues/203
2021-12-28 12:41:26 +09:00
Benjamin Thaut f943da88d7 Do not use mimalloc when building on Android as it causes a infinite recursuion.
Signed-off-by: Benjamin Thaut <[email protected]>
2021-12-27 17:13:25 +01:00
Rui Ueyama e8dcecfff0 [ELF] Create a symlink to mold as /usr/libexec/mold/ld
So that you can pass that directory name as an argument for `-B`.
2021-12-27 13:37:35 +09:00
Rui Ueyama cfccfc247d Update README 2021-12-27 12:25:44 +09:00
Rui Ueyama 04ad22d326 [ELF] Refactor
std::string_view::find_first_of() is faster than compiling a regex
and runnning it.
2021-12-26 23:33:34 +09:00
Rui Ueyama 1228bf3865 Merge pull request #200 from jmglogow/fix_version_globbing
[ELF] Fix '?' for globbing + version scripts
2021-12-26 23:29:02 +09:00
Jan-Marek Glogowski 31b0248b05 [ELF] Fix '?' for globbing + version scripts
For globbing, '?' matches a single character, so must be replaced
with '.'. As a result, don't skip the later regex matching for
version scripts, if the pattern contains either '*' or '?'.

Signed-off-by: Jan-Marek Glogowski <[email protected]>
2021-12-26 15:02:43 +01:00
Rui Ueyama d1161137d9 [ELF] Fix Initial-Exec TLS variables
Previously, GOTTPOFF relocations against Initial-Exec TLS variables
got wrong value.

Fixes https://github.com/rui314/mold/issues/197
2021-12-26 20:51:37 +09:00
Rui Ueyama 888474b59c [ELF] Ignore --warn-execstack
mold never sets executable bit to the stack area, so we can
simply ignore the flag.

Fixes https://github.com/rui314/mold/issues/196
2021-12-26 10:29:16 +09:00
Rui Ueyama 5c35d2a41f [ELF] Fix a layout issue for thread-local bss sections
Previously, if there are more than one TLS BSS section (e.g. .tbss and
.tcommon), mold layout them in such a way that they overlap in memory.
That caused a mysterious program crash to the programs compiled with DMD,
a D compiler.

Fixes https://github.com/rui314/mold/issues/126
2021-12-25 20:32:33 +09:00
Rui Ueyama eaa8bf8b30 [ELF] Fix an error message 2021-12-25 19:29:04 +09:00
Rui Ueyama 0d3c9811c1 Improve make test 2021-12-25 16:59:43 +09:00
Rui Ueyama 6e290aab3e [ELF] Implement --color-diagnostics 2021-12-25 16:55:51 +09:00
Rui Ueyama d1a47ee57b [ELF] Ignore --apply-dynamic-relocs
We always write dynamic relocation addends for bug-compatibiltiy
with the Go toolchain. Therefore, this flag is no-op.

See 919e8cbc62 for the details of
the Go's bug.
2021-12-25 16:22:35 +09:00
Rui Ueyama 7aa5c393e4 [ELF] Support extern "C++" in dynamic lists
Fixes https://github.com/rui314/mold/issues/149
2021-12-25 15:10:24 +09:00
Rui Ueyama 7b3c640472 Fix --dynamic-list
Previously, symbols were not exported from an executable even if
they are specified so by a dynamic list.
2021-12-25 13:38:24 +09:00
Rui Ueyama d9606d65b5 [ELF] Remove R_X86_64_{TLSLD,TPOFF32,TPOFF64} error checks
Compiler should not emit these types of relocations unless it knows
they will never refer imported symbols. However, it looks like GCC 7
emits these relocations against global symbols with STB_GNU_UNIQUE
attribute, which can be resolved to a symbol in other ELF module at
runtime. It looks like the bug only exists in GCC 7 and fixed in
recent versions of GCC.

mold verifies the above conditions and reports an error if the
condition is violated. On the other hand, GNU ld and LLVM lld don't
verify and simply create a shared library that is not always
guaranteed to work.

Give this situation, I decided to simply remove the verification code
from mold. This is what other linkers do, and it make mold "compatible"
with GCC 7.

Fixes https://github.com/rui314/mold/issues/145
2021-12-24 22:50:15 +09:00
Rui Ueyama 13245fd9a8 Merge pull request #194 from sicherha/container-improvements
Container improvements
2021-12-24 22:12:08 +09:00
Rui Ueyama 04ccd4dbdd [ELF] Export undef symbols if both -z defs and -warn-undefined-symbols are given
When we are creating a DSO, unresolved undefined symbols are promoted to
dynamic symbols by default so that they will get another chance to be
resolved at runtime.

You can suppress this behavior by passing `-z defs`. If that option is
given, remaining undefs are reported as errors instead of being silently
promoted.

It looks like `-warn-undefined-symbols` negates the effect of `-z defs`.
So, if both options are given, remaining undefs are promoted to dynamic
symbols. mold previously silently make such symbols absolute symbols with
value 0.

Fixed https://github.com/rui314/mold/issues/152
2021-12-24 21:13:15 +09:00
Rui Ueyama 5601cf4236 [ELF] Add -z separate-code, -z noseparate-code and -z separate-lodable-segments
Fixes https://github.com/rui314/mold/issues/172
2021-12-24 20:28:45 +09:00
Rui Ueyama 088912e2fc [ELF] Create less number of PT_NOTE segments 2021-12-24 20:15:56 +09:00
Rui Ueyama 29d956a7b0 [ELF] Fix handling of DSO symbols with default version
Fixes https://github.com/rui314/mold/issues/150
2021-12-24 16:10:01 +09:00
Rui Ueyama 1ba6cc9188 [ELF] Handle relocation referring 0th symbol correctly 2021-12-24 16:09:57 +09:00
Christoph Erhardt 27f0e8c0e5 Pass on command-line arguments to make inside the container
This allows the caller to pass extra build options if desired.
Moreover, it is possible to run `./build-static.sh test` in order to
execute the testsuite inside the container.

Signed-off-by: Christoph Erhardt <[email protected]>
2021-12-23 16:01:39 +01:00
Christoph Erhardt 92bc33eed4 Add test dependencies to Docker container
These packages contain the i686 toolchain as well as the `file` and
`hexdump` utilities. They increase the size of the container image by
approximately 10 % (70 MiB).

Signed-off-by: Christoph Erhardt <[email protected]>
2021-12-23 16:01:39 +01:00
Christoph Erhardt 6160f3874f Make build-static.sh compatible with Podman and SELinux
* Append the `Z` option for the mounted volume
* Add `--userns=keep-id` if Podman's `docker` wrapper is used

Signed-off-by: Christoph Erhardt <[email protected]>
2021-12-23 16:01:37 +01:00
Rui Ueyama 135f17c5aa [ELF] Handle --sysroot
Attempt to fix https://github.com/rui314/mold/issues/150
2021-12-23 21:23:00 +09:00
Rui Ueyama d60e302f70 Merge pull request #192 from sicherha/fix-broken-mold-wrapper
Do not use custom `LDFLAGS` for linking `mold-wrapper.so`
2021-12-23 20:31:16 +09:00
Christoph Erhardt d858068975 Do not use custom LDFLAGS for linking mold-wrapper.so
Linking a dynamic library with `-static` would prevent it from being
loadable.

Fixes #191.

Signed-off-by: Christoph Erhardt <[email protected]>
2021-12-23 10:41:53 +01:00
Rui Ueyama 8c86c28496 Add -z nodefaultlib
Fixes https://github.com/rui314/mold/issues/184
2021-12-23 15:01:57 +09:00
Rui Ueyama 76407a6646 Do not create a PT_NOTE segment for non-alloc .note sections
Fixes https://github.com/rui314/mold/issues/185
2021-12-23 14:04:08 +09:00
Rui Ueyama 56f63dd295 Merge pull request #186 from sicherha/fix-cppcheck-warnings
[ELF] Add missing calls to `va_end()`
2021-12-22 23:13:25 +09:00
Christoph Erhardt c8cec61e1c [ELF] Add missing calls to va_end()
Reported by cppcheck. Omitting `va_end()` causes undefined behaviour:
https://en.cppreference.com/w/c/variadic/va_end

Signed-off-by: Christoph Erhardt <[email protected]>
2021-12-22 14:10:01 +01:00
Rui Ueyama feb63f7b5b [ELF] Ignore -z nodefaultlib
Fixes https://github.com/rui314/mold/issues/184
2021-12-22 21:04:21 +09:00
Rui Ueyama 4d5e4730a2 Fix typo 2021-12-22 20:44:29 +09:00
Rui Ueyama 24bf92c27c [ELF] Fix a crash bug 2021-12-22 20:41:11 +09:00
Rui Ueyama 8bc57363c8 [ELF] Issue a warning instead of error for an unknown -z option
Fixes https://github.com/rui314/mold/issues/180
2021-12-22 20:08:14 +09:00
Rui Ueyama e65560f963 Add the Repology badge 2021-12-22 19:59:39 +09:00
Rui Ueyama 9326f90d14 Remove dead code
Fixes https://github.com/rui314/mold/issues/175
2021-12-22 17:08:41 +09:00
Rui Ueyama 390e737dea Attempt to silence cppcheck warning
https://github.com/rui314/mold/issues/176
2021-12-22 17:06:23 +09:00
Rui Ueyama 358464d5ad Reduce docker image size for ./build-static.sh
Suggested by https://github.com/rui314/mold/issues/161#issuecomment-997184302.
2021-12-22 14:01:46 +09:00
Rui Ueyama 5bc8bc9d64 Fix -Wall warnings
Fixes https://github.com/rui314/mold/issues/174
2021-12-22 12:10:20 +09:00
Rui Ueyama 74fdf90d70 Fix a test for clang and clang-as
clang-as does not support --keep-locals, so use its synonym -L
which is supported both by GNU as and clang-as.

Fixes https://github.com/rui314/mold/issues/173
2021-12-22 11:42:29 +09:00
Rui Ueyama 530568e662 [ELF] Use a better type 2021-12-20 20:08:25 +09:00
Rui Ueyama f9ff04866e [ELF] Add --threads=N option
Fixes https://github.com/rui314/mold/issues/168
2021-12-20 16:29:22 +09:00
Rui Ueyama 96c44be33d [ELF] Add an assertion 2021-12-20 14:38:36 +09:00
Rui Ueyama 2bd3bc6d47 Revert "[ELF] Relax TLSLD error check"
This reverts commit 1baac27e8c.

In order to link gcc 7's output, relaxing this error check wasn't
enough as reported on https://github.com/rui314/mold/issues/145.
We need to remove more error checks or keep them as-is.
For now, I'll restore all the error checks, but before making another
release, I may remove all error checks to accept gcc 7's buggy
output files.
2021-12-20 13:38:53 +09:00
Rui Ueyama fb89ce22fd Update third-party/mimalloc to v2.0.3 2021-12-20 13:01:38 +09:00
Rui Ueyama 3e397d6e78 Cosmetic changes 2021-12-20 12:35:06 +09:00
Rui Ueyama c824e7831a [ELF] Show a hint if -b binary is given
Fixes https://github.com/rui314/mold/issues/164
2021-12-20 12:26:02 +09:00
Rui Ueyama 8f1c328d1a Cosmetic changes 2021-12-20 11:46:28 +09:00
Rui Ueyama 4d78510cb0 [ELF] Keep SHF_MERGE and SHF_STRINGS bits
Once object files are linked into an executable or a shared object file,
sections are no longer splittable. So these bits don't make sense anymore.

Previously, we cleared the bits. But it looks like there are tools that
are picky about them. So we'll just leave them as-is.

Fixes https://github.com/rui314/mold/issues/155
2021-12-18 17:05:41 +09:00
Rui Ueyama dbc9869d7e Revert "[ELF] Use RE2 for version script symbol matching"
This reverts commit 27147dfe32.

I don't think the performance improvement wasn't large enough to
justify adding more dependencies to third-party libraries.

https://github.com/rui314/mold/issues/156
2021-12-18 13:26:35 +09:00
Rui Ueyama 27147dfe32 [ELF] Use RE2 for version script symbol matching
This is an attempt to speed up version script application.
It looks like RE2 is faster than libstdc++'s std::regex.
This change reduces libQt6Gui.so.6.3.0's link time by about 30%.

https://github.com/rui314/mold/issues/156
2021-12-18 13:23:18 +09:00
Rui Ueyama 665bffa52f Import xxhash library to third-party for ease of building
In some environment, XXH3 isn't available as a binary package.
If you do not like to use the imported xxhash library but instead
link to system's libxxhash.so, invoke make with `SYSTEM_XXHASH=1`.
2021-12-18 13:05:54 +09:00
Rui Ueyama 65dc32fdb8 Merge commit '0621402e0a83a71ee5a13e92ce6a5de0f14dc1f2' as 'third-party/xxhash' 2021-12-18 12:42:16 +09:00
Rui Ueyama 0621402e0a Squashed 'third-party/xxhash/' content from commit 35b0373c
git-subtree-dir: third-party/xxhash
git-subtree-split: 35b0373c697b5f160d3db26b1cbb45a0d5ba788c
2021-12-18 12:42:16 +09:00
Rui Ueyama 1d6d0e2fe3 Merge pull request #158 from sylvestre/second-fix
test/pie.sh: extend the check to other output
2021-12-17 20:16:07 +09:00
Rui Ueyama 4f37c3d024 Fix tests in non-English environment
These test files are not only invoked by make by also directly by hand.
Unsetting `LANG` on each file so that they don't fail in a non-English
environment.

This change is mechanically created by the following command:

  sed -i '1 a export LANG=' test/*/*.sh
2021-12-17 20:06:50 +09:00
Rui Ueyama 072cf0eb30 Merge pull request #153 from sylvestre/patch-1
Force the execution of tests in English
2021-12-17 20:02:31 +09:00
Rui Ueyama 455e729393 [ELF] Make version script application faster
Instead of calling regex match multiple times, create a single
regex and call regex match function only once.

https://github.com/rui314/mold/issues/156
2021-12-17 19:09:26 +09:00
Sylvestre Ledru fbee0ec588 test/pie.sh: extend the check to other output
On debian unstable, the output doesn't contain 'Shared object file'
Parsing a different output

Signed-off-by: Sylvestre Ledru <[email protected]>
2021-12-17 10:02:21 +01:00
Sylvestre Ledru 9a96dc1c33 Force the execution of tests in English
If the tests are executed in a different locale like French, some logs  (ex: ```out/test/elf/auxiliary/log```) can contain output like:

```La section dynamique à l'offset 0x2000 contient 10 entrées :```

which of course doesn't work as the grep is
```
fgrep -q 'Auxiliary library: [foo]' $t/log
```

Signed-off-by: Sylvestre Ledru <[email protected]>
2021-12-17 09:25:42 +01:00
Rui Ueyama 36633895e5 [ELF] Fix undefined symbol versions
Previously, if the following conditions are met:

 - we are creating a shared object file,
 - there's an undefined symbol in an input object file that are
   to be promoted to a dynamic symbol, and
 - a version script defining a default version is given,

then the symbol gets the default version. But that's a wrong behavior
because version scripts should not affect symbols that are not defined
in an output file.

This change fixes the issue by not setting version to such symbol.

Fixes https://github.com/rui314/mold/issues/151
2021-12-17 17:07:36 +09:00
Rui Ueyama 1baac27e8c [ELF] Relax TLSLD error check
This is a workaround for https://github.com/rui314/mold/issues/145
2021-12-17 14:35:43 +09:00
Rui Ueyama a9f9163d2c Fix macOS build failure 2021-12-17 08:51:31 +09:00
Rui Ueyama e4fc96f691 [ELF] Improve error message 2021-12-17 08:47:31 +09:00
Miguel Raz Guzmán Macedo d3adb6ca09 add missing -lrt flag to Makefile (#141)
* add missing -lrt flag to Makefile

vis #140

* update where -lrt is added to Makefile

* add -lrt in Makefile to appropriate line

Signed-off-by: Miguel Raz Guzmán Macedo <[email protected]>
2021-12-17 08:47:01 +09:00
Rui Ueyama 46f22a2778 Merge pull request #147 from Frederik-Baetens/main
fix clang pkg name in fedora instructions
2021-12-16 21:02:20 +09:00
Rui Ueyama 75bd303b15 Merge branch 'main' into main 2021-12-16 21:02:00 +09:00
Rui Ueyama 1c9eea0033 Merge pull request #148 from markusgod/patch-1
Add libstdc++-devel to fedora dependencies.
2021-12-16 20:39:08 +09:00
Mark Nefedov c77271aa56 Add libstdc++-devel to fedora dependencies.
In build environments such as SUSE OBS or Fedora COPR build fails without clang standard library.

https://build.opensuse.org/package/show/home:MarkNefedov/mold
2021-12-16 14:35:46 +03:00
Rui Ueyama 04d5abc9eb Attempt to fix an ODR violation 2021-12-16 20:34:13 +09:00
Frederik Baetens 031ee33093 fix clang pkg name in fedora instructions 2021-12-16 12:22:30 +01:00
Rui Ueyama 307552a70c Merge pull request #144 from rurban/patch-2
start stop copy pasta
2021-12-16 15:43:20 +09:00
Reini Urban f17a2eb941 start stop copy pasta 2021-12-16 07:31:21 +01:00
Rui Ueyama 613ca6fc80 Merge pull request #143 from thesamesam/main
build: fix build-static.sh (adapt to Makefile changes: respect LDFLAGS)
2021-12-16 14:31:03 +09:00
Sam James e610f62818 build: fix build-static.sh (adapt to Makefile changes: respect LDFLAGS)
Closes: https://github.com/rui314/mold/issues/138
Signed-off-by: Sam James <[email protected]>
2021-12-16 04:18:32 +00:00
Rui Ueyama 6fd76f2619 [Mach-O] Fix build breakage on Alpine by renaming PAGE_SIZE
PAGE_SIZE is sometimes defined by a header file as macro.
This change renames it COMMON_PAGE_SIZE.

Fixes https://github.com/rui314/mold/issues/142
2021-12-16 13:05:13 +09:00
Rui Ueyama ed9924895d Bump mold version to 1.0.0 2021-12-15 21:25:26 +09:00
Rui Ueyama 27f72ac320 Fix tests 2021-12-15 20:42:27 +09:00
Rui Ueyama ba1b63eb76 Fix GCC 10 link failure
Fixes https://github.com/rui314/mold/issues/136
2021-12-15 14:42:01 +09:00
Rui Ueyama 9c651d513a Update README 2021-12-15 10:44:58 +09:00
Rui Ueyama d9903d72c7 Make make uninstall to remove an installed man page 2021-12-15 10:41:50 +09:00
Rui Ueyama c9a2fd1d7d Fix a test 2021-12-15 10:36:51 +09:00
Rui Ueyama e99baebc49 Merge pull request #135 from thesamesam/main
build: respect user *FLAGS, don't compress man pages
2021-12-15 10:36:09 +09:00
Sam James 0c6458da26 build: don't compress man page
Negligible saving and downstream, distributions usually recompress or
compress with their own specific options. Unconditionally compressing
man pages, while well intended, usually creates more hassle there.

Signed-off-by: Sam James <[email protected]>
2021-12-14 11:56:47 +00:00
Sam James 770b7312f5 build: respect user *FLAGS
- Respect user CXXFLAGS
- Rename CPPFLAGS (previously used in the sense of "flags for the C++ compiler") -> CXXFLAGS
- CPPFLAGS is generally used for "flags for the C(++) preprocessor.", so let's
  use it for that
- Respect user LDFLAGS
  (In one instance, we were respecting LDFLAGS, but doing it too late.
  We need to pass LDFLAGS _before_ any objects in order for -Wl,--as-needed
  to work correctly.)

Signed-off-by: Sam James <[email protected]>
2021-12-14 11:56:47 +00:00
Rui Ueyama f05c3162cd Update README 2021-12-13 15:28:26 +09:00
Rui Ueyama d821445304 Update README 2021-12-12 21:47:26 +09:00
Rui Ueyama 100ed91a78 [ELF] Ignore -no-call-graph-profile-sort 2021-12-12 14:27:49 +09:00
Rui Ueyama 733bb6354f Rename variables 2021-12-11 21:40:57 +09:00
Rui Ueyama 10a318d5ba [ELF] Fix -exclude_libs option 2021-12-10 20:45:57 +09:00
Rui Ueyama e394fa73d4 Fix demangler 2021-12-10 16:24:54 +09:00
Rui Ueyama 54d75153d2 Rename variables 2021-12-07 21:55:04 +09:00
Rui Ueyama 84cd674ff1 Revert "[ELF] Rename section piece -> subsection"
This reverts commit 3fc9c6c3ed.
2021-12-07 14:44:32 +09:00
Rui Ueyama 58b74bf961 Revert "[ELF] s/SectionFragment/Subsection/g"
This reverts commit aa46df7735.
2021-12-07 14:44:11 +09:00
Rui Ueyama 381ff9ee48 Merge pull request #134 from Keruspe/strip
allow overriding strip
2021-12-06 22:14:35 +09:00
Marc-Antoine Perennou b6549eb4c9 allow overriding strip
Some packaging systems want to handle the stripping by themselves.
Setting e.g. STRIP=true will result in true being used instead of strip
and thus will skip the stripping part, leaving it to the package manager

Signed-off-by: Marc-Antoine Perennou <[email protected]>
2021-12-06 13:32:21 +01:00
Rui Ueyama 22116629f1 [ELF] Add --start-lib and --end-lib
Fixes https://github.com/rui314/mold/issues/133
2021-12-06 20:09:46 +09:00
Rui Ueyama 0328f37b2a [Mach-O] Add -bundle 2021-12-05 16:52:35 +09:00
Rui Ueyama c5f5e6153f [Mach-O] Add -headerpad_max_install_names 2021-12-05 15:53:41 +09:00
Rui Ueyama 6fae1d8555 [Mach-O] Report an error on -search_dylibs_first 2021-12-05 15:40:36 +09:00
Rui Ueyama f6609474b6 Refactor 2021-12-05 13:37:14 +09:00
Rui Ueyama 83721464ed [Mach-O] Remove unnecessary #includes 2021-12-04 21:30:26 +09:00
Rui Ueyama da13b1d3a6 [Mach-O] Fix an assertion failure 2021-12-04 20:21:48 +09:00
Rui Ueyama efefba2bf3 [Mach-O] Port mold/macOS to ARM64 2021-12-04 20:07:36 +09:00
Rui Ueyama cc35d725f2 [Mach-O] Port TBD reader to ARM64 2021-12-04 19:59:42 +09:00
Rui Ueyama a3e0e9f197 wip 2021-12-04 16:41:51 +09:00
Rui Ueyama a3fd0ea5a4 wip 2021-12-04 16:36:18 +09:00
Rui Ueyama 6a3ddf1ab4 wip 2021-12-04 16:31:15 +09:00
Rui Ueyama a7cae9b2a4 wip 2021-12-04 15:41:53 +09:00
Rui Ueyama d8e25b9753 wip 2021-12-04 13:17:47 +09:00
Rui Ueyama a415accbc3 wip 2021-12-04 12:55:21 +09:00
Rui Ueyama d6a9005b14 wip 2021-12-04 12:10:18 +09:00
Rui Ueyama bf7366438b wip 2021-12-03 23:06:07 +09:00
Rui Ueyama 412e3aa136 wip 2021-12-03 18:20:25 +09:00
Rui Ueyama d23183ed31 wip 2021-12-03 16:06:47 +09:00
Rui Ueyama fa8d5d97d0 wip 2021-12-03 15:47:42 +09:00
Rui Ueyama 16921c78ea [Mach-O] Add ARM64 stub 2021-12-02 11:51:42 +09:00
Rui Ueyama 790703b5fa Fix build breakage 2021-12-01 22:15:47 +09:00
Rui Ueyama 4878b8bca2 [Mach-O] Make everything template 2021-12-01 22:02:33 +09:00
Rui Ueyama bdb01432df [Mach-O] Link against libraries in /opt/homebrew 2021-12-01 20:43:17 +09:00
Rui Ueyama 6dfede035b Fix build breakage 2021-12-01 19:45:49 +09:00
Rui Ueyama 4bd92c0d46 [Mach-O] Do not emit PAGEZERO segment for dylibs 2021-12-01 15:14:38 +09:00
Rui Ueyama 57d7a2e8dd [Mach-O] Refactor 2021-12-01 13:50:34 +09:00
Rui Ueyama 8ceaf53728 [Mach-O] Add -needed_framework 2021-12-01 13:45:25 +09:00
Rui Ueyama ee05f3a65f [Mach-O] Add -dead_strip_dylibs 2021-11-30 19:20:29 +09:00
Rui Ueyama 7156dd265f [Mach-O] Add -needed-l 2021-11-30 18:05:28 +09:00
Rui Ueyama 9e7e41cfac [Mach-O] Fix -L 2021-11-30 15:23:00 +09:00
Rui Ueyama 4998a130e5 [Mach-O] Support -dylib 2021-11-29 18:12:48 +09:00
Rui Ueyama 39fbd5b29c Refactor 2021-11-28 10:25:25 +09:00
Rui Ueyama e99727f87f [Mach-O] Add -Z 2021-11-28 10:05:23 +09:00
Rui Ueyama 0ee3986da6 [ELF] Fix image-base.sh test on AArch64 2021-11-27 13:15:02 +00:00
Rui Ueyama 1219d3250c [ELF] Fix a test for AArch64 2021-11-27 21:03:47 +09:00
Rui Ueyama 8ae43210e7 [Mach-O] Add -framework and -F 2021-11-27 20:03:12 +09:00
Rui Ueyama 5deb697ec4 [Mach-O] wip 2021-11-27 13:18:10 +09:00
Rui Ueyama a4a21b6a92 [Mach-O] wip 2021-11-27 13:18:10 +09:00
Rui Ueyama c3c832fffa [ELF] Support R_AARCH64_ADR_PREL_LO21 2021-11-27 12:18:36 +09:00
Rui Ueyama b32f4592fa [ELF] Support R_AARCH64_CONDBR19 2021-11-27 12:18:36 +09:00
Rui Ueyama c8f1766b71 [ELF] Support R_AARCH64_PREL{16,64} 2021-11-27 12:18:36 +09:00
Rui Ueyama 411706d147 [ELF] Accept any argv[0] other than ld64 or ld64.mold
ld is often named as x86_64-pc-linux-gnu-ld or some other system-
dependent name. We shouldn't report an error for an unknown argv[0].
2021-11-27 12:18:36 +09:00
Rui Ueyama 72cea9a0bf [Mach-O] Improve -filelist 2021-11-21 22:18:55 +09:00
Rui Ueyama 5804d6b4b2 [Mach-O] Add -ObjC 2021-11-21 20:26:41 +09:00
Rui Ueyama af4a4af038 [Mach-O] Ignore --color-diagnostics 2021-11-21 15:32:36 +09:00
Rui Ueyama 602ec8d0c0 [Mach-O] Ignore -fatal_warnings 2021-11-21 15:31:23 +09:00
Rui Ueyama efb6e6729a [Mach-O] Handle response files correctly 2021-11-21 14:53:50 +09:00
Rui Ueyama 6087782660 [Mach-O] Add -filepath 2021-11-20 19:26:29 +09:00
Rui Ueyama cee6412e3d [Mach-O] Add -rpath 2021-11-20 19:01:18 +09:00
Rui Ueyama 1e4262753a [Mach-O] wip 2021-11-19 21:42:33 +09:00
Rui Ueyama 39676ef7a9 Define BINDIR, LIBDIR and MANDIR
So that it is easy to specify alternative install target paths.
2021-11-19 17:18:15 +09:00
Rui Ueyama 8b41bb923a [ELF] Fix canonical PLT entry
Previously, an executable linked by mold could fall into an infinite
loop between .plt.got and .got entries. This commit fixes the issue
by creating .plt entries instead of .plt.got.

Fixes https://github.com/rui314/mold/issues/129
2021-11-18 20:53:15 +09:00
Rui Ueyama e2e344ea7a [Mach-O] Fix relocation addends 2021-11-16 19:28:30 +09:00
Rui Ueyama 94889d7a02 [Mach-O] Support LC_DYLD_EXPORTS_TRIE 2021-11-16 12:51:56 +09:00
Rui Ueyama cd404f72cd [Mach-O] wip 2021-11-16 11:44:47 +09:00
Rui Ueyama c13da97044 [Mach-O] wip 2021-11-15 14:50:16 +09:00
Rui Ueyama 0ac8821015 [Mach-O] wip 2021-11-15 11:27:30 +09:00
Rui Ueyama 40b0e08d35 [Mach-O] wip 2021-11-14 21:53:38 +09:00
Rui Ueyama 15215b1f71 [Mach-O] wip 2021-11-14 15:05:22 +09:00
Rui Ueyama 18cfe1f4ca [Mach-O] Add -pagezero_size option 2021-11-14 14:23:44 +09:00
Rui Ueyama 750d6ca3ce [Mach-O] wip 2021-11-14 14:08:50 +09:00
Rui Ueyama 06bc828a9b [Mach-O] wip 2021-11-14 13:30:55 +09:00
Rui Ueyama 91b9f925d6 [Mach-O] wip 2021-11-13 17:45:04 +09:00
Rui Ueyama 433666a470 [Mach-O] Implement -dead_strip 2021-11-13 15:21:52 +09:00
Rui Ueyama d0138a404d [ELF] Rename variables 2021-11-12 19:29:12 +09:00
Rui Ueyama 75c516f3cd [Mach-O] wip 2021-11-12 19:28:55 +09:00
Rui Ueyama fcd592e53d [Mach-O] Add -e option 2021-11-12 19:10:00 +09:00
Rui Ueyama 4a1ec53c24 [Mach-O] wip 2021-11-12 19:10:00 +09:00
Rui Ueyama 2b807ddf83 [Mach-O] wip 2021-11-12 09:56:28 +09:00
Rui Ueyama 66b95013f9 [Mach-O] wip 2021-11-11 16:14:13 +09:00
Rui Ueyama a5e3c681bc [Mach-O] wip 2021-11-11 16:06:21 +09:00
Rui Ueyama 2d5cb51fe2 [Mach-O] wip 2021-11-11 14:53:28 +09:00
Rui Ueyama 03b9e1b914 [Mach-O] wip 2021-11-11 14:41:57 +09:00
Rui Ueyama 132dd7a7f2 [Mach-O] wip 2021-11-11 14:11:55 +09:00
Rui Ueyama 25a902c45a [Mach-O] wip 2021-11-11 13:36:23 +09:00
Rui Ueyama be6824b14d [Mach-O] wip 2021-11-10 22:20:10 +09:00
Rui Ueyama 026f7b9abc [Mach-O] wip 2021-11-10 22:11:54 +09:00
Rui Ueyama bec8166a77 [Mach-O] wip 2021-11-10 20:54:27 +09:00
Rui Ueyama 9f6db83054 [Mach-O] wip 2021-11-10 15:29:41 +09:00
Rui Ueyama 87c4c1df15 [Mach-O] Relax GOT/TLV load instructions 2021-11-09 19:09:07 +09:00
Rui Ueyama 92f56aa73f [Mach-O] Support thread-local variables 2021-11-09 16:23:43 +09:00
Rui Ueyama 3a24532d2a [Mach-O] wip 2021-11-08 20:36:27 +09:00
Rui Ueyama cd73b40635 [Mach-O] wip 2021-11-08 00:17:36 +09:00
Rui Ueyama 72587e643f [Mach-O] wip 2021-11-07 23:57:43 +09:00
Rui Ueyama ea6d310576 [Mach-O] wip 2021-11-07 20:01:36 +09:00
Rui Ueyama 0cb34615d9 [Mach-O] wip 2021-11-07 19:12:58 +09:00
Rui Ueyama c89448d17c [Mach-O] Fix local symbol handling
With this commit, `git show` seems to be working fine on my Mac.
2021-11-07 16:32:23 +09:00
Rui Ueyama 0f0f747135 [Mach-O] Fix .bss sections 2021-11-07 12:18:55 +09:00
Rui Ueyama fd5d95f9d0 [Mach-O] wip 2021-11-07 11:19:58 +09:00
Rui Ueyama a9fea29aaf [Mach-O] wip 2021-11-06 21:29:11 +09:00
Rui Ueyama 6d709de396 [Mach-O] wip 2021-11-06 16:22:55 +09:00
Rui Ueyama b78a62c7ab [Mach-O] wip 2021-11-06 15:50:27 +09:00
Rui Ueyama d88b4c1e86 [Mach-O] wip 2021-11-06 14:56:51 +09:00
Rui Ueyama a4bdd81966 [Mach-O] wip 2021-11-06 14:29:02 +09:00
Rui Ueyama 97ed33758e [Mach-O] wip 2021-11-06 13:05:34 +09:00
Rui Ueyama f7b2558b0e [Mach-O] wip 2021-11-06 11:04:27 +09:00
Rui Ueyama f232e857f0 [Mach-O] wip 2021-11-06 10:53:44 +09:00
Rui Ueyama 977ebe5256 [Mach-O] wip 2021-11-05 22:02:11 +09:00
Rui Ueyama cbc990d459 [Mach-O] wip 2021-11-05 18:40:59 +09:00
Rui Ueyama cd47a3b2be [Mach-O] wip 2021-11-05 16:00:56 +09:00
Rui Ueyama f5dbb8112c Format 2021-11-05 14:41:26 +09:00
Rui Ueyama 247655179f [Mach-O] Add -map option 2021-11-05 14:23:28 +09:00
Rui Ueyama 3f2124e612 [Mach-O] wip 2021-11-05 12:37:26 +09:00
Rui Ueyama 27ed76ddac [Mach-O] wip 2021-11-04 23:12:46 +09:00
Rui Ueyama f90a55cec9 [ELF] Ignore invalid SHF_MERGE sections
DMD, a compiler for the D language, generates a broken .rodata.str1.1
section with sh_entsize = 0. The section also contains out-of-bound
relocations. This patch handles such broken mergeable sections as
regular sections to workaround the issues.

Fixes https://github.com/rui314/mold/issues/126
2021-11-04 22:42:33 +09:00
Rui Ueyama 06f377806b Fix formatting 2021-11-04 22:14:27 +09:00
Rui Ueyama 32f30c304e [ELF] Fix -thread-count option 2021-11-04 22:13:51 +09:00
Rui Ueyama 3d02a3b20b [Mach-O] wip 2021-11-03 22:07:50 +09:00
Rui Ueyama 0f2dbbc09d [Mach-O] Emit __data_in_code 2021-11-03 21:10:46 +09:00
Rui Ueyama bfa50ac015 [Mach-O] Handle Universal binaries 2021-11-03 16:38:29 +09:00
Rui Ueyama 23bbb0fcd2 [Mach-O] Parse .dylib files 2021-11-03 15:26:31 +09:00
Rui Ueyama 32cdec42cb [Mach-O] wip 2021-11-03 13:58:36 +09:00
Rui Ueyama ac8597dee0 [Mach-O] wip 2021-11-03 13:48:18 +09:00
Rui Ueyama 9cef61debe [Mach-O] Emit __code_signature section 2021-11-02 16:11:29 +09:00
Rui Ueyama 2524c6448e [Mach-O] wip 2021-11-02 15:43:18 +09:00
Rui Ueyama c5f3a92f51 [Mach-O] wip 2021-11-02 15:23:06 +09:00
Rui Ueyama 00e45a4ba1 [Mach-O] wip 2021-11-02 15:08:02 +09:00
Rui Ueyama 51779b2a35 [Mach-O] wip 2021-11-02 14:30:32 +09:00
Rui Ueyama 76a92b1a10 [Mach-O] wip 2021-11-02 14:08:33 +09:00
Rui Ueyama 2af5ec006e [Mach-O] wip 2021-11-02 13:45:32 +09:00
Rui Ueyama 581c445062 [Mach-O] wip 2021-11-02 13:03:48 +09:00
Rui Ueyama 28984b5362 [Mach-O] wip 2021-11-02 10:24:30 +09:00
Rui Ueyama 4de3bb9a78 [Mach-O] wip 2021-11-02 10:07:49 +09:00
Rui Ueyama 95f8035ec0 [Mach-O] wip 2021-11-02 10:07:26 +09:00
Rui Ueyama fe9756c9b4 [Mach-O] Support throw-catch 2021-11-01 22:30:27 +09:00
Rui Ueyama 9cc0a2e5be [Mach-O] wip 2021-11-01 22:19:07 +09:00
Rui Ueyama bfec2435da [Mach-O] wip 2021-11-01 21:06:33 +09:00
Rui Ueyama fa5688737c [Mach-O] wip 2021-11-01 20:52:08 +09:00
Rui Ueyama 1f5400071e [Mach-O] wip 2021-11-01 17:24:27 +09:00
Rui Ueyama fb31927a33 [Mach-O] wip 2021-11-01 17:06:27 +09:00
Rui Ueyama 9820a60374 [Mach-O] wip 2021-11-01 16:00:38 +09:00
Rui Ueyama 3c297c2254 [Mach-O] wip 2021-11-01 15:13:28 +09:00
Rui Ueyama ec5c85dcc7 [Mach-O] wip 2021-10-31 16:28:03 +09:00
Rui Ueyama 1ab9f39f70 [Mach-O] wip 2021-10-31 16:12:39 +09:00
Rui Ueyama 01fb761d98 [Mach-O] simplify 2021-10-31 15:46:23 +09:00
Rui Ueyama 3b47e90274 [Mach-O] wip 2021-10-30 15:16:55 +09:00
Rui Ueyama 631412844c [Mach-O] wip 2021-10-30 12:48:46 +09:00
Rui Ueyama 0a6d3986cd [Mach-O] Align common symbols properly 2021-10-29 21:34:27 +09:00
Rui Ueyama 4afc68d74d [Mach-O] Handle common symbols 2021-10-29 16:19:05 +09:00
Rui Ueyama 5ec27ff6c8 [Mach-O] wip 2021-10-29 14:10:32 +09:00
Rui Ueyama c227286dd5 [Mach-O] Handle .bss 2021-10-29 13:28:52 +09:00
Rui Ueyama 16d904a198 [Mach-O] wip 2021-10-28 20:35:26 +09:00
Rui Ueyama e1ab83155a [Mach-O] wip 2021-10-28 18:51:54 +09:00
Rui Ueyama 3fba4dabd6 [Mach-O] wip 2021-10-28 18:43:38 +09:00
Rui Ueyama d3ef7e754d [Mach-O] wip 2021-10-28 18:43:38 +09:00
Rui Ueyama 4c60f05ca5 [Mach-O] wip 2021-10-28 18:43:38 +09:00
Rui Ueyama e1909a541f [Mach-O] wip 2021-10-28 18:43:38 +09:00
Rui Ueyama b1440067cc Fix indentation 2021-10-28 15:50:31 +09:00
Rui Ueyama 58f6502a1c [Mach-O] Add static archive file support 2021-10-28 14:37:18 +09:00
Rui Ueyama 9973e51b92 [Mach-O] wip 2021-10-28 14:37:18 +09:00
Rui Ueyama 30dd7b0230 Merge pull request #125 from Calinou/improve-readme
Add installation instructions for Fedora and improve README
2021-10-28 12:15:22 +09:00
Hugo Locurcio bfc43ef52b Add installation instructions for Fedora and improve README
Fedora dependencies were tested in a fresh Fedora 34 Docker container.

- Use all available CPU threads to speed up compilation.
- Add `sudo make install` step to make the mold binary available
  system-wide.
- List Ubuntu instructions as compatible with Debian 11 (tested
  in a fresh Docker container).
- Reorder the list of dependencies to be consistent between Ubuntu
  and Fedora.
- Don't use a `$` prefix for commands to make copy-pasting easier.
- Fix warnings reported by markdownlint.

Signed-off-by: Hugo Locurcio <[email protected]>
2021-10-28 02:47:40 +02:00
Rui Ueyama 495df9ea00 Change the default install PREFIX from /usr to /usr/local
If not specified, `make install` usually installs binaries to /usr/local.
It's nice to follow that convention.

Fixes https://github.com/rui314/mold/issues/124
2021-10-28 08:06:37 +09:00
Rui Ueyama 4bf1ba34f6 Fix build breakage 2021-10-27 21:53:23 +09:00
Rui Ueyama 7236d14650 [Mach-O] Report errors for remaining undefined symbols 2021-10-27 21:46:57 +09:00
Rui Ueyama 04fcb66580 [Mach-O] wip 2021-10-27 21:24:00 +09:00
Rui Ueyama 6b02b3d9aa [Mach-O] Ignore -no_deduplicate 2021-10-27 21:15:34 +09:00
Rui Ueyama 6a83705a68 [Mach-O] wip 2021-10-27 21:11:02 +09:00
Rui Ueyama 2ec3b16ffd [Mach-O] wip 2021-10-27 21:04:52 +09:00
Rui Ueyama 0bdb744918 [Mach-O] wip 2021-10-27 20:27:18 +09:00
Rui Ueyama cd3726b394 [Mach-O] wip 2021-10-27 20:12:54 +09:00
Rui Ueyama 6cdfd45134 [Mach-O] Create GOT entries for internal references 2021-10-27 15:57:31 +09:00
Rui Ueyama 5549a005f1 [Mach-O] Create GOT entries for external references 2021-10-26 17:44:57 +09:00
Rui Ueyama 5837fe75eb [Mach-O] wip 2021-10-26 16:38:44 +09:00
Rui Ueyama d7fb95fa63 [Mach-O] wip 2021-10-26 15:26:08 +09:00
Rui Ueyama 8471f47abb [Mach-O] wip 2021-10-26 15:24:23 +09:00
Rui Ueyama 48e7616263 [Mach-O] Add the -platform_version option 2021-10-26 15:14:14 +09:00
Rui Ueyama 2589190724 [Mach-O] wip 2021-10-26 15:04:02 +09:00
Rui Ueyama e12055de49 [Mach-O] wip 2021-10-26 14:21:37 +09:00
Rui Ueyama 986516545a [ELF] Do not share OutputFile between ELF and Mach-O 2021-10-26 14:06:11 +09:00
Rui Ueyama ee0ee2375d [Mach-O] wip 2021-10-26 13:53:48 +09:00
Rui Ueyama ed2a7ba1ed [Mach-O] wip 2021-10-26 13:43:04 +09:00
Rui Ueyama 07bf64d9cb [Mach-O] wip 2021-10-26 13:39:41 +09:00
Rui Ueyama d6657a3cb0 [Mach-O] Add the -headerpad option 2021-10-25 20:14:52 +09:00
Rui Ueyama 5817265e91 [Mach-O] Fix ASAN issue 2021-10-25 20:14:32 +09:00
Rui Ueyama a86ad2771a [Mach-O] Use clang as a linker frontend
Now that we can link a "hello world" program on macOS, we can
use clang as a linker frontend.
2021-10-25 19:09:18 +09:00
Rui Ueyama 31e49a08a0 [Mach-O] wip 2021-10-25 15:47:02 +09:00
Rui Ueyama 2e07e62ffd [Mach-O] wip 2021-10-25 15:46:40 +09:00
Rui Ueyama 638bcfe311 [Mach-O] wip 2021-10-25 15:35:09 +09:00
Rui Ueyama 5450debfce [Mach-O] wip 2021-10-25 15:31:03 +09:00
Rui Ueyama 948f4d2605 [Mach-O] wip 2021-10-25 15:05:25 +09:00
Rui Ueyama cb9d159738 [Mach-O] wip 2021-10-25 15:00:45 +09:00
Rui Ueyama 53fe663791 [Mach-O] wip 2021-10-25 01:12:42 +09:00
Rui Ueyama e7f465bf16 [Mach-O] wip 2021-10-24 22:13:06 +09:00
Rui Ueyama 5c8481f1ca [Mach-O] wip 2021-10-24 22:02:02 +09:00
Rui Ueyama 2e92fe2e2a [Mach-O] wip 2021-10-24 22:01:03 +09:00
Rui Ueyama 9d81e7e1a3 [Mach-O] wip 2021-10-24 20:54:26 +09:00
Rui Ueyama 78ff2bb73a [Mach-O] wip 2021-10-24 17:00:53 +09:00
Rui Ueyama 31373b1d6d [Mach-O] wip 2021-10-24 13:34:36 +09:00
Rui Ueyama c56a83c405 [Mach-O] wip 2021-10-24 12:57:54 +09:00
Rui Ueyama 94cda25277 [Mach-O] wip 2021-10-24 00:42:39 +09:00
Rui Ueyama b3528e0aee [Mach-O] wip 2021-10-24 00:27:27 +09:00
Rui Ueyama ecf17abfd3 [Mach-O] wip 2021-10-24 00:18:00 +09:00
Rui Ueyama be147aea80 [Mach-O] wip 2021-10-24 00:12:55 +09:00
Rui Ueyama 07f6e9517d [Mach-O] wip 2021-10-23 23:05:43 +09:00
Rui Ueyama ba8e305fdb [Mach-O] wip 2021-10-23 22:45:17 +09:00
Rui Ueyama 0fbbef7858 [Mach-O] wip 2021-10-23 22:44:32 +09:00
Rui Ueyama 857aef3244 [Mach-O] wip 2021-10-23 22:16:24 +09:00
Rui Ueyama 1f5bc4b3ee [Mach-O] wip 2021-10-23 22:15:03 +09:00
Rui Ueyama ef943d5f9a [Mach-O] wip 2021-10-23 22:12:23 +09:00
Rui Ueyama a70fa4f6b1 [Mach-O] wip 2021-10-23 22:08:34 +09:00
Rui Ueyama 8c8aaf4133 [Mach-O] wip 2021-10-23 21:31:25 +09:00
Rui Ueyama 0b233ee1e6 [Mach-O] wip 2021-10-23 21:14:57 +09:00
Rui Ueyama 1a70f94dcd [Mach-O] wip 2021-10-23 21:10:24 +09:00
Rui Ueyama e66be5010f [Mach-O] wip 2021-10-23 21:09:30 +09:00
Rui Ueyama 7de2e86045 [Mach-O] wip 2021-10-23 21:01:35 +09:00
Rui Ueyama dc22d42e96 [Mach-O] wip 2021-10-23 18:06:21 +09:00
Rui Ueyama bab46b211a [Mach-O] wip 2021-10-23 18:00:10 +09:00
Rui Ueyama 4b6407dfc0 [Mach-O] wip 2021-10-23 17:45:45 +09:00
Rui Ueyama 59139a778d [Mach-O] wip 2021-10-23 17:10:40 +09:00
Rui Ueyama a599ce318e [Mach-O] wip 2021-10-23 17:06:36 +09:00
Rui Ueyama 5bac5f3c60 [Mach-O] wip 2021-10-23 16:54:10 +09:00
Rui Ueyama 794882435f [Mach-O] wip 2021-10-23 16:22:55 +09:00
Rui Ueyama d599ebe3b9 [Mach-O] wip 2021-10-23 11:40:47 +09:00
Rui Ueyama 834d0045ae [Mach-O] wip 2021-10-23 11:18:52 +09:00
Rui Ueyama 0430c806c4 [Mach-O] wip 2021-10-23 10:44:50 +09:00
Rui Ueyama 12ea4e69f1 [Mach-O] wip 2021-10-23 09:12:30 +09:00
Rui Ueyama 43ff20c0a8 [Mach-O] wip 2021-10-22 17:51:19 +09:00
Rui Ueyama d29e75ac7a [Mach-O] wip 2021-10-22 17:16:06 +09:00
Rui Ueyama ee158a031d [Mach-O] wip 2021-10-22 16:34:49 +09:00
Rui Ueyama 95ae34887c [Mach-O] wip 2021-10-22 15:47:07 +09:00
Rui Ueyama 3b357976df [Mach-O] wip 2021-10-22 15:34:16 +09:00
Rui Ueyama 577199ce64 [Mach-O] wip 2021-10-21 23:48:08 +09:00
Rui Ueyama 71a51d5775 [Mach-O] wip 2021-10-21 23:18:15 +09:00
Rui Ueyama 815707e66c [Mach-O] wip 2021-10-21 23:11:29 +09:00
Rui Ueyama e7cc301f17 [Mach-O] Remove dead code 2021-10-21 23:07:49 +09:00
Rui Ueyama 2e32498ef1 [Mach-O] Add the -demangle flag 2021-10-21 22:57:27 +09:00
Rui Ueyama dbf3594146 [Mach-O] wip 2021-10-21 21:11:22 +09:00
Rui Ueyama baec02dc03 [Mach-O] Fix a build issue on macOS 2021-10-19 20:50:47 +09:00
Rui Ueyama 7769a6d2bc [Mach-O] wip 2021-10-19 20:48:47 +09:00
Rui Ueyama 951eca1680 Fix build issue on Linux
I don't know if it is a bug in Clang 10, but the new code couldn't
compile on Linux because `YamlNode` was an incomplete type.
I changed the type from `unordered_map` to `map` to workaround the issue.
2021-10-19 20:46:05 +09:00
Rui Ueyama e28838031c [ELF] Allow the current directory to have a space in it
Fixes https://github.com/rui314/mold/issues/122
2021-10-19 20:39:48 +09:00
Rui Ueyama 5d910222bf [Mach-O] wip 2021-10-19 20:30:53 +09:00
Rui Ueyama 86255ca6bb [Mach-O] wip 2021-10-19 15:33:37 +09:00
Rui Ueyama d200431602 [Mach-O] wip 2021-10-19 14:49:18 +09:00
Rui Ueyama 6f2a13544b [Mach-O] wip 2021-10-18 21:39:52 +09:00
Rui Ueyama 761a4d953b [Mach-O] wip 2021-10-18 10:55:24 +09:00
Rui Ueyama 6d23937bc7 [Mach-O] wip 2021-10-18 09:33:01 +09:00
Rui Ueyama b7993a5f74 [Mach-O] wip 2021-10-17 20:46:17 +09:00
Rui Ueyama 88e714db09 [Mach-O] wip 2021-10-17 20:42:16 +09:00
Rui Ueyama b66f6e0e61 [Mach-O] wip 2021-10-17 20:31:45 +09:00
Rui Ueyama 9605844ccf [Mach-O] wip 2021-10-17 19:52:43 +09:00
Rui Ueyama 45406823c6 [Mach-O] wip 2021-10-17 18:42:23 +09:00
Rui Ueyama 465ff1e238 [Mach-O] wip 2021-10-17 18:40:15 +09:00
Rui Ueyama 43a1742460 [Mach-O] wip 2021-10-17 18:09:03 +09:00
Rui Ueyama 075ac54cd0 [Mach-O] wip 2021-10-17 16:56:00 +09:00
Rui Ueyama 1ec2e78306 [Mach-O] wip 2021-10-16 20:29:22 +09:00
Rui Ueyama 1e39d9f8c8 [Mach-O] wip 2021-10-16 20:23:33 +09:00
Rui Ueyama 42258f0225 [Mach-O] wip 2021-10-16 19:59:21 +09:00
Rui Ueyama 983cf8f203 [Mach-O] wip 2021-10-15 19:14:28 +09:00
Rui Ueyama 63b4e583dc [Mach-O] wip 2021-10-15 17:07:58 +09:00
Rui Ueyama 0393fc2fda [Mach-O] wip 2021-10-15 16:39:03 +09:00
Rui Ueyama 67f8782b53 [Mach-O] wip 2021-10-15 16:34:29 +09:00
Rui Ueyama fa10e60189 [Mach-O] wip 2021-10-15 15:23:00 +09:00
Rui Ueyama e218692672 [Mach-O] wip 2021-10-14 20:54:28 +09:00
Rui Ueyama 4fee9df38d [Mach-O] wip 2021-10-14 20:20:38 +09:00
Rui Ueyama de34da86a0 [Mach-O] wip 2021-10-14 17:54:35 +09:00
Rui Ueyama 97ab328bd7 [Mach-O] wip 2021-10-14 16:43:59 +09:00
Rui Ueyama 4e30c31e17 [Mach-O] wip 2021-10-14 15:05:55 +09:00
Rui Ueyama 1e63f6fbf6 [Mach-O] wip 2021-10-13 17:30:24 +09:00
Rui Ueyama c3e3cfaf44 [Mach-O] wip 2021-10-13 16:50:31 +09:00
Rui Ueyama 0426f3d1de [Mach-O] wip 2021-10-13 16:49:35 +09:00
Rui Ueyama 31e9cea7d2 [Mach-O] wip 2021-10-13 16:30:31 +09:00
Rui Ueyama 06404b96ba [Mach-O] wip 2021-10-13 16:04:22 +09:00
Rui Ueyama 964702c385 [Mach-O] wip 2021-10-13 16:01:56 +09:00
Rui Ueyama 3faa340895 [Mach-O] wip 2021-10-13 14:29:28 +09:00
Rui Ueyama 369c19fdf6 [Mach-O] wip 2021-10-13 09:46:52 +09:00
Rui Ueyama 4ab5e09974 [Mach-O] wip 2021-10-13 09:34:54 +09:00
Rui Ueyama f8ff631605 [Mach-O] wip 2021-10-13 07:50:36 +09:00
Rui Ueyama 2fcbb582ed [Mach-O] wip 2021-10-12 23:04:08 +09:00
Rui Ueyama f382337eb5 [Mach-O] wip 2021-10-12 22:57:00 +09:00
Rui Ueyama f64446c06f [Mach-O] wip 2021-10-12 22:30:49 +09:00
Rui Ueyama d8d733d211 [Mach-O] wip 2021-10-12 18:58:51 +09:00
Rui Ueyama 81581a475d [Mach-O] wip 2021-10-12 18:33:41 +09:00
Rui Ueyama 8124a07e07 [Mach-O] wip 2021-10-12 18:33:41 +09:00
Rui Ueyama d72c1bf62c [Mach-O] wip 2021-10-12 18:33:41 +09:00
Rui Ueyama 34485cc1ec [Mach-O] wip 2021-10-12 18:33:41 +09:00
Rui Ueyama 8097c09c85 [Mach-O] wip 2021-10-12 18:33:41 +09:00
Rui Ueyama a89c7e528f [Mach-O] wip 2021-10-12 18:33:41 +09:00
Rui Ueyama 8639fc8a9b [Mach-O] wip 2021-10-12 18:33:41 +09:00
Rui Ueyama 031de0df32 [Mach-O] wip 2021-10-12 18:33:41 +09:00
Rui Ueyama 43f2e46f34 [Mach-O] wip 2021-10-12 18:33:41 +09:00
Rui Ueyama bb67c78df8 [Mach-O] wip 2021-10-12 18:33:41 +09:00
Rui Ueyama a0a162a48c [Mach-O] wip 2021-10-12 18:33:41 +09:00
Rui Ueyama d176ed8fbb [Mach-O] wip 2021-10-12 18:33:41 +09:00
Rui Ueyama 96b07d875d [Mach-O] wip 2021-10-12 18:33:41 +09:00
Rui Ueyama c1c8270e45 [Mach-O] wip 2021-10-12 18:33:41 +09:00
Rui Ueyama e6c614d69c [ELF] Remove extra path separators 2021-10-12 18:32:20 +09:00
Rui Ueyama ffb8e03c97 [ELF] Make .rela.dyn and .rela.plt contiguous in an output file
glibc 2.22 or prior have a bug that the dynamic linker (ld-linux.so.2)
crashes on `dlopen` if .rela.dyn and .rela.plt are not contiguous in
the `dlopen`-ed file and RTLD_NOW is specified. That bug was fixed in
https://github.com/gentoo/glibc/commit/fa19d5c48a6b36518ce68412e3bdde6bfa8aa4a6.

glibc 2.23 which includes the fix for the bug was released on 2016-02-18.
So, unless you are using glibc that is more than 5 years old, mold-
generated shared object files work fine with `dlopen`. But it is easy
to make the sections contiguous in file, so I'll commit this change as a
workaround for the bug.

Fixes https://github.com/rui314/mold/issues/120
2021-10-12 17:10:32 +09:00
Rui Ueyama 06c237838c [ELF] Fix --help message
Fixes https://github.com/rui314/mold/issues/119
2021-10-08 23:43:03 +09:00
Rui Ueyama e942f5e28e Fix build failure 2021-10-08 20:38:30 +09:00
Rui Ueyama 038f42a579 [Mach-O] wip 2021-10-08 20:24:39 +09:00
Rui Ueyama 69ce692671 [Mach-O] wip 2021-10-08 18:39:48 +09:00
Rui Ueyama d76c6966b0 [Mach-O] wip 2021-10-08 16:55:33 +09:00
Rui Ueyama f7d3fda88a [Mach-O] wip 2021-10-08 16:52:42 +09:00
Rui Ueyama 45fdfd4e87 Disable C++ exceptions
mold itself doesn't use C++ exceptions, so we can disable C++ exceptions.
Passing `-fno-exceptions` to g++/clang++ makes them to produce smaller code.
2021-10-08 15:04:16 +09:00
Rui Ueyama 8ecb117997 [Mach-O] wip 2021-10-07 22:05:49 +09:00
Rui Ueyama 0b5b5dbcf5 [Mach-O] wip 2021-10-07 20:27:53 +09:00
Rui Ueyama 071c74acb3 [Mach-O] wip 2021-10-07 20:01:46 +09:00
Rui Ueyama 86c8b77dd6 [Mach-O] wip 2021-10-07 19:17:18 +09:00
Rui Ueyama 91ec5ae972 [Mach-O] wip 2021-10-07 18:12:38 +09:00
Rui Ueyama 14cadf44ac [Mach-O] wip 2021-10-07 18:01:00 +09:00
Rui Ueyama a414c03bf3 [Mach-O] wip 2021-10-07 17:52:17 +09:00
Rui Ueyama a8b2f521f7 [ELF] Create .rodata.cst and .rodata.str sections
Previously, mold created two or more ".rodata" sections if input files
contain regular .rodata sections as well as .rodata.str* or .rodata.cst*
sections. This is because .rodata.str* and .rodata.cst* contains mergeable
section contents (i.e. string constants and constant pools, respectively),
and they are handled in a special way.

In ELF, section names are not significant, so nothing is wrong with
creating multiple .rodata. However, valgrind unfortunately doesn't like
such executable.

With this change, mold keeps ".rodata.str" and ".rodata.cst" prefixes
to avoid creating multiple ".rodata" sections.

Fixes https://github.com/rui314/mold/issues/118
2021-10-07 13:55:46 +09:00
Rui Ueyama d71c33b3e8 [ELF] Refactor 2021-10-07 12:40:55 +09:00
Rui Ueyama 301d45b2fa Fix a test 2021-10-06 22:04:25 +09:00
Rui Ueyama f49265c788 [Mach-O] Take stub address into symbol address computation 2021-10-06 20:29:08 +09:00
Rui Ueyama 510ec4b003 [Mach-O] Copy __cstring section from input to output 2021-10-06 17:24:51 +09:00
Rui Ueyama 45788bd8ad [Mach-O] wip 2021-10-06 17:16:02 +09:00
Rui Ueyama e2d7cd7b03 [Mach-O] wip 2021-10-06 16:53:20 +09:00
Rui Ueyama 627fbc3ec0 [Mach-O] wip 2021-10-06 16:41:18 +09:00
Rui Ueyama 3c513a31cc [Mach-O] Apply relocations 2021-10-06 14:33:01 +09:00
Rui Ueyama 7fc365a657 [Mach-O] wip 2021-10-06 13:43:41 +09:00
Rui Ueyama dc9cfc4f41 [Mach-O] wip 2021-10-05 22:17:14 +09:00
Rui Ueyama e36cf0271f [Mach-O] wip 2021-10-05 20:14:28 +09:00
Rui Ueyama 46c20da35e [Mach-O] wip 2021-10-05 20:02:41 +09:00
Rui Ueyama 27e52a430b [Mach-O] wip 2021-10-05 19:39:39 +09:00
Rui Ueyama 46d3e12946 [Mach-O] wip 2021-10-05 19:26:15 +09:00
Rui Ueyama a861f192ec [Mach-O] wip 2021-10-05 19:17:57 +09:00
Rui Ueyama bd259a795f [Mach-O] wip 2021-10-05 16:00:45 +09:00
Rui Ueyama 2da5057d58 [Mach-O] wip 2021-10-05 12:59:22 +09:00
Rui Ueyama d111361a1f [Mach-O] wip 2021-10-05 12:59:18 +09:00
Rui Ueyama 46868805e2 [Mach-O] wip 2021-10-05 11:40:33 +09:00
Rui Ueyama e1e603f633 [Mach-O] wip 2021-10-05 11:40:33 +09:00
Rui Ueyama 0a130212cb [Mach-O] wip 2021-10-05 11:40:33 +09:00
Rui Ueyama 7dd9a38b3b [Mach-O] wip 2021-10-05 11:40:32 +09:00
Rui Ueyama e7f3e94f30 [Mach-O] wip 2021-10-05 11:40:32 +09:00
Rui Ueyama 2dc8ac0bdd [Mach-O] wip 2021-10-05 11:40:32 +09:00
Rui Ueyama 4932daadba [Mach-O] wip 2021-10-05 11:40:32 +09:00
Rui Ueyama 74244c3c9c [Mach-O] wip 2021-10-05 11:40:32 +09:00
Rui Ueyama 8965de697b [Mach-O] wip 2021-10-05 11:40:32 +09:00
Rui Ueyama 89d5e9e3b4 [Mach-O] wip 2021-10-05 11:40:32 +09:00
Rui Ueyama fd62bbfacb [Mach-O] wip 2021-10-05 11:40:32 +09:00
Rui Ueyama e6edf2002d [Mach-O] wip 2021-10-05 11:40:32 +09:00
Rui Ueyama f68e301c30 [Mach-O] wip 2021-10-05 11:40:32 +09:00
Rui Ueyama 745792b34d [Mach-O] wip 2021-10-05 11:40:32 +09:00
Rui Ueyama 7933e44493 [Mach-O] wip 2021-10-05 11:40:32 +09:00
Rui Ueyama 840d19bb5e [Mach-O] Add -o option 2021-10-05 11:40:32 +09:00
Rui Ueyama ca9a6d0843 Move code from elf/output-file.cc to output-file.h 2021-10-05 11:37:30 +09:00
Rui Ueyama de1db98cde Split mold.h into multiple headers 2021-10-05 11:24:48 +09:00
Rui Ueyama 7b251e3d7b [ELF] Improve .init and .fini detection logic 2021-10-05 11:05:36 +09:00
Rui Ueyama 30b45d2263 [ELF] Rename Symbol<E>::intern -> intern 2021-10-05 08:31:28 +09:00
Rui Ueyama 3fc9c6c3ed [ELF] Rename section piece -> subsection 2021-10-05 08:22:38 +09:00
Rui Ueyama 97ff050396 Use s suffix 2021-10-04 15:41:49 +09:00
Rui Ueyama e89af3ee94 Use sv suffix 2021-10-04 15:28:02 +09:00
Rui Ueyama 77069156cb [ELF] Rename OutputChunk Chunk 2021-10-04 10:16:24 +09:00
Rui Ueyama 0c42930d55 [Mach-O] Add -o option 2021-10-03 18:17:59 +09:00
Rui Ueyama 928c39937a Refactor 2021-10-03 16:26:31 +09:00
Rui Ueyama 001cf042d9 Refactor 2021-10-03 16:01:59 +09:00
Rui Ueyama fcd10254b7 Rename variables 2021-10-03 16:01:59 +09:00
Rui Ueyama bc3f556055 Make get_file_type() to recognize Mach-O file types 2021-10-03 13:44:45 +09:00
Rui Ueyama 0426ec6d2f [Mach-O] Simplify 2021-10-03 12:01:17 +09:00
Rui Ueyama 19b1b0252c [Mach-O] Dump export table entries 2021-10-02 17:48:52 +09:00
Rui Ueyama ebc8a68cb3 [ELF] Rename variables 2021-10-02 14:12:42 +09:00
Rui Ueyama 4a65748851 [Mach-O] Refactor 2021-10-02 14:02:42 +09:00
Rui Ueyama 56b7c42fae Refactor 2021-10-01 00:35:42 +09:00
Rui Ueyama 52c7793326 Move archive-file.cc out of elf directory 2021-09-30 23:13:27 +09:00
Rui Ueyama 7c9205f68d Move memory-mapped-file.cc out of elf directory
So that we can use the class from mold/mach-o.
2021-09-30 23:13:22 +09:00
Rui Ueyama ffd34678e0 [ELF] Fix "mold-wrapper.so is not found" error 2021-09-30 15:01:55 +09:00
Rui Ueyama a6c75e969d [ELF] Refactor 2021-09-30 00:10:56 +09:00
Rui Ueyama a2c9d0ad4d [ELF] Reduce the size of Subsection struct 2021-09-29 16:30:04 +09:00
Rui Ueyama aa46df7735 [ELF] s/SectionFragment/Subsection/g 2021-09-29 16:18:41 +09:00
Rui Ueyama d123009460 [Mach-O] Add a test 2021-09-28 21:55:37 +09:00
Rui Ueyama cc5cd031ab [Mach-O] Use sysctl -n hw.logicalcpu instead of nproc no macOS
`nproc` is not a valid command on macOS.
2021-09-28 21:20:05 +09:00
Rui Ueyama e3d47ddafa [Mach-O] Do not try to use ccache for brew
The brew command, by design, will never use ccache.
2021-09-28 21:15:00 +09:00
Rui Ueyama 4f69f53cae [Mach-O] Make GitHub actions macOS rules to use ccache 2021-09-28 21:12:58 +09:00
Rui Ueyama 99fba5995a [Mach-O] Make GitHub CI to run make test on macOS 2021-09-28 18:49:11 +09:00
Rui Ueyama 9d805f5d26 [Mach-O] Make make test to work on macOS 2021-09-28 18:47:24 +09:00
Rui Ueyama 5e3f526bc1 Refactor 2021-09-28 16:40:07 +09:00
Rui Ueyama c74b2197f9 Refactor 2021-09-28 16:24:41 +09:00
Rui Ueyama dad3306d1f [Mach-O] Set up macOS github actions 2021-09-28 15:44:25 +09:00
Rui Ueyama 2844f1f573 [ELF] Refactor 2021-09-28 13:23:58 +09:00
Rui Ueyama bc2bd0e26a [ELF] Refactor 2021-09-27 23:01:51 +09:00
Rui Ueyama 3d95b0e1d4 [ELF] Refactor 2021-09-27 21:44:39 +09:00
Rui Ueyama 5bd9edeeed Bump mold version to 0.9.6 2021-09-27 20:38:18 +09:00
Rui Ueyama c40b9aea5f [Mach-O] Generalize perf.cc so that we can use the feature in mold/mach-o 2021-09-27 18:14:56 +09:00
Rui Ueyama 1fb421d82c Fix a bug for a very long pathname 2021-09-27 17:38:55 +09:00
Rui Ueyama 541399911d [ELF] Refactor 2021-09-26 19:55:46 +09:00
Rui Ueyama 67990f775b [ELF] Refactor 2021-09-26 18:50:03 +09:00
Rui Ueyama 58f1fbadc3 [ELF] Refactor 2021-09-26 12:43:51 +09:00
Rui Ueyama 6536663130 [ELF] Fix comment 2021-09-26 12:43:39 +09:00
Rui Ueyama 774fc0f340 [ELF] Remove an extra space in an error message 2021-09-26 12:43:39 +09:00
Rui Ueyama a5d02b18c7 Refactor 2021-09-25 21:47:09 +09:00
Rui Ueyama e4861bb3e1 [ELF] Fix "recompile with -fPIC" error
mold used to emit a spurious "recompile with -fPIC" error when creating
a position-dependent executable. This is because we alwyas create
dynamic relocations for importe symbols. If the relocated place is
read-only, we can't apply a dynamic relocation, and we printed out the
error message.

This patch fixes the issue by creating copy relocations and PLTs for
such symbols.

Fixes https://github.com/rui314/mold/issues/116
2021-09-25 18:13:26 +09:00
Rui Ueyama d11ecda08c [Mach-O] wip 2021-09-23 14:38:37 +09:00
Rui Ueyama 23ab97351f Update README 2021-09-23 14:32:22 +09:00
Rui Ueyama 326831837d [Mach-O] wip 2021-09-23 14:31:04 +09:00
Rui Ueyama bdd458241b [Mach-O] wip 2021-09-21 21:48:32 +09:00
Rui Ueyama fc2ee0d0b0 [Mach-O] wip 2021-09-21 19:32:48 +09:00
Rui Ueyama c002284cd8 [Mach-O] wip 2021-09-21 19:11:34 +09:00
Rui Ueyama 56fb6ba443 [Mach-O] wip 2021-09-21 18:56:31 +09:00
Rui Ueyama c66bd302bd [Mach-O] Programmatically construct __stubs, __stub_helper and __la_symbol_ptr 2021-09-21 17:19:44 +09:00
Rui Ueyama 17c67418f6 [Mach-O] wip 2021-09-21 17:16:42 +09:00
Rui Ueyama 935194d5ae [Mach-O] wip 2021-09-21 15:57:23 +09:00
Rui Ueyama 02ce171aba [Mach-O] wip 2021-09-21 14:53:38 +09:00
Rui Ueyama a52179d090 [Mach-O] wip 2021-09-21 14:51:29 +09:00
Rui Ueyama 1390a7f622 [Mach-O] wip 2021-09-21 14:47:09 +09:00
Rui Ueyama a05d073018 [Mach-O] wip 2021-09-21 14:32:54 +09:00
Rui Ueyama c0daab6075 [Mach-O] wip 2021-09-21 12:55:09 +09:00
Rui Ueyama 18fb0d5d3f [Mach-O] Programmatically construct symtab 2021-09-20 22:04:41 +09:00
Rui Ueyama 5f5139ad6c [Mach-O] wip 2021-09-20 19:41:03 +09:00
Rui Ueyama 046324b64c Simplify 2021-09-20 17:59:37 +09:00
Rui Ueyama 48c16571d1 Simplify 2021-09-20 17:27:23 +09:00
Rui Ueyama 1127061d54 Simplify 2021-09-20 16:36:50 +09:00
Rui Ueyama fa2f54b358 Fix indentation 2021-09-20 16:31:33 +09:00
Rui Ueyama afbc46e135 Simplify 2021-09-20 12:39:34 +09:00
Rui Ueyama e3cebd981e [Mach-O] wip 2021-09-19 20:28:45 +09:00
Rui Ueyama 9881a61cb3 [Mach-O] Programmatically construct export trie 2021-09-19 20:18:34 +09:00
Rui Ueyama 43e513d7af [Mach-O] wip 2021-09-19 19:17:12 +09:00
Rui Ueyama 08f049434f [Mach-O] wip 2021-09-19 16:21:08 +09:00
Rui Ueyama a71f70708c [Mach-O] wip 2021-09-19 14:35:45 +09:00
Rui Ueyama 7f671f5390 [Mach-O] Programmatically construct lazy bind instructions 2021-09-19 14:13:01 +09:00
Rui Ueyama d84b813cb3 [Mach-O] Programmatically construct bind instructions 2021-09-19 13:37:56 +09:00
Rui Ueyama fabd425f67 [Mach-O] Simplify 2021-09-19 12:13:54 +09:00
Rui Ueyama fbf3a1a24e [Mach-O] Programmatically construct rebase instructions 2021-09-19 12:01:03 +09:00
Rui Ueyama 76874d84ba [Mach-O] Output "hello world" program
With this change, ld64.mold is able to emit a "hello world" program.

  $ ./ld64.mold -out hello
  $ ./hello
  Hello world
2021-09-18 20:57:05 +09:00
Rui Ueyama ded5d5e6a1 [Mach-O] wip 2021-09-18 20:57:03 +09:00
Rui Ueyama 2d5e6888f9 [Mach-O] wip 2021-09-18 20:57:01 +09:00
Rui Ueyama 3a503ce2cc [Mach-O] wip 2021-09-18 20:56:59 +09:00
Rui Ueyama 1f3f019a59 [Mach-O] wip 2021-09-18 20:56:55 +09:00
Rui Ueyama f55fc5f082 [Mach-O] wip 2021-09-18 20:56:51 +09:00
Rui Ueyama fb0b316c81 [Mach-O] wip 2021-09-18 17:38:34 +09:00
Rui Ueyama 1ebfc28aea [Mach-O] wip 2021-09-18 17:25:59 +09:00
Rui Ueyama da5effd52d [Mach-O] wip 2021-09-18 16:56:00 +09:00
Rui Ueyama e8aa31cd8b [Mach-O] wip 2021-09-18 15:05:46 +09:00
Rui Ueyama c7243f6c5c [Mach-O] wip 2021-09-18 14:38:23 +09:00
Rui Ueyama 2500ae7e27 [Mach-O] wip 2021-09-18 12:35:27 +09:00
Rui Ueyama 5af8995471 [Mach-O] wip 2021-09-18 12:27:17 +09:00
Rui Ueyama aa5061d784 [Mach-O] wip 2021-09-18 11:42:48 +09:00
Rui Ueyama 4b79c858dd [Mach-O] wip 2021-09-18 11:40:38 +09:00
Rui Ueyama d2aec43b66 [Mach-O] wip 2021-09-17 22:40:21 +09:00
Rui Ueyama 76b767df4b [Mach-O] wip 2021-09-17 22:01:00 +09:00
Rui Ueyama 1dc41ab2d0 [Mach-O] wip 2021-09-17 21:57:34 +09:00
Rui Ueyama c6d3370f07 [Mach-O] wip 2021-09-17 20:47:53 +09:00
Rui Ueyama 40a689011e [Mach-O] wip 2021-09-17 20:43:49 +09:00
Rui Ueyama 03d73f2e9e [Mach-O] wip 2021-09-17 20:32:29 +09:00
Rui Ueyama 142a9c2703 [Mach-O] wip 2021-09-17 20:13:37 +09:00
Rui Ueyama 49233b1ef6 [Mach-O] wip 2021-09-17 18:03:44 +09:00
Rui Ueyama 958d79fa6b [Mach-O] wip 2021-09-17 15:19:00 +09:00
Rui Ueyama 079900fa84 [Mach-O] wip 2021-09-17 13:54:40 +09:00
Rui Ueyama 211bc1810b [Mach-O] wip 2021-09-16 22:23:18 +09:00
Rui Ueyama 0d60940b40 [Mach-O] wip 2021-09-16 22:12:51 +09:00
Rui Ueyama 1e3aff2d71 [Mach-O] wip 2021-09-16 20:02:24 +09:00
Rui Ueyama 7bab3aa994 [Mach-O] wip 2021-09-16 19:26:49 +09:00
Rui Ueyama bfdf9ecf7b [Mach-O] wip 2021-09-16 18:13:59 +09:00
Rui Ueyama 4933af3550 [Mach-O] wip 2021-09-16 17:59:32 +09:00
Rui Ueyama 474dc4a123 [Mach-O] wip 2021-09-16 17:40:14 +09:00
Rui Ueyama aea0022c5c [Mach-O] wip 2021-09-16 17:19:54 +09:00
Rui Ueyama a1ec749dfe [Mach-O] wip 2021-09-16 16:54:14 +09:00
Rui Ueyama 6b477e37ca [Mach-O] wip 2021-09-16 16:21:18 +09:00
Rui Ueyama 28092ffe9d [Mach-O] wip 2021-09-16 15:29:30 +09:00
Rui Ueyama 5e83481ffb [Mach-O] wip 2021-09-16 14:49:50 +09:00
Rui Ueyama 7232178513 [Mach-O] wip 2021-09-16 14:20:38 +09:00
Rui Ueyama aaf04a515b [Mach-O] wip 2021-09-16 12:25:05 +09:00
Rui Ueyama 5ea876ff2f [Mach-O] wip 2021-09-15 21:00:34 +09:00
Rui Ueyama 2fedb900d3 [Mach-O] wip 2021-09-15 17:32:13 +09:00
Rui Ueyama 150565601b Move error handlers from mold::elf to mold 2021-09-15 15:32:42 +09:00
Rui Ueyama 6ab3ddaf8e Move cleanup handlers from mold::elf to mold 2021-09-15 15:25:14 +09:00
Rui Ueyama cae5a93c7e [Mach-O] wip 2021-09-15 12:40:27 +09:00
Rui Ueyama 955f35e977 [Mach-O] wip 2021-09-14 19:45:51 +09:00
Rui Ueyama a504ef9ba7 [Mach-O] wip 2021-09-14 18:45:23 +09:00
Rui Ueyama dcc3cbf1b1 [Mach-O] wip 2021-09-14 17:11:49 +09:00
Rui Ueyama 6aed43b89c [Mach-O] wip 2021-09-14 16:23:03 +09:00
Rui Ueyama 8035024531 [Mach-O] wip 2021-09-14 16:02:41 +09:00
Rui Ueyama 90380ed232 [Mach-O] wip 2021-09-14 15:57:22 +09:00
Rui Ueyama 568bba75c6 [Mach-O] wip 2021-09-14 15:28:28 +09:00
Rui Ueyama f81c869d8f [Mach-O] wip 2021-09-14 15:27:36 +09:00
Rui Ueyama f546e7e696 [Mach-O] wip 2021-09-14 13:12:43 +09:00
Rui Ueyama 730e030994 [Mach-O] wip 2021-09-13 22:40:10 +09:00
Rui Ueyama 2e24055f5c [Mach-O] wip 2021-09-13 21:59:20 +09:00
Rui Ueyama e9caa18ff9 [Mach-O] wip 2021-09-13 21:26:51 +09:00
Rui Ueyama 93bc0cf38a [Mach-O] wip 2021-09-13 20:48:46 +09:00
Rui Ueyama 1fe9055055 [Mach-O] wip 2021-09-13 20:28:06 +09:00
Rui Ueyama 79f2b2bbdc [Mach-O] wip 2021-09-13 19:30:41 +09:00
Rui Ueyama fbc2ea478e [Mach-O] wip 2021-09-13 19:18:04 +09:00
Rui Ueyama 7ffc3a4545 [Mach-O] Add a feature to dump an executable
This is not a linker feature, but in order to learn how Mach-O
executables are constructed, I'll implement a dump feature.
I'll remove the feature once I understand the structure of Mach-O
binaries.
2021-09-13 18:16:13 +09:00
Rui Ueyama e051ad2a9a Do not define _GNU_SOURCE
We should not depend on glibc-specific features.
2021-09-13 17:29:49 +09:00
Rui Ueyama 02b9744d5d Add -g compiler option only when DEBUG=1 2021-09-12 19:42:25 +09:00
Rui Ueyama 08b61f29d2 [ELF] Add --require-defined 2021-09-12 18:34:42 +09:00
Rui Ueyama 1cb750a649 [ELF] Add -Bno-symbolic 2021-09-11 21:41:17 +09:00
Rui Ueyama 730105898b Silence a warning 2021-09-11 14:56:09 +09:00
Rui Ueyama 0a4305f82a Inline a few functions 2021-09-11 14:54:55 +09:00
Rui Ueyama 2e5f480a97 Simplify input file preloading logic 2021-09-10 20:41:20 +09:00
Rui Ueyama 0001cb2818 Simplify 2021-09-10 16:10:28 +09:00
Rui Ueyama 8558a98bf6 Simplify 2021-09-10 16:05:45 +09:00
Rui Ueyama c42bd19c49 Add a missing filename 2021-09-08 20:22:51 +09:00
Rui Ueyama 68ff4a8408 Rename functions 2021-09-08 20:15:03 +09:00
Rui Ueyama dc7e0ca4bf Remove a useless macro 2021-09-08 19:51:02 +09:00
Rui Ueyama 78bddacd5b Move target-independent files to the top directory 2021-09-08 19:49:51 +09:00
Rui Ueyama 8f10ac5047 [Mach-O] Add a test for mach-o stub 2021-09-08 19:19:07 +09:00
Rui Ueyama 5dab8612c8 Move ELF tests to test/elf directory 2021-09-08 19:13:18 +09:00
Rui Ueyama bfa24a3205 Create temporary files for tests under out/ 2021-09-08 19:08:52 +09:00
Rui Ueyama cab0ccf0bd [Mach-O] Add a stub for Mach-O 2021-09-08 19:03:07 +09:00
Rui Ueyama 6cf0a010ec Install mold as ld.mold
This command name is more comsistent with other linkers, i.e.,
ld.bfd, ld.gold and ld.bfd. mold will be a all-in-one linker that
is capable of cross-linking, and it should dispatch according to
argv[0] as follows:

 - mold: a native linker
 - ld or ld.mold: a Unix linker
 - ld64.mold: a macOS linker
 - mold-link: a Windows linker
2021-09-08 17:06:22 +09:00
Rui Ueyama b7be2e6d3b Remove an unused variable 2021-09-08 15:56:45 +09:00
Rui Ueyama aed968ebe6 Fix CI failure 2021-09-07 20:35:26 +09:00
Rui Ueyama 087d4300f2 Create object files in out directory 2021-09-07 20:17:31 +09:00
Rui Ueyama dc672ad821 Bump mold version to 0.9.5 2021-09-06 21:06:34 +09:00
Rui Ueyama b39a47a759 Promote weak undefs to dynamic symbols if building DSO
475a250ad4 changed mold's behavior on
weak undefined symbols, so that if they are not resolved within the
current ELF module, they are resolved to address zero. Previously,
they would be promoted to dynamic symbols to give then another chance
to be resolved at runtime.

That change caused a regression in Firefox. Firefox uses weak undef
symbols as a mean to export symbols from libxul.so. Quote from
Firefox's mfbt/Types.h:

> On linux mozglue is linked in the program and we link libxul.so with
> -z,defs. Normally that causes the linker to reject undefined references in
> libxul.so, but as a loophole it allows undefined references to weak
> symbols. We add the weak attribute to the import version of the MFBT API
> macros to exploit this.

So, they use this as a "loophole".

This change partially revert 475a250ad4.
Now, remaining weak undefs are resolved to address zero only when we
are creating an executable.

Fixes https://github.com/rui314/mold/issues/114
2021-09-06 20:47:16 +09:00
Rui Ueyama c21302e28a Do not use strerror
strerror is not guaranteed to be thread-safe
2021-09-05 17:15:15 +09:00
Rui Ueyama 76018da068 Remove dependency to OpenSSL's RAND_bytes 2021-09-05 17:02:08 +09:00
Rui Ueyama b4953951f0 Remove an unused file 2021-09-03 01:31:33 +09:00
Rui Ueyama 459b5973bb Move code to elf sub-directory 2021-09-02 23:16:49 +09:00
Rui Ueyama 1103b14683 Revert "Remove dependency to openssl/rand.h"
This reverts commit 16d48eae6f.

I don't know why, but that commit broke statically-linked mold.
2021-09-02 23:14:23 +09:00
Rui Ueyama 177dc71335 Move third-party libraries to a separate sub-directory 2021-09-02 22:19:09 +09:00
Rui Ueyama f7a4aceeae Remove an unused file 2021-09-02 22:14:51 +09:00
Rui Ueyama fd391b03ef Move everything into mold::elf namespace 2021-09-02 18:19:43 +09:00
Rui Ueyama 1be5d61bb4 Fix a build issue on macOS 2021-09-01 15:40:11 +09:00
Rui Ueyama 4678fcee52 Fix a build issue on macOS 2021-09-01 15:29:45 +09:00
Rui Ueyama e7537116b3 Fix a build issue on macOS
macOS does not define std::quick_exit.
2021-09-01 14:12:05 +09:00
Rui Ueyama 16d48eae6f Remove dependency to openssl/rand.h 2021-09-01 13:37:11 +09:00
Rui Ueyama 0ce0ceb2c2 Fix a build issue on macOS 2021-09-01 13:26:32 +09:00
Rui Ueyama 0bac54baaa Remove dependency to endian.h
This header file is not there on macOS.
2021-08-31 23:45:38 +09:00
Rui Ueyama d994020807 Add missing include 2021-08-31 23:42:52 +09:00
Rui Ueyama 6a33e7eaa1 Refactor 2021-08-31 17:43:38 +09:00
Rui Ueyama 2a2da35c25 Remove unused declaration 2021-08-30 22:01:49 +09:00
Rui Ueyama b3d0ee093b Report the "recompile with -fPIC' error correctly 2021-08-30 21:07:27 +09:00
Rui Ueyama d3577550d2 Fix filename typo 2021-08-30 20:52:28 +09:00
Rui Ueyama 16c02c2cc3 Refactor 2021-08-30 18:41:27 +09:00
Rui Ueyama 92855aa6ee Refactor 2021-08-30 18:01:27 +09:00
Rui Ueyama e69182d7bc Refactor 2021-08-30 17:32:08 +09:00
Rui Ueyama 4734007ec9 [AArch64] Improve error message 2021-08-30 00:10:43 +09:00
Rui Ueyama ed230a12cc [i386] Add relocation overflow check 2021-08-30 00:05:07 +09:00
Rui Ueyama 0b2584018d Refactor 2021-08-29 23:43:52 +09:00
Rui Ueyama 9501d2cc67 [AArch64] Add relocation overflow check 2021-08-29 21:48:54 +09:00
Rui Ueyama c50dd18881 Fix an issue that local symbols are exported
We sometimes put local symbols into .dynsym, but if they are
global symbols hidden by a version script, they were exported
from .dynsym. This patch correctly makes them local symbols.
2021-08-29 13:04:23 +09:00
Rui Ueyama d06e2f71f3 Attempt to fix CI 2021-08-28 20:47:45 +09:00
Rui Ueyama d43e43adbb Add a test 2021-08-28 14:50:19 +09:00
Rui Ueyama 59c4fc06f3 Fix indentation 2021-08-28 14:37:30 +09:00
Rui Ueyama 5016240d14 Bump mold version to 0.9.4 2021-08-27 18:23:34 +09:00
Rui Ueyama 2032b51dac Use ccache to speed up compilation 2021-08-27 16:59:00 +09:00
Rui Ueyama 06b11da76d Refactor 2021-08-27 16:41:34 +09:00
Rui Ueyama 475a250ad4 Do not promote unresolved weak undefs to dynamic symbols
Previously, we try to promote unresolved weak undefined symbols to
dynamic symbols so that they will get another chance to be resolved at
runtime. This is not always doable. Consider the following two cases:

 - There's a relocation that directly refers a weak undefined symbol

 - There's a relocation that is in a read-only section

In the former case, we need to create a copy relocation, but we can't
do that against a weak undef becasue a weak undef doesn't have the notion
of the symbol size.

In the latter case, we need to create a dynamic relocation, but such
dynamic relocation would fail at load-time when the runtime linker tries
to mutate the contents of a read-only section.

So, we had a logic to detect the above cases and promote weak undefs
only when they can be promoted. But the logic is not as robust as I
hoped. So, in this patch, I removed the logic and stop promoting weak
undefs.
2021-08-27 12:50:23 +09:00
Rui Ueyama b99626fbf2 Refactor 2021-08-25 13:53:09 +00:00
Rui Ueyama 046cdbe724 Simplify 2021-08-25 17:43:57 +09:00
Rui Ueyama 5d53ed9eae Support R_AARCH64_LDST16_ABS_LO12_NC relocation 2021-08-25 08:43:03 +00:00
Rui Ueyama b933cbbae6 Improve Gentoo test script 2021-08-25 08:42:51 +00:00
Rui Ueyama 92616474e4 Fix R_AARCH64_ADR_GOT_PAGE relocation 2021-08-25 07:22:12 +00:00
Rui Ueyama ffb32fe73e Make gentoo-test script work on AArch64 2021-08-25 07:22:02 +00:00
Rui Ueyama e4e618628f Use compare_exchange_weak instead of strong version
I'm not sure if that makes any difference (at least on x86, it doesn't),
but this change is harmless, so I'm making this change.
2021-08-25 04:05:36 +00:00
Rui Ueyama be4f2f52b2 Fix indentation 2021-08-25 12:48:41 +09:00
Rui Ueyama 05ecceb436 Update README 2021-08-25 12:36:16 +09:00
Rui Ueyama 81cb2fab89 Refactor 2021-08-24 10:37:38 +00:00
Rui Ueyama 8bb9fe654e Support R_AARCH64_LDST128_ABS_LO12_NC
With this change, mold can self-host it on ARM64 machines.
2021-08-24 07:08:08 +00:00
Rui Ueyama 684962b84c Support TLSGD relocations for AArch64 2021-08-24 06:29:04 +00:00
Rui Ueyama 75b85b2e8f Remove an unnecessary insn from .plt.got 2021-08-23 12:34:21 +00:00
Rui Ueyama 51705d90c4 Update comment 2021-08-23 20:57:29 +09:00
Rui Ueyama 5912a0022f Fix CI 2021-08-23 18:40:05 +09:00
Rui Ueyama fe9e52b184 Fix CI 2021-08-23 18:32:18 +09:00
Rui Ueyama a4aa3b93cb Fix execle wrapper 2021-08-23 09:21:31 +00:00
Rui Ueyama f0f40d073b Fix tests for AArch64 2021-08-23 09:21:31 +00:00
Rui Ueyama bb1ec6177f Fix TLSDESC relocations against imported symbols
Such relocations shouldn't be relaxed to local-exec, as they are
not local.
2021-08-23 13:38:53 +09:00
Rui Ueyama 7f943d1445 Implement TLSDESC relaxation for AArch64 2021-08-23 03:24:18 +00:00
Rui Ueyama abc2ffc185 Refactor 2021-08-23 11:44:24 +09:00
Rui Ueyama 4c710df347 Fix TLSDESC relocations for statically-linked executables
We shouldn't create TLSDESC dynamic relocations for statically-
linked executables because such executables don't contain the
tranpoline function needed for TLSDESC. Instead, we should
always relax these relocations.
2021-08-22 22:01:38 +09:00
Rui Ueyama 3c79d672dc Implement TLSDESC for AArch64 2021-08-22 11:34:22 +00:00
Rui Ueyama a82bc71088 Fix test/nocopyreloc.sh for AARCH64 2021-08-22 10:33:38 +00:00
Rui Ueyama 96589d4acf Allow to put local symbols to .dynsym
We used to write only global symbols to .dynsym because, in most
use cases, .dynsym are used for resolving inter-module dependencies.
However, we need to put local symbols to .dynsym if they are thread-
local symbols.
2021-08-22 19:28:37 +09:00
Rui Ueyama 771fc02b6d Handle LLVM compiler-rt's .eh_frame symbols 2021-08-21 13:29:41 +09:00
Rui Ueyama f570c4e9e8 Fix tests for AARCH64 2021-08-20 09:48:10 +00:00
Rui Ueyama 2a3639a7d8 Fix tests for AARCH63 2021-08-19 12:31:23 +00:00
Rui Ueyama e4547c31d3 Fix AARCH64 PLT
This patch fixes test/hello-dynamic.sh on ARM64 machines.
2021-08-19 18:45:24 +09:00
Rui Ueyama 91d14191c7 Fix TSAN build issue 2021-08-19 18:45:19 +09:00
Rui Ueyama 34558f410d Do not generate dynrels against RO sections for weak undef symbols
Previously, we created dynamic relocations against read-only sections
if the sections contain relocations against weak undefined symbols.
Since such dynamic relocations cannot be applied at load-time, the
generated executables failed with SEGV.

Now, such relocations are resolved to address 0.

Reported at https://github.com/rui314/mold/pull/110
2021-08-17 17:23:22 +09:00
Rui Ueyama aea7fac8f0 Merge pull request #109 from mqudsi/cmake_unix_makefiles
Explicitly instruct CMake to use Unix Makefiles
2021-08-16 07:34:59 +09:00
Mahmoud Al-Qudsi 4bd77f1d78 Explicitly instruct CMake to use Unix Makefiles
mold currently builds dependencies in its `Makefile` by explicitly
issuing `make -C ...` targeting the CMake build directory; this will
fail if a global `CMAKE_GENERATOR` environment variable is present that
specifies a different CMake build file generator.

Closes #91

Signed-off-by: Mahmoud Al-Qudsi <[email protected]>
2021-08-15 12:27:01 -05:00
Rui Ueyama a46ba486a8 Merge pull request #110 from dylanaraps/fix-cc-cxx
Do not hardcode clang/clang++
2021-08-15 21:23:27 +09:00
Dylan Araps f9336832d4 Do not hardcode clang/clang++
Signed-off-by: Dylan Araps <[email protected]>
2021-08-15 14:51:09 +03:00
Rui Ueyama cc7dc1cf0b Fix build for older versions of CMake
Based on https://github.com/oneapi-src/oneTBB/issues/297#issuecomment-878408577

Fixes https://github.com/rui314/mold/issues/105
2021-08-14 10:18:51 +09:00
Rui Ueyama 631913599e Merge pull request #108 from mqudsi/tbb_no_werror
Disable TBB_STRICT when building TBB (on by default)
2021-08-13 23:00:37 +09:00
Rui Ueyama 184583f1ac Merge pull request #104 from syrusakbary/patch-1
Fix README typos and improved syntax a bit
2021-08-13 22:45:57 +09:00
Mahmoud Al-Qudsi f6c92c2eae Disable TBB_STRICT when building TBB (on by default)
This allows mold to build under clang++-14 which catches the write-only
`intptr_t drained` in `tbb/arena.cpp` as an unused parameter that
ultimately triggers `-Werror` to error out and abort the build.

It's 2021 and there are still projects that default to `-Werror` as the
default instead of using it only in the dev and CI environments... smh.

Closes #107.
2021-08-11 18:39:52 -05:00
Syrus Akbary f448fddd50 Update README.md 2021-08-06 04:16:42 -05:00
Syrus Akbary a44ca755d2 Apply suggestions from code review 2021-08-06 04:15:28 -05:00
Syrus Akbary 3720528354 Fix README typos and improved syntax a bit 2021-08-05 16:55:25 -07:00
Rui Ueyama ef69e9e736 Refactor 2021-08-02 21:51:57 +09:00
Rui Ueyama 31be7ba0d9 Refactor 2021-08-02 21:34:26 +09:00
Rui Ueyama 91428eaa96 Do not dereference sections for undef symbols 2021-08-02 15:41:39 +09:00
Rui Ueyama 05b532af79 Refactor 2021-07-29 20:57:05 +09:00
Rui Ueyama 035aa73c43 Fix CI 2021-07-28 23:40:29 +09:00
Rui Ueyama d25c2553ad Intercept all invocations of ld, ld.gold or ld.lld
Previously, only /usr/bin/ld, /usr/bin/ld.lld and /usr/bin/ld.gold
were intercepted. Now, mold ignores the directory part when comparing
a command name with `ld`, `ld.lld` or `ld.gold`.

This change is made because ld is often installed other than /usr/bin.

Fixes https://github.com/rui314/mold/issues/101
2021-07-28 22:42:35 +09:00
Rui Ueyama 965da0af4a Use hyphen instead of underscore in filename
Test files are following this convention already, but source files weren't.
2021-07-26 21:34:04 +09:00
Rui Ueyama 73d1dcac5d Add a test 2021-07-26 21:32:34 +09:00
Rui Ueyama 2d003c2546 Update issue templates 2021-07-26 20:51:57 +09:00
Rui Ueyama 79787360c6 Fix test
This piece of code is intended to be position-independent,
but it actually directly called printf without PLT.

Fixes https://github.com/rui314/mold/issues/100
2021-07-26 20:17:28 +09:00
Rui Ueyama 6b0d599a31 Fix i386 relocation addends
Fixes https://github.com/rui314/mold/issues/98
2021-07-26 19:32:08 +09:00
Rui Ueyama 0f82b352c7 Compile mold object files as PIE 2021-07-26 16:20:15 +09:00
Rui Ueyama fbdb8367ef Do not add an -I option if not necessary 2021-07-26 16:18:26 +09:00
Rui Ueyama 982544a63d Add a header for linker LTO plugin 2021-07-24 17:29:56 +09:00
Rui Ueyama ec3319b37f Bump mold version to 0.9.3 2021-07-21 19:44:21 +09:00
Rui Ueyama 6fa659c41b Remove an argument from test scripts 2021-07-21 16:27:29 +09:00
Rui Ueyama e4e8535345 Remove CMakeLists.txt
I was experimenting with cmake to see if it is useful for mold,
but it looks like using cmake doesn't make much sense for us.
So I'm undoing all changes that I did for cmake.

cmake is definitely better than autoconf, and it is also useful
if your program is cross-platform. However, neither of the benefits
don't apply to mold; mold doesn't need a complex feature detection,
and it currently supports only ELF-based Unix-like systems.

I think Makefile is a lingua-franca, while CMakeLists.txt isn't.
The good ol' Makefile works just fine for mold.

In the future, mold might become a cross-platform product, and if
that happens, we might want to re-introduce cmake.
2021-07-21 16:27:29 +09:00
Rui Ueyama d1422a03e2 Check if libxxhash exists 2021-07-21 00:02:44 +09:00
Rui Ueyama e13b1180af Make cmake to accept -DMOLD_BUILD_STATIC_EXE flags 2021-07-20 23:22:27 +09:00
Rui Ueyama 33fef23ffb Enable assert() for release builds
Our assert() statements are pretty cheap. We want to enable them
even for release builds.

By default, cmake passes -DNDEBUG to disable assert() for release
builds. So, in this patch, we undefine it to re-enable assertions.
2021-07-20 21:13:03 +09:00
Rui Ueyama 9e78e4a792 Update README 2021-07-20 19:46:45 +09:00
Rui Ueyama 800aba8312 Update README 2021-07-20 15:33:57 +09:00
Rui Ueyama 6254d7def3 Make CI to use cmake instead of make 2021-07-20 14:08:07 +09:00
Rui Ueyama 81ea1d407a Make cmake to accept -DMOLD_USE_SYSTEM_{MIMALLOC,TBB} flags 2021-07-20 13:43:02 +09:00
Rui Ueyama 271c9151f4 Disable tests for mold-wrapper if ASAN is enabled
ASAN doens't work well if other libraries are LD_PRELOAD'ed.
2021-07-20 13:32:02 +09:00
Rui Ueyama 59822bf07e Attempt to fix CI 2021-07-20 00:43:14 +09:00
Rui Ueyama fe26dad744 Fix cmake build
You can now build mold with the following commands:

  $ mkdir -p out/debug
  $ cd out/debug
  $ cmake -GNinja -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Debug ../..
  $ ninja

To run tests, use the following commands:

  $ cd out/debug
  $ ctest -j$(nproc)
2021-07-20 00:33:28 +09:00
Rui Ueyama 4d81fdd4d8 Merge pull request #49 from 3a2l/cmake
Add CMake support
2021-07-20 00:08:57 +09:00
Rui Ueyama 2bf2da4822 Refactor 2021-07-18 20:01:55 +09:00
Rui Ueyama e9c6a08e1e Use more relaxed memory store to flip "is_alive" flag
By default, std::atomic<T>::operator=() stores a given value with
the sequentially-consistent memory ordering, which is a very strong
memory order. We only need the atomicity of store in this case,
so we can use memory_order_relaxed instead.

This change improves performance when we have a lot of section
fragments.

This change shortens the time for garbage collection for clang-13
from 170ms to 100ms.
2021-07-18 14:56:25 +09:00
Rui Ueyama afc1fe6645 Update README 2021-07-17 15:09:16 +09:00
Rui Ueyama c0c2e1409c Merge pull request #95 from tbillington/patch-1
include example of linking rust code
2021-07-17 15:08:36 +09:00
Rui Ueyama bb989791a7 Update .gitignore 2021-07-17 01:24:23 +09:00
Rui Ueyama 04e9aa4ebc Skip i386/aarch64 tests if cross compilers are not available
https://github.com/rui314/mold/issues/89
2021-07-17 01:23:58 +09:00
Trent abb1258ee2 include example of linking rust code 2021-07-16 23:00:12 +10:00
Rui Ueyama c220909e1b Improve Gentoo test script 2021-07-16 16:26:41 +09:00
Rui Ueyama cce1cb353f Fill .rela.dyn even if there's no .got 2021-07-16 15:43:37 +09:00
Rui Ueyama c44fa6172b Recognize yet another crt{begin,end}.o variant
Looks like musl libc sometimes uses crtbeginT.o and crtendT.o.
2021-07-16 15:43:21 +09:00
Rui Ueyama 280892f061 Fix tests for musl 2021-07-16 15:30:54 +09:00
Rui Ueyama bedb2f55f9 Fix header path
"sys/signal.h" happens to work with GNU libc, but the correct path
is "signal.h".
2021-07-16 15:26:21 +09:00
Rui Ueyama dca0e6b7ad Do out-of-tree build for tbb and mimalloc
So that the build directory is less scattered.
2021-07-16 15:10:59 +09:00
Rui Ueyama 1713f6e2f7 Rename oneTBB tbb
"oneTBB" used to be a git submodule, and it is now just a subdirectory.
Using the same directory name makes it difficult to switch between
branches. So I rename it "tbb".
2021-07-16 15:10:59 +09:00
Rui Ueyama 3a7b0525c7 Make it build with musl
musl does not provide makecontext() and swapcontext(), though
they were once in POSIX. They were removed from POSIX.2008 though.
2021-07-16 15:10:59 +09:00
Rui Ueyama 7937360c6a Avoid "PAGE_SIZE" as an identifier
musl libc uses PAGE_SIZE as a macro name, so use other name as
a variable name.
2021-07-16 15:10:59 +09:00
Rui Ueyama fb100f21b3 Do not print out stacktrace on crash
This commit partially reverts e855b90344
because that change was not portable to non-glibc systems.
2021-07-16 14:33:20 +09:00
Rui Ueyama fa543ae350 Attempt to fix a breakage
It looks like 564d7e044ff8a2534a2413d34762dd84be7eaf66 introduced
a concurrency issue.
2021-07-16 14:31:12 +09:00
Rui Ueyama d8ad600b6a Improve MergedSection<E>::assign_offsets()
This patch parallelize MergedSection<E>::assign_offsets().
clang-13 link time is reduced from ~2.5s to ~2.35 with this patch.
2021-07-14 17:11:25 +09:00
Rui Ueyama d79cdb8371 Fix a broken test
Fixes https://github.com/rui314/mold/issues/89
2021-07-13 19:24:26 +09:00
Rui Ueyama 41b2fa7375 Optimize string merging
Linking clang-13 with debug info takes ~3.6 seconds on a simulated
10-core/20-threads machine. mold spends most of its time (~2.3 seconds)
merging string literals in .debug_str. Input .debug_str sections contain
70 million string literals in total, which is reduced to 2 million after
de-duplication. The input object files contain a lot of duplicates.
clang-13 with debug info is enormous -- it is ~3.1 GiB after linking.

It looks like TBB's concurrent hashmap doesn't scale well with the
input.

In this patch, I implemented our own concurrent hashmap. The hashmap
is extremely lightweight and support only the key-value insertion
operation. It doesn't even support rehashing. It aborts once the hash
table becomes full.

In order to know the correct size for the hashmap before inserting
strings into it, I also implemented HyperLogLog algorithm in this patch.
HyperLogLog is an algorithm that gives a fairly accurate estimate on
the number of unique elements.

With this patch, mold can link clang-13 in ~2.5 seconds, which is ~30%
faster than before.

https://github.com/rui314/mold/issues/73
2021-07-13 16:54:09 +09:00
Rui Ueyama 6bb091595e Refactor 2021-07-13 13:13:34 +09:00
Rui Ueyama ecbd3eae14 Merge pull request #87 from Logarithmus/fix-run-sh
Fix test/run.sh for cases when /usr/bin/ld -> /usr/bin/mold
2021-07-12 13:49:39 +09:00
Artur Sinila 5fb7ecbd03 Fix test/run.sh for cases when /usr/bin/ld -> /usr/bin/mold
Signed-off-by: Artur Sinila <[email protected]>
2021-07-12 05:27:21 +03:00
Rui Ueyama e0d44b6678 Use concurrent_unorderd_map for string merging
With high contention rate, it looks like concurrent_unordered_map
outperforms concurrent_hash_map.
2021-07-12 00:02:01 +09:00
Rui Ueyama 3204bb01d9 Fix function pointer equality
Previously, a GOT relocation (e.g. R_X86_64_REX_GOTPCRELX) and a
R_X86_64_64 relocation referring the same imported symbols were
resolved to different addresses. Here is why:

 - When we saw a R_X86_64_64 relocation against an imported symbol,
   we created a PLT and resolve the relocation there.

 - GOT relocation is resolved to a GOT entry, which has a true
   address of an imported function at runtime, which is different
   from PLT entries that redirect calls to the real function.

With this patch, we no longer create a PLT entry for R_X86_64_64.
Instead, we emit a dynamic relocation so that it is always resolved
to a real function address.

Fixes GNU MP's `make check` failure, which was reported at
https://github.com/rui314/mold/issues/81
2021-07-10 17:54:57 +09:00
Rui Ueyama faac31f217 Support VERSION linker script command
The grammar of the command is this

  VERSION { <version-script> }

where <version-script> is a version script you can specify with
the --version-script option.
2021-07-09 23:34:44 +09:00
Rui Ueyama e855b90344 Show stacktrace on SEGV and assertion failure 2021-07-09 23:34:39 +09:00
Rui Ueyama 63b6d30876 Compress .repro section contents
Previously, .repro contains an uncompressed tar file containing all
input files. This patch compresses the contents in the gzip format.
2021-07-09 00:47:15 +09:00
Rui Ueyama 3acb7c8e2f Update README
Pointed out by @pecak.
2021-07-08 17:17:10 +09:00
Rui Ueyama 50b7497e19 Align section header to a E::wordsize boundary
Fixes https://github.com/rui314/mold/issues/80
2021-07-08 15:58:55 +09:00
Rui Ueyama 64913ba610 Merge pull request #77 from Logarithmus/fix-tests
Optimize CI build (enable ccache & run tests in parallel)
2021-07-08 00:43:40 +09:00
Artur Sinila f9a5e9171e ci.yml: enable ccache
Signed-off-by: Artur Sinila <[email protected]>
2021-07-07 18:37:14 +03:00
Artur Sinila 67948ac222 ci.yml: run tests in parallel
Signed-off-by: Artur Sinila <[email protected]>
2021-07-07 18:37:14 +03:00
Rui Ueyama 84d9e4d5ac Fix regexp 2021-07-07 23:12:24 +09:00
Rui Ueyama 72cc07fb42 Merge pull request #83 from nehaljwani/dynsym-IFUNC
Do not replace IFUNC with FUNC in .dynsym
2021-07-07 21:48:15 +09:00
Rui Ueyama 057fffb1dd Optimize regexes 2021-07-07 21:46:23 +09:00
Rui Ueyama 6ae115ac69 Support R_AARCH_ABS{32,64} relocations 2021-07-07 21:06:18 +09:00
Nehal J Wani 1aec54efdb Do not replace IFUNC with FUNC in .dynsym
This is a partial revert of dd04357

Signed-off-by: Nehal J Wani <[email protected]>
2021-07-07 07:59:51 -04:00
Rui Ueyama e3dccd0157 Add a test 2021-07-07 20:38:48 +09:00
Rui Ueyama 048a478bab Merge pull request #82 from nehaljwani/dynsym-visibility
Ensure correct visibility of symbols in .dynsym section
2021-07-07 20:25:33 +09:00
Nehal J Wani 36853d1669 Ensure correct visibility of symbols in .dynsym section
Signed-off-by: Nehal J Wani <[email protected]>
2021-07-07 07:19:10 -04:00
Rui Ueyama 6d6df45a23 Fix definition of __GLOBAL_OFFSET_TABLE__ for AArch64 2021-07-07 12:51:23 +09:00
Rui Ueyama d4a67f6f38 Disable an AArch64 test 2021-07-06 23:06:02 +09:00
Rui Ueyama b9c35e0009 Add R_AARCH64_LD64_GOTPAGE_LO15 2021-07-06 23:00:01 +09:00
Rui Ueyama 4dffb74762 Fix CI 2021-07-06 22:49:51 +09:00
Rui Ueyama ce06ea80ca Fix CI 2021-07-06 22:38:41 +09:00
Rui Ueyama 41497d7990 Support AARCH64 relocations
With this change, mold can now create a "Hello world" program
for the AArch64 target.
2021-07-06 22:24:48 +09:00
Rui Ueyama fc4aafa974 Fix assertion failures
mold failed with `make EXTRA_CPPFLAGS="-Wp,-D_GLIBCXX_ASSERTIONS" test`,
which enables extra assertions.

Thanks for @nehaljwani to find out the flag.
2021-07-06 14:43:06 +09:00
Rui Ueyama d0265554a7 Refactor 2021-07-06 13:39:33 +09:00
Rui Ueyama 713b3a9925 Merge pull request #78 from nehaljwani/oob
Fix out of bound check in get_shndx()
2021-07-06 10:49:41 +09:00
Nehal J Wani b596248a1e Fix out of bound check in get_shndx()
Assert failure:
/usr/include/c++/11.1.0/span:276:
  std::span::reference
  std::span<ElfSym<X86_64>, 18446744073709551615>
     ::operator[](std::span::size_type)
         const [_Type = ElfSym<X86_64>, _Extent = 18446744073709551615]:
           Assertion '__idx < size()' failed.

GDB stacktrace:
Thread 2.4 "mold" received signal SIGABRT, Aborted.
[Switching to Thread 0x7fabc3d3f640 (LWP 17804)]
0x00007fabc496fd22 in raise () from /usr/lib/libc.so.6
(gdb) bt
 #0  0x00007fabc496fd22 in raise () from /usr/lib/libc.so.6
 #1  0x00007fabc4959862 in abort () from /usr/lib/libc.so.6
 #2  0x000055a9685eb018 in std::__replacement_assert (...)
     at /usr/include/c++/11.1.0/x86_64-pc-linux-gnu/bits/c++config.h:504
 #3  0x000055a968614c47 in std::span<ElfSym<X86_64>, ...>::operator[] (...)
     at /usr/include/c++/11.1.0/span:276
 #4  ObjectFile<X86_64>::get_shndx (this=<...>, esym=...) at ./mold.h:2145
 #5  ObjectFile<X86_64>::get_section (this=<...>, esym=...) at ./mold.h:2154

Signed-off-by: Nehal J Wani <[email protected]>
2021-07-05 18:02:27 -04:00
Rui Ueyama 426a689d22 Fix i386 relocation handling 2021-07-05 14:00:16 +09:00
Rui Ueyama b721514f98 Rename a variable 2021-07-05 14:00:16 +09:00
Rui Ueyama 4282ef24cd Merge pull request #76 from Logarithmus/cache
.gitignore: add .cache & compile_commands.json (for clangd)
2021-07-05 10:15:08 +09:00
Artur Sinila 7bbfaac67a .gitignore: add .cache & compile_commands.json (for clangd)
Signed-off-by: Artur Sinila <[email protected]>
2021-07-04 21:09:51 +03:00
Rui Ueyama 11f7653daf Refactor 2021-07-04 21:01:39 +09:00
Rui Ueyama 19d29f25f2 Merge pull request #71 from nehaljwani/gcc-ci
[CI] Test code with GCC 11.1.0
2021-07-04 13:26:40 +09:00
Nehal J Wani 32dff0b877 [CI] Test code with GCC 11.1.0
Signed-off-by: Nehal J Wani <[email protected]>
2021-07-03 23:51:39 -04:00
Rui Ueyama f3a7f86abb Merge pull request #75 from nehaljwani/fix-spare-dynamic-tags-test
[tests] Improve test for -spare-dynamic-tags
2021-07-04 12:45:33 +09:00
Nehal J Wani be6d443bc8 [tests] Improve test for -spare-dynamic-tags
The default size and offsets of the .dynamic section are not necessarily
same with different builds of clang. For example, some builds can make
clang pass --hash-style=gnu to the linker and some --hash-style=both.

This change updates the test to compute the difference in size of the
.dynamic section before and after using the flag -spare-dynamic-tags,
making it independent of the compiler build.

Signed-off-by: Nehal J Wani <[email protected]>
2021-07-03 22:35:42 -04:00
Rui Ueyama 70d1acd744 Fix CI 2021-07-03 21:53:28 +09:00
Rui Ueyama 30ecba45c6 Update README 2021-07-03 21:48:18 +09:00
Rui Ueyama accf96877f Add a stub for AArch64
It can generate an executable, but generated executable won't run
correctly because we don't process relocations at all yet.
2021-07-03 21:39:44 +09:00
Rui Ueyama d502b6ec60 Initial AARCH64 support 2021-07-03 20:48:38 +09:00
Rui Ueyama 546df46eaf Define AARCH64 type and other constants for ARM64 2021-07-03 19:58:46 +09:00
Rui Ueyama fe3af50fb8 Fix comment 2021-07-03 18:32:43 +09:00
Rui Ueyama 6935272033 Create $PREFIX/bin if not exists 2021-07-03 15:07:26 +09:00
Rui Ueyama 3c992c02ea Merge pull request #72 from nehaljwani/fix-pie-test
[tests] Fix pie test when cc isn't built with --enable-default-pie
2021-07-03 14:30:05 +09:00
Rui Ueyama 4c4bfca20e Make make clean to remove artifacts of vendored repos 2021-07-03 14:29:01 +09:00
Rui Ueyama 2abca8b5c1 Fix tests for non-Ubuntu-20 systems
Fixes https://github.com/rui314/mold/issues/67
2021-07-03 14:26:38 +09:00
Rui Ueyama 662e8aa60a Support R_386_TLS_IE relocation 2021-07-03 14:14:50 +09:00
Nehal J Wani 3208ceaac6 [tests] Fix pie test when cc isn't built with --enable-default-pie
mold: /__w/mold/mold/test/tmp/pie/a.o:(.text): R_X86_64_32 relocation
       against symbol `.rodata' can not be used; recompile with -fPIE
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Signed-off-by: Nehal J Wani <[email protected]>
2021-07-03 01:05:28 -04:00
Rui Ueyama c278c66e16 Merge pull request #70 from nehaljwani/gcc-11-fix
Fix compilation error with GCC 11
2021-07-03 12:52:21 +09:00
Nehal J Wani a48eee9179 Fix compilation error with GCC 11
mold.h:128:19: error: explicit specialization of
  ‘template<class Key> class tbb::detail::d1::tbb_hash_compare’
  outside its namespace must use a nested-name-specifier [-fpermissive]
  128 | template<> struct tbb_hash_compare<std::string_view> {
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Nehal J Wani <[email protected]>
2021-07-02 23:40:16 -04:00
Rui Ueyama 475fad3a78 Allow sysroot to be a relative path
Chromium cannot be built with out this patch.
2021-07-03 12:02:32 +09:00
Rui Ueyama 4749764e3e Merge pull request #68 from nehaljwani/tbb-only
[oneTBB] build only required target(s)
2021-07-03 01:43:44 +09:00
Nehal J Wani 9c541ad461 [oneTBB] build only required target(s)
The 'all' target builds tbbmalloc and tbbmalloc_proxy
which mold does not care about.

Signed-off-by: Nehal J Wani <[email protected]>
2021-07-02 12:38:26 -04:00
Rui Ueyama 2f681babf5 Do not attempt to call dlopen
Without this change, statically-linked mold executable crashes
on startup.
2021-07-03 00:08:47 +09:00
Rui Ueyama 3e3d58b6f1 Static-link oneTBB by default
oneTBB API is changing rapidly, so even if a oneTBB is installed
into a system already, it is likely that that is not a compatible
version with mold. This makes program building unnecessarily hard.

This change intends to solve the problem once and for all by
including oneTBB as a subdirectory and static-link against it at
build-time.

oneTBB is released under the Apache License 2.0, which is compatible
with AGPL. Therefore, we can still distribute the binary of mold
under AGPL.

If you do not want to static-link oneTBB, pass `SYSTEM_TBB=1`
to `make`.

This change also ports mold from oneTBB v2020.3 to v2021.3.0.

Fixes https://github.com/rui314/mold/issues/66
2021-07-03 00:08:33 +09:00
Rui Ueyama a32c81f94c Merge commit 'c3c791efcb97384ae25bbdd8a165bbc7473598a8' as 'oneTBB' 2021-07-03 00:01:04 +09:00
Rui Ueyama c3c791efcb Squashed 'oneTBB/' content from commit 261fe226
git-subtree-dir: oneTBB
git-subtree-split: 261fe22630bd61ec137b66f6dd4403ad7ab36a14
2021-07-03 00:01:04 +09:00
Rui Ueyama d19c7dbafc Do not ignore oneTBB directory 2021-07-03 00:00:41 +09:00
Rui Ueyama 29a7d06dd4 Fix race condition 2021-07-01 23:10:00 +09:00
Rui Ueyama cd55d22611 Merge pull request #64 from Logarithmus/fix-makefile
Makefile: add $(DESTDIR) to strip
2021-07-01 20:29:37 +09:00
Artur Sinila 5c846496a2 Makefile: add $(DESTDIR) to strip 2021-07-01 13:05:43 +03:00
Rui Ueyama 0fd62ce693 Fix sysroot handling
Fix https://github.com/rui314/mold/issues/59
2021-07-01 17:40:45 +09:00
Rui Ueyama 18156f3965 Do not set a variable instead of undefine it later 2021-07-01 10:38:30 +09:00
Rui Ueyama 4efc795520 Merge pull request #62 from Logarithmus/fix-makefile
Various fixes in Makefile
2021-07-01 10:05:14 +09:00
Rui Ueyama 9abfeee0e3 Split a function and add tests 2021-07-01 10:00:08 +09:00
Rui Ueyama 44bdbbb164 Merge pull request #61 from johejo/fix_dso_detection
Fix DSO detection for installed with PREFIX
2021-07-01 09:39:11 +09:00
Rui Ueyama b044ac844c Merge pull request #63 from Logarithmus/readme-gcc-guide
README.md: add guide to using mold with GCC via -B option
2021-07-01 09:38:34 +09:00
Rui Ueyama 34a75dee02 Update README
I recommend users use the latest release instead of git HEAD
because HEAD may be broken in a subtle way. Before a release,
I build all Gentoo packages using mold, but I don't do that for
every commit because it takes ~2 days.
2021-07-01 09:28:35 +09:00
Artur Sinila da619e8615 Various fixes in Makefile
Signed-off-by: Artur Sinila <[email protected]>
2021-06-30 20:53:49 +03:00
Artur Sinila aa7d0f5cca README.md: add guide to using mold with GCC via -B option
Signed-off-by: Artur Sinila <[email protected]>
2021-06-30 20:46:26 +03:00
Mitsuo Heijo b6e97e5fb5 Fix DSO detection for installed with PREFIX
Signed-off-by: Mitsuo Heijo <[email protected]>
2021-07-01 01:48:39 +09:00
Rui Ueyama 6432114e2a Fix handling of --sysroot
Fixes https://github.com/rui314/mold/issues/59
2021-06-30 22:15:19 +09:00
Rui Ueyama a89df30537 Merge pull request #57 from nehaljwani/mimalloc-static-only
[mimalloc] build only required target(s)
2021-06-30 08:18:32 +09:00
Nehal J Wani a1073e69b0 [mimalloc] build only required target(s)
The 'all' target builds the shared library as well as test binaries
which mold doesn't care about

Signed-off-by: Nehal J Wani <[email protected]>
2021-06-29 16:34:46 -04:00
Ahmed Hesham 93845d6a2c Add a CMakeLists.txt file.
This uses CMake to fetch the dependencies without using Git submodules.

Signed-off-by: Ahmed Hesham <[email protected]>
2021-06-07 00:28:17 +01:00
3069 changed files with 732523 additions and 44702 deletions

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
# These are supported funding model platforms
github: [rui314] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
+10
View File
@@ -0,0 +1,10 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---
Delete this message and describe the bug here. Note that we only fix bugs in the most recent release of mold, so please make sure that you are using the most recent version.
+51
View File
@@ -0,0 +1,51 @@
name: Build all tarballs
on:
schedule:
- cron: '0 0 * * *'
release:
types: [ published ]
workflow_dispatch:
jobs:
build-tarballs:
strategy:
matrix:
include:
- { target: x86_64, os: ubuntu-24.04 }
- { target: aarch64, os: ubuntu-24.04-arm }
- { target: arm, os: ubuntu-24.04-arm }
- { target: riscv64, os: ubuntu-24.04 }
- { target: ppc64le, os: ubuntu-24.04 }
- { target: s390x, os: ubuntu-24.04 }
- { target: loongarch64, os: ubuntu-24.04 }
runs-on: ${{ matrix.os }}
permissions:
contents: read
packages: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install Podman
run: sudo apt-get update && sudo apt-get install -y podman qemu-user-static
- name: Login to GitHub Container Registry
uses: redhat-actions/podman-login@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build a tarball
run: ./dist.sh ${{ matrix.target }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: dist/mold-*.tar.gz
compression-level: 0
+44
View File
@@ -0,0 +1,44 @@
name: Build native tarballs
on:
push:
workflow_dispatch:
jobs:
build-tarballs:
strategy:
matrix:
include:
- { target: x86_64, os: ubuntu-24.04 }
- { target: aarch64, os: ubuntu-24.04-arm }
- { target: arm, os: ubuntu-24.04-arm }
runs-on: ${{ matrix.os }}
permissions:
contents: read
packages: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install Podman
run: sudo apt-get update && sudo apt-get install -y podman qemu-user-static
- name: Login to GitHub Container Registry
uses: redhat-actions/podman-login@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build a tarball
run: ./dist.sh ${{ matrix.target }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: dist/mold-*.tar.gz
compression-level: 0
+143 -11
View File
@@ -1,17 +1,149 @@
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
UBSAN_OPTIONS: print_stacktrace=1:halt_on_error=1
jobs:
build:
runs-on: ubuntu-20.04
build-sanitizers:
strategy:
matrix:
target:
- ''
- '-DMOLD_USE_ASAN=On'
- '-DMOLD_USE_TSAN=On'
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v2
- name: apt-get
run: sudo dpkg --add-architecture i386 && sudo apt-get update && sudo apt-get install build-essential libstdc++-10-dev cmake clang libssl-dev zlib1g-dev libxxhash-dev libtbb-dev git dwarfdump libc6-dev:i386 lib32gcc-10-dev gcc-multilib
- name: make
run: make -j$(nproc)
- name: make test
run: make test
- uses: actions/checkout@v4
- uses: rui314/setup-mold@staging
- run: sudo ./install-build-deps.sh
- name: build
run: |
sudo apt-get install -y clang-18 clang gcc-multilib gdb dwarfdump zstd
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang-18 -DCMAKE_CXX_COMPILER=clang++-18 ${{ matrix.target }} ..
cmake --build . -j$(nproc)
- run: cd build; ctest --output-on-failure -j$(nproc)
- name: archive test results
uses: actions/upload-artifact@v4
if: failure()
with:
name: test-results-clang
path: |
build
!build/CMakeFiles
build-multi-archs:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: install-build-deps
run: |
sudo ./install-build-deps.sh
sudo ./install-cross-tools.sh
sudo .github/workflows/install-extras.sh
- name: build
run: |
mkdir build
cd build
cmake ..
cmake --build . -j$(nproc)
- run: cd build; ctest --output-on-failure -j$(nproc)
- name: archive test results
uses: actions/upload-artifact@v4
if: failure()
with:
name: test-results-multi-archs
path: |
build
!build/CMakeFiles
build-distros:
strategy:
matrix:
distro:
- alpine
- archlinux
- debian:11 # GCC 10 and CMake 3.18 - the minimum supported by mold
- fedora
- gentoo/stage3
- opensuse/tumbleweed
- ubuntu:22.04
- ubuntu:25.04
runs-on: ubuntu-latest
container: ${{ matrix.distro }}
steps:
- uses: actions/checkout@v4
- run: ./install-build-deps.sh
- name: build
run: |
mkdir build
cd build
cmake ..
cmake --build . -j$(nproc)
- run: cd build; ctest --output-on-failure -j$(nproc)
- name: archive test results
uses: actions/upload-artifact@v4
if: failure()
with:
name: test-results-${{ matrix.distro }}
path: |
build
!build/CMakeFiles
build-macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: build
run: |
mkdir build
cd build
cmake ..
cmake --build . -j$(sysctl -n hw.physicalcpu)
build-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: build
run: |
mkdir build
cd build
cmake -T clangcl ..
cmake --build . -j $Env:NUMBER_OF_PROCESSORS
build-msys:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: UCRT64
update: true
pacboy: gcc-libs:p libwinpthread-git:p tbb:p zlib:p zstd:p dlfcn:p cc:p cmake:p ninja:p
- name: build
shell: msys2 {0}
run: |
mkdir build
cd build
cmake -GNinja -DMOLD_USE_MIMALLOC=OFF -DMOLD_USE_SYSTEM_TBB=ON ..
cmake --build . -j $(nproc)
build-freebsd:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build and test
uses: vmactions/freebsd-vm@v1
with:
usesh: true
run: |
./install-build-deps.sh
mkdir build
cd build
cmake ..
cmake --build . -j$(nproc)
ctest --output-on-failure -j$(nproc)
+61
View File
@@ -0,0 +1,61 @@
#!/bin/bash -x
apt-get update
apt-get install -y wget xz-utils
# Install a 32-bit RISC-V toolchain
mkdir /rv32
wget -O- -q https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/2025.01.20/riscv32-glibc-ubuntu-22.04-gcc-nightly-2025.01.20-nightly.tar.xz | tar -C /rv32 --strip-components=1 --xz -xf -
ln -sf /rv32/sysroot /usr/riscv32-linux-gnu
echo '/rv32/bin/riscv32-unknown-linux-gnu-gcc -L/usr/riscv32-linux-gnu "$@"' > /usr/bin/riscv32-linux-gnu-gcc
echo '/rv32/bin/riscv32-unknown-linux-gnu-g++ -L/usr/riscv32-linux-gnu "$@"' > /usr/bin/riscv32-linux-gnu-g++
chmod 755 /usr/bin/riscv32-linux-gnu-{gcc,g++}
for i in objdump objcopy strip; do
ln -sf /rv32/bin/riscv32-unknown-linux-gnu-$i /usr/bin/riscv32-linux-gnu-$i
done
# Install a LoongArch toolchain
mkdir /larch
wget -O- -q https://github.com/loongson/build-tools/releases/download/2025.02.21/x86_64-cross-tools-loongarch64-binutils_2.44-gcc_14.2.0-glibc_2.41.tar.xz | tar -C /larch --strip-components=1 --xz -xf -
cp -r /larch/loongarch64-unknown-linux-gnu/lib/* /larch/target/lib64
ln -sf /larch/target /usr/loongarch64-linux-gnu
for i in gcc g++ objdump objcopy strip; do
ln -sf /larch/bin/loongarch64-unknown-linux-gnu-$i /usr/bin/loongarch64-linux-gnu-$i
done
wget -O /usr/local/bin/qemu-loongarch64 -q https://github.com/loongson/build-tools/releases/download/2024.11.01/qemu-loongarch64
chmod 755 /usr/local/bin/qemu-loongarch64
# Install ARM64 big-endian toolchain
mkdir /aarch64be
wget -O- -q https://sources.buildroot.net/toolchain-external-arm-aarch64-be/arm-gnu-toolchain-13.3.rel1-x86_64-aarch64_be-none-linux-gnu.tar.xz | tar -C /aarch64be --strip-components=1 --xz -xf -
ln -sf /aarch64be/aarch64_be-none-linux-gnu/libc /usr/aarch64_be-linux-gnu
echo '/aarch64be/bin/aarch64_be-none-linux-gnu-gcc -L/usr/aarch64_be-linux-gnu "$@"' > /usr/bin/aarch64_be-linux-gnu-gcc
echo '/aarch64be/bin/aarch64_be-none-linux-gnu-g++ -L/usr/aarch64_be-linux-gnu "$@"' > /usr/bin/aarch64_be-linux-gnu-g++
chmod 755 /usr/bin/aarch64_be-linux-gnu-{gcc,g++}
for i in objdump objcopy strip; do
ln -sf /aarch64be/bin/aarch64_be-none-linux-gnu-$i /usr/bin/aarch64_be-linux-gnu-$i
done
# Install SH4 big-endian toolchain
mkdir /sh4aeb
wget -O- -q https://toolchains.bootlin.com/downloads/releases/toolchains/sh-sh4aeb/tarballs/sh-sh4aeb--glibc--stable-2024.05-1.tar.xz | tar -C /sh4aeb --strip-components=1 --xz -xf -
ln -sf /sh4aeb/sh4aeb-buildroot-linux-gnu/sysroot /usr/sh4aeb-linux-gnu
echo '/sh4aeb/bin/sh4aeb-linux-gcc -L/usr/sh4aeb-linux-gnu "$@"' > /usr/bin/sh4aeb-linux-gnu-gcc
echo '/sh4aeb/bin/sh4aeb-linux-g++ -L/usr/sh4aeb-linux-gnu "$@"' > /usr/bin/sh4aeb-linux-gnu-g++
chmod 755 /usr/bin/sh4aeb-linux-gnu-{gcc,g++}
for i in objdump objcopy strip; do
ln -sf /sh4aeb/bin/sh4aeb-linux-$i /usr/bin/sh4aeb-linux-gnu-$i
done
# Install Intel SDE CPU emulator for CET-related tests
mkdir /sde
wget -O- -q https://downloadmirror.intel.com/843185/sde-external-9.48.0-2024-11-25-lin.tar.xz | tar -C /sde --strip-components=1 --xz -xf -
ln -s /sde/sde64 /usr/bin
+33
View File
@@ -0,0 +1,33 @@
name: Update manpage
on:
push:
paths:
- 'docs/mold.md'
branches:
- main
workflow_dispatch:
jobs:
update-manpage:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Install ronn
run: sudo apt-get update && sudo apt-get install -y ronn
- name: Generate mold.1 from mold.md
run: ronn --roff docs/mold.md
- name: Configure Git
run: |
git config --global user.name 'Rui Ueyama'
git config --global user.email '[email protected]'
- name: Commit and push if mold.1 is updated
run: |
git add docs/mold.1
git diff --staged --quiet || (git commit -m "Update mold.1 (automated commit)" && git push)
+6 -5
View File
@@ -1,10 +1,11 @@
*.o
*.so
*~
/mold
/test/tmp
options.inc
**/.DS_Store
.cache
core
ld
oneTBB
gentoo
/mold-*.tar.gz
/build*
/mold
/dist
+458
View File
@@ -0,0 +1,458 @@
# You can customize a build by specifying CMake options. An option may be
# given in the -Dvariable=value form. For a boolean variable, `ON` or `1`
# means true, while `OFF` or `0` means false.
#
# Here are a couple of common cmake options:
#
# -DCMAKE_C_COMPILER=<command-name>
#
# Specifies the C compiler name to use. The default value is `cc`.
#
# -DCMAKE_CXX_COMPILER=<command-name>
#
# Specifies the C++ compiler name to use. The default value is `c++`.
#
# -DCMAKE_INSTALL_PREFIX=<directory>
#
# Specifies the install target directory. The default value is `/usr/local`.
#
# -DCMAKE_BUILD_TYPE=[Debug | Release | RelWithDebInfo | MinSizeRel]
#
# Specifies the build type. The default is `Release`, which is the right
# option unless you are debugging mold.
#
# An example of a cmake command line is shown below:
#
# $ cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_CXX_COMPILER=g++-12 ..
#
# where `..` refers to this directory.
#
# With cmake, you may run `cmake --install .` instead of `make install` to
# install build artifacts to system directories. If you want to install
# artifacts to a temporary target directory, run `cmake --install . --prefix
# <dir>`.
#
# You can see the current cmake variables and their values by running
# `cmake -N -L .` in a build directory.
#
# Note that in this file, we provide various dials and knobs to configure
# how to build mold. However, as a policy, we do not provide a way to
# enable/disable any individual mold's feature. In other words, we do not
# provide options like `--enable-foo` or `--disable-foo`. The motivation
# behind this is build reproducibility. We want to guarantee that all builds
# of the mold linker of the same version will have the exact same set of
# features and behave exactly the same.
cmake_minimum_required(VERSION 3.14)
project(mold VERSION 2.37.1)
include(CMakeDependentOption)
include(CheckSymbolExists)
include(GNUInstallDirs)
add_executable(mold)
target_compile_features(mold PRIVATE cxx_std_20)
if(MINGW)
target_link_libraries(mold PRIVATE dl)
else()
target_link_libraries(mold PRIVATE ${CMAKE_DL_LIBS})
endif()
# Build mold itself using mold if -DMOLD_USE_MOLD=ON
option(MOLD_USE_MOLD "Use mold to build mold" OFF)
if(MOLD_USE_MOLD)
target_link_options(mold PRIVATE -fuse-ld=mold -Wl,--gdb-index)
if(CMAKE_BUILD_TYPE MATCHES "^Rel")
target_link_options(mold PRIVATE -Wl,--gc-sections,--icf=safe)
endif()
endif()
if(NOT "${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC")
target_compile_options(mold PRIVATE
-fno-exceptions
-fno-unwind-tables
-fno-asynchronous-unwind-tables
-ffunction-sections
-fdata-sections
-Wall
-Wextra
-Wno-sign-compare
-Wno-unused-function
-Wno-unused-parameter
-Wno-missing-field-initializers
-ggnu-pubnames)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_options(mold PRIVATE -D_GLIBCXX_ASSERTIONS)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
set(OPENBSD ON)
endif()
# Build mold with -flto if -DMOLD_LTO=ON
option(MOLD_LTO "Build mold with link-time optimization enabled")
if(MOLD_LTO)
set_property(TARGET mold PROPERTY INTERPROCEDURAL_OPTIMIZATION ON)
endif()
# Enable AddressSanitizer if -DMOLD_USE_ASAN=ON
option(MOLD_USE_ASAN "Build mold with AddressSanitizer" OFF)
if(MOLD_USE_ASAN)
target_compile_options(mold PRIVATE -fsanitize=address -fsanitize=undefined)
target_link_options(mold PRIVATE -fsanitize=address -fsanitize=undefined)
endif()
# Enabled ThreadSanitizer if -DMOLD_USE_TSAN=ON
option(MOLD_USE_TSAN "Build mold with ThreadSanitizer" OFF)
if(MOLD_USE_TSAN)
target_compile_options(mold PRIVATE -fsanitize=thread)
target_link_options(mold PRIVATE -fsanitize=thread)
endif()
# Statically-link libstdc++ if -DMOLD_MOSTLY_STATIC=ON.
#
# This option is intended to be used by `./dist.sh` script to create a
# mold binary that works on various Linux distros. You probably don't
# need nor want to set this to ON.
option(MOLD_MOSTLY_STATIC "Statically link libstdc++ and some other libraries" OFF)
if(MOLD_MOSTLY_STATIC)
target_link_options(mold PRIVATE -static-libstdc++)
endif()
# Find zlib. If libz.so is not found, we compile a bundled one and
# statically-link it to mold.
find_package(ZLIB QUIET)
if(ZLIB_FOUND AND NOT MOLD_MOSTLY_STATIC)
target_link_libraries(mold PRIVATE ZLIB::ZLIB)
else()
set(ZLIB_BUILD_EXAMPLES OFF CACHE INTERNAL "")
add_subdirectory(third-party/zlib EXCLUDE_FROM_ALL)
target_include_directories(zlibstatic INTERFACE third-party/zlib
$<TARGET_PROPERTY:zlibstatic,BINARY_DIR>)
target_link_libraries(mold PRIVATE zlibstatic)
endif()
# Find BLAKE3 cryptographic hash library. Just like zlib, if libblkae3.so
# is not found, we compile a bundled one and statically-link it to mold.
find_package(BLAKE3 QUIET)
if(BLAKE3_FOUND AND NOT MOLD_MOSTLY_STATIC)
target_link_libraries(mold PRIVATE BLAKE3::blake3)
else()
function(mold_add_blake3)
set(BUILD_SHARED_LIBS OFF)
add_subdirectory(third-party/blake3/c EXCLUDE_FROM_ALL)
target_link_libraries(mold PRIVATE blake3)
target_include_directories(mold PUBLIC third-party/blake3/c)
endfunction()
mold_add_blake3()
endif()
# Find zstd compression library. If zstd.h is not found, we compile a
# bundled one and statically-link it to mold.
include(CheckIncludeFile)
check_include_file(zstd.h HAVE_ZSTD_H)
if(HAVE_ZSTD_H AND NOT MOLD_MOSTLY_STATIC)
target_link_libraries(mold PRIVATE zstd)
else()
add_subdirectory(third-party/zstd/build/cmake EXCLUDE_FROM_ALL)
target_compile_definitions(libzstd_static PRIVATE
ZSTD_BUILD_STATIC=1
ZSTD_BUILD_SHARED=0
ZSTD_BUILD_PROGRAMS=0
ZSTD_MULTITHREAD_SUPPORT=0
ZSTD_BUILD_TESTS=0)
target_include_directories(mold PUBLIC third-party/zstd/lib)
target_link_libraries(mold PRIVATE libzstd_static)
endif()
# Find mimalloc. mimalloc is an alternative malloc implementation
# optimized for multi-threaded applications.
#
# If you want to use the usual libc's malloc, pass -DMOLD_USE_MIMALLOC=OFF.
#
# We enable mimalloc by default for 64-bit targets. It doesn't seem to
# be stable on 32-bit targets.
cmake_dependent_option(
MOLD_USE_MIMALLOC "Use mimalloc" ON
"CMAKE_SIZEOF_VOID_P EQUAL 8; NOT APPLE; NOT ANDROID; NOT OPENBSD; NOT MOLD_USE_ASAN; NOT MOLD_USE_TSAN" OFF)
cmake_dependent_option(
MOLD_USE_SYSTEM_MIMALLOC "Use system or vendored mimalloc" OFF
MOLD_USE_MIMALLOC OFF)
# By default, we build a bundled mimalloc and statically-link it to
# mold. If you want to dynamically link to the system's
# libmimalloc.so, pass -DMOLD_USE_SYSTEM_MIMALLOC=ON.
if(MOLD_USE_MIMALLOC)
if(MOLD_USE_SYSTEM_MIMALLOC)
find_package(mimalloc REQUIRED)
target_link_libraries(mold PRIVATE mimalloc)
else()
function(mold_add_mimalloc)
set(MI_BUILD_STATIC ON CACHE INTERNAL "")
set(MI_BUILD_TESTS OFF CACHE INTERNAL "")
add_subdirectory(third-party/mimalloc EXCLUDE_FROM_ALL)
target_compile_definitions(mimalloc-static PRIVATE MI_USE_ENVIRON=0)
target_link_libraries(mold PRIVATE mimalloc-static)
endfunction()
mold_add_mimalloc()
endif()
endif()
# Find TBB. TBB (OneTBB or Intel TBB) is a high-level threading library.
# Use of this library is mandatory.
#
# By default, we build a bundled one and statically-link the library
# to mold. If you want to link to the system's libtbb2.so, pass
# -DMOLD_USE_SYSTEM_TBB=ON.
option(MOLD_USE_SYSTEM_TBB "Use system or vendored TBB" OFF)
if(MOLD_USE_SYSTEM_TBB)
find_package(TBB REQUIRED)
target_link_libraries(mold PRIVATE TBB::tbb)
else()
function(mold_add_tbb)
set(BUILD_SHARED_LIBS OFF)
set(TBB_TEST OFF CACHE INTERNAL "")
set(TBB_STRICT OFF CACHE INTERNAL "")
add_subdirectory(third-party/tbb EXCLUDE_FROM_ALL)
target_compile_definitions(tbb PRIVATE __TBB_DYNAMIC_LOAD_ENABLED=0)
target_link_libraries(mold PRIVATE TBB::tbb)
endfunction()
mold_add_tbb()
endif()
# We always use Clang to build mold on Windows. MSVC can't compile mold.
if(WIN32)
if(MSVC AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message(FATAL_ERROR
"Your compiler is not supported; install Clang from Visual Studio Installer and re-run cmake with '-T clangcl'")
endif()
target_compile_definitions(mold PRIVATE NOGDI NOMINMAX)
if(MINGW)
target_compile_definitions(mold PRIVATE _WIN32_WINNT=0xA00)
target_link_libraries(mold PRIVATE bcrypt)
endif()
else()
include(CheckLibraryExists)
check_library_exists(m pow "" LIBM_FOUND)
if(LIBM_FOUND)
target_link_libraries(mold PRIVATE m)
endif()
endif()
# Build mold-wrapper.so
if(NOT APPLE AND NOT WIN32)
add_library(mold-wrapper SHARED)
install(TARGETS mold-wrapper DESTINATION ${CMAKE_INSTALL_LIBDIR}/mold)
# Remove the default `lib` prefix
set_target_properties(mold-wrapper PROPERTIES PREFIX "")
target_link_libraries(mold-wrapper PRIVATE ${CMAKE_DL_LIBS})
target_sources(mold-wrapper PRIVATE src/mold-wrapper.c)
endif()
# If atomics doesn't work by default, add -latomic.
# We need the flag on riscv, armv6 and m68k.
include(CheckCXXSourceCompiles)
check_cxx_source_compiles("#include <atomic>
int main() {
std::atomic_uint8_t a;
std::atomic_uint16_t b;
std::atomic_uint32_t c;
std::atomic_uint64_t d;
return ++a + ++b + ++c + ++d;
}" HAVE_FULL_ATOMIC_SUPPORT)
if(NOT HAVE_FULL_ATOMIC_SUPPORT)
target_link_libraries(mold PRIVATE atomic)
endif()
# Add -pthread
if(NOT APPLE AND NOT MSVC)
target_compile_options(mold PRIVATE -pthread)
target_link_options(mold PRIVATE -pthread)
endif()
check_symbol_exists(madvise sys/mman.h HAVE_MADVISE)
check_symbol_exists(uname sys/utsname.h HAVE_UNAME)
# Create a .cc file containing the current git hash for `mold --version`.
add_custom_target(git_hash
COMMAND ${CMAKE_COMMAND}
-DSOURCE_DIR=${CMAKE_SOURCE_DIR}
-DOUTPUT_FILE=${CMAKE_BINARY_DIR}/git-hash.cc
-P ${CMAKE_SOURCE_DIR}/lib/update-git-hash.cmake
DEPENDS lib/update-git-hash.cmake
BYPRODUCTS git-hash.cc
VERBATIM)
add_dependencies(mold git_hash)
# Create config.h file
configure_file(lib/config.h.in config.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
# Almost all functions are template in mold which take a target type
# (e.g. X86_64) as its type parameter. Since we suport more than 10
# targets, compiling a single source file for all the targets is very
# slow.
#
# As a workaround, we create a .cc file for each target and spawn many
# compiler instances. This is hacky but greatly reduces compile time
# on a multicore machine.
list(APPEND MOLD_ELF_TARGETS
X86_64 I386 ARM64LE ARM64BE ARM32 RV32LE RV32BE RV64LE RV64BE PPC32
PPC64V1 PPC64V2 S390X SPARC64 M68K SH4LE SH4BE LOONGARCH32 LOONGARCH64 ARC)
list(APPEND MOLD_ELF_TEMPLATE_FILES
src/arch-arm64.cc
src/arch-loongarch.cc
src/arch-riscv.cc
src/arch-sh4.cc
src/cmdline.cc
src/filetype.cc
src/gc-sections.cc
src/gdb-index.cc
src/icf.cc
src/input-files.cc
src/input-sections.cc
src/linker-script.cc
src/main.cc
src/mapfile.cc
src/output-chunks.cc
src/passes.cc
src/relocatable.cc
src/shrink-sections.cc
src/thunks.cc
src/tls.cc
)
if(WIN32 AND NOT MINGW)
list(APPEND MOLD_ELF_TEMPLATE_FILES src/lto-win32.cc)
else()
list(APPEND MOLD_ELF_TEMPLATE_FILES src/lto-unix.cc)
endif()
if(WIN32)
list(APPEND MOLD_ELF_TEMPLATE_FILES
src/output-file-win32.cc
src/subprocess-win32.cc
)
else()
list(APPEND MOLD_ELF_TEMPLATE_FILES
src/output-file-unix.cc
src/subprocess-unix.cc
)
endif()
function(mold_instantiate_templates SOURCE TARGET)
set(PATH ${CMAKE_BINARY_DIR}/${SOURCE}.${TARGET}.cc)
if(NOT EXISTS ${PATH})
file(WRITE ${PATH} "#define MOLD_${TARGET} 1
#define MOLD_TARGET ${TARGET}
#include \"${CMAKE_SOURCE_DIR}/${SOURCE}\"
")
endif()
target_sources(mold PRIVATE ${PATH})
endfunction()
foreach (SOURCE IN LISTS MOLD_ELF_TEMPLATE_FILES)
foreach(TARGET IN LISTS MOLD_ELF_TARGETS)
mold_instantiate_templates(${SOURCE} ${TARGET})
endforeach()
endforeach()
# Add other non-template source files.
target_sources(mold PRIVATE
git-hash.cc
lib/compress.cc
lib/crc32.cc
lib/demangle.cc
lib/filepath.cc
lib/glob.cc
lib/hyperloglog.cc
lib/mimalloc.cc
lib/multi-glob.cc
lib/perf.cc
lib/random.cc
lib/tar.cc
src/arch-arc.cc
src/arch-arm32.cc
src/arch-i386.cc
src/arch-m68k.cc
src/arch-ppc32.cc
src/arch-ppc64v1.cc
src/arch-ppc64v2.cc
src/arch-s390x.cc
src/arch-sparc64.cc
src/arch-x86-64.cc
src/config.cc
src/elf.cc
third-party/rust-demangle/rust-demangle.c
)
if(WIN32)
target_sources(mold PRIVATE
lib/jobs-win32.cc
lib/mapped-file-win32.cc
lib/signal-win32.cc
)
else()
target_sources(mold PRIVATE
lib/jobs-unix.cc
lib/mapped-file-unix.cc
lib/signal-unix.cc
)
endif()
include(CTest)
if(BUILD_TESTING)
# Create the ld symlinks required for testing
if(NOT WIN32)
add_custom_command(
TARGET mold POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink mold ld
BYPRODUCTS ld
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM)
endif()
if(${UNIX})
add_subdirectory(test)
endif()
endif()
if(NOT CMAKE_SKIP_INSTALL_RULES)
install(TARGETS mold RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES docs/mold.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1/)
install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
function(mold_install_relative_symlink OLD NEW)
install(CODE "
get_filename_component(PREFIX_ABS \${CMAKE_INSTALL_PREFIX}/ ABSOLUTE)
get_filename_component(OLD_ABS ${OLD} ABSOLUTE BASE_DIR \${PREFIX_ABS})
get_filename_component(NEW_ABS ${NEW} ABSOLUTE BASE_DIR \${PREFIX_ABS})
get_filename_component(NEW_DIR \${NEW_ABS} DIRECTORY)
file(RELATIVE_PATH OLD_REL \${NEW_DIR} \${OLD_ABS})
message(STATUS \"Installing symlink: \$ENV{DESTDIR}\${NEW_ABS} -> \${OLD_REL}\")
file(MAKE_DIRECTORY \$ENV{DESTDIR}\${NEW_DIR})
file(CREATE_LINK \${OLD_REL} \$ENV{DESTDIR}\${NEW_ABS} SYMBOLIC)")
endfunction()
mold_install_relative_symlink(${CMAKE_INSTALL_BINDIR}/mold${CMAKE_EXECUTABLE_SUFFIX}
${CMAKE_INSTALL_LIBEXECDIR}/mold/ld${CMAKE_EXECUTABLE_SUFFIX})
mold_install_relative_symlink(${CMAKE_INSTALL_BINDIR}/mold${CMAKE_EXECUTABLE_SUFFIX}
${CMAKE_INSTALL_BINDIR}/ld.mold${CMAKE_EXECUTABLE_SUFFIX})
mold_install_relative_symlink(${CMAKE_INSTALL_MANDIR}/man1/mold.1
${CMAKE_INSTALL_MANDIR}/man1/ld.mold.1)
endif()
-54
View File
@@ -1,54 +0,0 @@
# Contributing to mold
Summary: When you send a patch, you must agree that the patch is
released under the dual license of the GNU AGPLv3 and the MIT license.
As an indication of agreement, please add a `Signed-off-by` line to
your commit message using `git commit -s`.
Here is the long official version:
mold is currently licensed under the GNU AGPLv3, but I want to relicense
it under a more liberal license in the future. To make this possible,
I want all patches to be submitted under the dual license of the GNU
AGPLv3 and the MIT license (the "Dual License") from the beginning.
To make it clear that contributors have agreed to release their
patches under the Dual License, I introduced a sign-off procedure just
like the Linux kernel project did. The sign-off is a simple line at
the end of the git commit message, which certifies that you wrote it
or otherwise have the right to pass it on as an open-source patch. The
rules are pretty simple: if you can certify the below:
> ## Developer's Certificate of Origin
>
> By making a contribution to this project, I certify that:
>
> 1. The contribution was created in whole or in part by me and I
> have the right to submit it under the Dual License; or
>
> 2. The contribution is based upon previous work that, to the best
> of my knowledge, is covered under the the Dual License and I
> have the right under the Dual License to submit that work with
> modifications, whether created in whole or in part by me, under
> the Dual License (unless I am permitted to submit under
> different licenses), as indicated in the file; or
>
> 3. The contribution was provided directly to me by some other
> person who certified (1), (2) or (3) and I have not modified it.
>
> 4. I understand and agree that this project and the contribution
> are public and that a record of the contribution (including all
> personal information I submit with it, including my sign-off) is
> maintained indefinitely and may be redistributed consistent with
> this project or the open source license(s) involved.
then you just add a line saying:
```
Signed-off-by: Random J Developer <[email protected]>
```
using your real name (sorry, no pseudonyms or anonymous contributions.)
This will be done for you automatically if you use ``git commit -s``.
Reverts should also include "Signed-off-by". ``git revert -s`` does that
for you.
+21 -671
View File
@@ -1,671 +1,21 @@
Note: I'm looking for a sponsor who wants to purchase the copyright
of this work and relicense it under a more liberal license such as
the MIT license. For now, mold is released under the GNU AGPL v3.
If you just want to use mold but do not want to use AGPL software
in your organization, a commercial license is available. Please
contact [email protected].
--
GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU Affero General Public License is a free, copyleft license for
software and other kinds of works, specifically designed to ensure
cooperation with the community in the case of network server software.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
our General Public Licenses are intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
Developers that use our General Public Licenses protect your rights
with two steps: (1) assert copyright on the software, and (2) offer
you this License which gives you legal permission to copy, distribute
and/or modify the software.
A secondary benefit of defending all users' freedom is that
improvements made in alternate versions of the program, if they
receive widespread use, become available for other developers to
incorporate. Many developers of free software are heartened and
encouraged by the resulting cooperation. However, in the case of
software used on network servers, this result may fail to come about.
The GNU General Public License permits making a modified version and
letting the public access it on a server without ever releasing its
source code to the public.
The GNU Affero General Public License is designed specifically to
ensure that, in such cases, the modified source code becomes available
to the community. It requires the operator of a network server to
provide the source code of the modified version running there to the
users of that server. Therefore, public use of a modified version, on
a publicly accessible server, gives the public access to the source
code of the modified version.
An older license, called the Affero General Public License and
published by Affero, was designed to accomplish similar goals. This is
a different license, not a version of the Affero GPL, but Affero has
released a new version of the Affero GPL which permits relicensing under
this license.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU Affero General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Remote Network Interaction; Use with the GNU General Public License.
Notwithstanding any other provision of this License, if you modify the
Program, your modified version must prominently offer all users
interacting with it remotely through a computer network (if your version
supports such interaction) an opportunity to receive the Corresponding
Source of your version by providing access to the Corresponding Source
from a network server at no charge, through some standard or customary
means of facilitating copying of software. This Corresponding Source
shall include the Corresponding Source for any work covered by version 3
of the GNU General Public License that is incorporated pursuant to the
following paragraph.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the work with which it is combined will remain governed by version
3 of the GNU General Public License.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU Affero General Public License from time to time. Such new versions
will be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU Affero General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU Affero General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU Affero General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If your software can interact with users remotely through a computer
network, you should also make sure that it provides a way for users to
get its source. For example, if your program is a web application, its
interface could display a "Source" link that leads users to an archive
of the code. There are many ways you could offer source, and different
solutions will be better for different programs; see section 13 for the
specific requirements.
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU AGPL, see
<https://www.gnu.org/licenses/>.
MIT License
Copyright (c) 2023 Rui Ueyama
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-89
View File
@@ -1,89 +0,0 @@
CC = clang
CXX = clang++
MIMALLOC_LIB = mimalloc/out/release/libmimalloc.a
GIT_HASH = $(shell [ -d .git ] && git rev-parse HEAD)
CPPFLAGS = -g -Imimalloc/include -pthread -std=c++20 \
-Wno-deprecated-volatile \
-DMOLD_VERSION=\"0.9.1\" \
-DGIT_HASH=\"$(GIT_HASH)\" \
$(EXTRA_CPPFLAGS)
LDFLAGS = $(EXTRA_LDFLAGS)
LIBS = -Wl,-as-needed -lcrypto -pthread -ltbb -lz -lxxhash -ldl
OBJS = main.o object_file.o input_sections.o output_chunks.o \
mapfile.o perf.o linker_script.o archive_file.o output_file.o \
subprocess.o gc_sections.o icf.o symbols.o cmdline.o filepath.o \
passes.o tar.o compress.o memory_mapped_file.o relocatable.o \
arch_x86_64.o arch_i386.o
PREFIX ?= /usr
DEBUG ?= 0
LTO ?= 0
ASAN ?= 0
TSAN ?= 0
ifeq ($(DEBUG), 1)
CPPFLAGS += -O0
else
CPPFLAGS += -O2
endif
ifeq ($(LTO), 1)
CPPFLAGS += -flto -O3
LDFLAGS += -flto
endif
ifeq ($(ASAN), 1)
CPPFLAGS += -fsanitize=address
LDFLAGS += -fsanitize=address
else
# By default, we want to use mimalloc as a memory allocator.
# Since replacing the standard malloc is not compatible with ASAN,
# we do that only when ASAN is not enabled.
LDFLAGS += -Wl,-whole-archive $(MIMALLOC_LIB) -Wl,-no-whole-archive
endif
ifeq ($(TSAN), 1)
CPPFLAGS += -fsanitize=thread
LDFLAGS += -fsanitize=thread
endif
all: mold mold-wrapper.so
mold: $(OBJS) $(MIMALLOC_LIB)
$(CXX) $(CFLAGS) $(OBJS) -o $@ $(LDFLAGS) $(LIBS)
mold-wrapper.so: mold-wrapper.c Makefile
$(CC) -fPIC -shared -o $@ $< -ldl
$(OBJS): mold.h elf.h Makefile
$(MIMALLOC_LIB):
mkdir -p mimalloc/out/release
(cd mimalloc/out/release; CFLAGS=-DMI_USE_ENVIRON=0 cmake ../..)
$(MAKE) -C mimalloc/out/release
test tests check: all
$(MAKE) -C test --output-sync --no-print-directory
install: all
install -m 755 mold $(PREFIX)/bin
strip $(PREFIX)/bin/mold
install -m 755 -d $(PREFIX)/lib/mold
install -m 644 mold-wrapper.so $(PREFIX)/lib/mold
strip $(PREFIX)/lib/mold/mold-wrapper.so
install -m 644 docs/mold.1 $(PREFIX)/share/man/man1
rm -f $(PREFIX)/share/man/man1/mold.1.gz
gzip -9 $(PREFIX)/share/man/man1/mold.1
uninstall:
rm -rf $(PREFIX)/bin/mold $(PREFIX)/share/man/man1/mold.1.gz \
$(PREFIX)/lib/mold
clean:
rm -rf *.o *~ mold mold-wrapper.so test/tmp
.PHONY: all test tests check clean $(TESTS)
+216 -562
View File
@@ -1,115 +1,205 @@
# mold: A Modern Linker
![mold image](docs/mold.jpg)
mold is a faster drop-in replacement for existing Unix linkers. It is several
times quicker than the LLVM lld linker, the second-fastest open-source linker,
which I initially developed a few years ago. mold aims to enhance developer
productivity by minimizing build time, particularly in rapid
debug-edit-rebuild cycles.
mold is a high performance drop-in replacement for existing Unix
linkers. It is several times faster than LLVM lld linker, the (then-)
fastest open-source linker which I originally created a few years ago.
Here is a performance comparison of GNU gold, LLVM lld and mold for
linking final executables of major large programs.
Here is a performance comparison of GNU ld, GNU gold, LLVM lld, and
mold when linking final debuginfo-enabled executables for major large
programs on a simulated 16-core, 32-thread machine.
| Program (linker output size) | GNU gold | LLVM lld | mold | mold w/ preloading
|-------------------------------|----------|----------|-------|-------------------
| Firefox 87 (1.6 GiB) | 29.2s | 6.16s | 1.69s | 0.79s
| Chrome 86 (1.9 GiB) | 54.5s | 11.7s | 1.85s | 0.97s
| Clang 13 (3.1 GiB) | 59.4s | 5.68s | 2.76s | 0.86s
![Link speed comparison](docs/chart.svg)
(These nubmers are measured on an AMD Threadripper 3990X 64-core
machine with 32 threads enabled. All programs are built with debug
info enabled.)
| Program (linker output size) | GNU ld | GNU gold | LLVM lld | mold
|-------------------------------|--------|----------|----------|------
| MySQL 8.3 (0.47 GiB) | 10.84s | 7.47s | 1.64s | 0.46s
| Clang 19 (1.56 GiB) | 42.07s | 33.13s | 5.20s | 1.35s
| Chromium 124 (1.35 GiB) | N/A | 27.40s | 6.10s | 1.52s
Let me explain the "w/ preloading" column. mold supports the file
preloading feature. That is, if you run mold with `-preload` flag
along with other command line flags, it becomes a daemon and halts
after parsing input files. Then, if you invoke mold with the same
command line options (except `-preload` flag), it tells the daemon to
reload only updated files and proceed. With this feature enabled, and
if most of the input files haven't been updated, mold achieve a
near-`cp` performance or even exceeds it, as the throughput of file
copy using the `cp` command is about 2 GiB/s on my machine.
mold is so fast that it is only 2x _slower_ than the `cp` command on the same
machine. If you find that mold is not faster than other linkers, feel
free to [file a bug report](https://github.com/rui314/mold/issues).
So, mold is extremely fast per-se and even faster with a bit of cheating.
mold supports x86-64, i386, ARM64, ARM32, 64-bit/32-bit little/big-endian
RISC-V, 32-bit PowerPC, 64-bit big-endian PowerPC ELFv1, 64-bit little-endian
PowerPC ELFv2, s390x, 64-bit/32-bit LoongArch, SPARC64, m68k, and SH-4.
Why is mold so fast? One reason is because it simply uses faster
algorithms and efficient data structures than other linkers do.
The other reason is that the new linker is highly parallelized.
## Why does linking speed matter?
Here is a side-by-side comparison of per-core CPU usage of lld (left)
and mold (right). They are linking the same program, Chromium
executable.
If you are using a compiled language such as C, C++, or Rust, a build consists
of two phases. In the first phase, a compiler compiles source files into
object files (`.o` files). In the second phase, a linker takes all object
files and combines them into a single executable or shared library file.
![](docs/htop.gif)
The second phase can be time-consuming if your build output is large. mold can
speed up this process, saving you time and preventing distractions while
waiting for a lengthy build to finish. The difference is most noticeable
during rapid debug-edit-rebuild cycles.
As you can see, mold uses all available cores throughout its execution
and finishes quickly. On the other hand, lld failed to use available
cores most of the time. On this demo, the maximum parallelism is
artificially capped to 16 so that the bars fit in the GIF.
## Installation
Currently, mold is being developed with Linux/x86-64 as the primary
target platform. mold can link many user-land programs including large
ones such as web browsers for that target. It also has preliminary
Linux/i386 support. Supporting other OSes and ISAs are planned after
Linux/x86-64 support is complete.
Binary packages for the following systems are currently available:
## How to build
[![Packaging status](https://repology.org/badge/vertical-allrepos/mold.svg)](https://repology.org/project/mold/versions)
mold is written in C++20, so you need a very recent version of GCC or
Clang. I'm using Ubuntu 20.04 as a development platform. In that
environment, you can build mold by the following commands.
## How to Build
```
$ sudo apt-get install build-essential libstdc++-10-dev cmake clang libssl-dev zlib1g-dev libxxhash-dev libtbb-dev git
$ git clone https://github.com/rui314/mold.git
$ cd mold
$ make
mold is written in C++20, so if you build mold yourself, you will need a
recent version of a C++ compiler and a C++ standard library. We recommend GCC
10.2 or Clang 12.0.0 (or later) and libstdc++ 10 or libc++ 7 (or later).
### Install Dependencies
To install build dependencies, run `./install-build-deps.sh` in this
directory. It will detect your Linux distribution and attempt to install the
necessary packages. You may need to run it as root.
### Compile mold
```shell
git clone --branch stable https://github.com/rui314/mold.git
cd mold
./install-build-deps.sh
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=c++ -B build
cmake --build build -j$(nproc)
sudo cmake --build build --target install
```
The last `make` command creates `mold` executable.
You might need to pass a C++20 compiler command name to `cmake`. In the
example above, `c++` is passed. If that doesn't work for you, try a specific
version of a compiler, such as `g++-10` or `clang++-12`.
If you don't have Ubuntu 20.04, or if for any reason `make` in the
above commands doesn't work for you, you can use Docker to build it in
a Docker environment. To do so, just run `./build-static.sh` in this
directory. The script creates a Ubuntu 20.04 Docker image, install
necessary tools and libraries to it and build mold as a static binary.
By default, `mold` is installed to `/usr/local/bin`. You can change the
installation location by passing `-DCMAKE_INSTALL_PREFIX=<directory>`.
For other cmake options, see the comments in `CMakeLists.txt`.
`make test` depends on a few more packages. To install, run the following commands:
```
$ sudo dpkg --add-architecture i386
$ sudo apt-get install dwarfdump libc6-dev:i386 lib32gcc-10-dev gcc-multilib
```
If you are not using a recent enough Linux distribution, or if `cmake` does
not work for you for any reason, you can use Podman to build mold in a
container. To do so, run `./dist.sh` in this directory instead of using
`cmake`. The shell script will pull a container image, build mold and auxiliary
files inside it, and package them into a single tar file named
`dist/mold-$version-$arch-linux.tar.gz`. You can extract the tar file anywhere
and use the mold executable in it.
## How to use
On Unix, the linker command (which is usually `/usr/bin/ld`) is
invoked indirectly by `cc` (or `gcc` or `clang`), which is typically
in turn indirectly invoked by `make` or some other build system
command. It is sometimes very hard to pass an appropriate command line
option to `cc` to specify an alternative linker.
<details><summary>A classic way to use mold</summary>
To deal with the situation, mold has a feature to intercept all
invocations of `/usr/bin/ld`, `/usr/bin/ld.lld` or `/usr/bin/ld.gold`
and redirect it to itself. To use the feature, run `make` (or other
build command) as a subcommand of mold as follows:
On Unix, the linker command (usually `/usr/bin/ld`) is indirectly invoked by
the compiler driver (typically `cc`, `gcc`, or `clang`), which is in turn
indirectly invoked by `make` or other build system commands.
```
$ path/to/mold -run make <make-options-if-any>
If you can specify an additional command line option for your compiler driver
by modifying the build system's config files, add one of the following flags
to use mold instead of `/usr/bin/ld`:
- For Clang: pass `-fuse-ld=mold`
- For GCC 12.1.0 or later: pass `-fuse-ld=mold`
- For GCC before 12.1.0: the `-fuse-ld` option does not accept `mold` as a
valid argument, so you need to use the `-B` option instead. The `-B` option
tells GCC where to look for external commands like `ld`.
If you have installed mold with `make install`, there should be a directory
named `/usr/libexec/mold` (or `/usr/local/libexec/mold`, depending on your
`$PREFIX`), and the `ld` command should be there. The `ld` is actually a
symlink to `mold`. So, all you need is to pass `-B/usr/libexec/mold` (or
`-B/usr/local/libexec/mold`) to GCC.
If you haven't installed `ld.mold` to any `$PATH`, you can still pass
`-fuse-ld=/absolute/path/to/mold` to clang to use mold. However, GCC does not
accept an absolute path as an argument for `-fuse-ld`.
</details>
<details><summary>If you are using Rust</summary>
Create `.cargo/config.toml` in your project directory with the following:
```toml
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=/path/to/mold"]
```
Internally, mold invokes a given command with `LD_PRELOAD` environment
variable set to its companion shared object file. The shared object
file intercepts all function calls to exec-family functions to replace
`argv[0]` with `mold` if it is `/usr/bin/ld`, `/usr/bin/ld.gold` or
`/usr/bin/ld.lld`.
where `/path/to/mold` is an absolute path to the mold executable. In the
example above, we use `clang` as a linker driver since it always accepts the
`-fuse-ld` option. If your GCC is recent enough to recognize the option, you
may be able to remove the `linker = "clang"` line.
Alternatively, you can pass `-fuse-ld=<absolute-path-to-mold-executable>`
to a linker command line. Since GCC doesn't support that option,
I recommend using clang.
```toml
[target.x86_64-unknown-linux-gnu]
rustflags = ["-C", "link-arg=-fuse-ld=mold"]
```
mold leaves its identification string in `.comment` section in an output
If you want to use mold for all projects, add the above snippet to
`~/.cargo/config.toml`.
</details>
<details><summary>If you are using Nim</summary>
Create `config.nims` in your project directory with the following:
```nim
when findExe("mold").len > 0 and defined(linux):
switch("passL", "-fuse-ld=mold")
```
where `mold` must be included in the `PATH` environment variable. In this
example, `gcc` is used as the linker driver. Use the `-fuse-ld` option if your
GCC is recent enough to recognize this option.
If you want to use mold for all projects, add the above snippet to
`~/.config/config.nims`.
</details>
<details><summary>If you are using Conan package manager</summary>
You can configure [Conan](https://github.com/conan-io) to download the latest
version of `mold` and use it as the linker when building your dependencies and
projects from source. Please see the instructions [here](https://conan.io/center/recipes/mold).
</details>
<details><summary>mold -run</summary>
It is sometimes very hard to pass an appropriate command line option to `cc`
to specify an alternative linker. To address this situation, mold has a
feature to intercept all invocations of `ld`, `ld.bfd`, `ld.lld`, or `ld.gold`
and redirect them to itself. To use this feature, run `make` (or another build
command) as a subcommand of mold as follows:
```shell
mold -run make <make-options-if-any>
```
Internally, mold invokes a given command with the `LD_PRELOAD` environment
variable set to its companion shared object file. The shared object file
intercepts all function calls to `exec(3)`-family functions to replace
`argv[0]` with `mold` if it is `ld`, `ld.bf`, `ld.gold`, or `ld.lld`.
</details>
<details><summary>GitHub Actions</summary>
You can use our [setup-mold](https://github.com/rui314/setup-mold) GitHub
Action to speed up GitHub-hosted continuous builds. Although GitHub Actions
run on a 4 core machine, mold is still significantly faster than the default
GNU linker, especially when linking large programs.
</details>
<details><summary>Verify that you are using mold</summary>
mold leaves its identification string in the `.comment` section of an output
file. You can print it out to verify that you are actually using mold.
```
```shell
$ readelf -p .comment <executable-file>
String dump of section '.comment':
@@ -117,505 +207,69 @@ String dump of section '.comment':
[ 2b] mold 9a1679b47d9b22012ec7dfbda97c8983956716f7
```
If `mold` is in `.comment`, the file is created by mold.
If `mold` is present in the `.comment` section, the file was created by mold.
# Design and implementation of mold
</details>
For the rest of this documentation, I'll explain the design and the
implementation of mold. If you are only interested in using mold, you
don't need to read the below.
<details><summary>Online manual</summary>
## Motivation
Since mold is a drop-in replacement, you should be able to use it without
reading its manual. However, if you need it, [mold's man page](docs/mold.md)
is available online. You can read the same manual by running `man mold`.
Here is why I'm writing a new linker:
</details>
- Even though lld has significantly improved the situation, linking is
still one of the slowest steps in a build. It is especially
annoying when I changed one line of code and had to wait for a few
seconds or even more for a linker to complete. It should be
instantaneous. There's a need for a faster linker.
## Why is mold so fast?
- The number of cores on a PC has increased a lot lately, and this
trend is expected to continue. However, the existing linkers can't
take the advantage of the trend because they don't scale well for more
cores. I have a 64-core/128-thread machine, so my goal is to create
a linker that uses the CPU nicely. mold should be much faster than
other linkers on 4 or 8-core machines too, though.
One reason is that it utilizes faster algorithms and more efficient data
structures compared to other linkers. Another reason is that mold is highly
parallelized.
- It looks to me that the designs of the existing linkers are somewhat
too similar, and I believe there are a lot of drastically different
designs that haven't been explored yet. Developers generally don't
care about linkers as long as they work correctly, and they don't
even think about creating a new one. So there may be lots of low
hanging fruits there in this area.
Here is a side-by-side comparison of per-core CPU usage for lld (left) and
mold (right), linking the same program, a Chromium executable.
## Basic design
![CPU usage comparison in htop animation](docs/htop.gif)
- In order to achieve a `cp`-like performance, the most important
thing is to fix the layout of an output file as quickly as possible, so
that we can start copying actual data from input object files to an
output file as soon as possible.
As you can see, mold uses all available cores throughout its execution and
finishes quickly. In contrast, lld fails to utilize available cores most of
the time. In this demo, the maximum parallelism is artificially capped at 16,
so that the bars fit in the GIF.
- Copying data from input files to an output file is I/O-bounded, so
there should be room for doing computationally-intensive tasks while
copying data from one file to another.
For details, please see the [design notes](docs/design.md).
- We should allow the linker to preload object files from disk and
parse them in memory before a complete set of input object files
is ready. To do so, we need
to split the linker into two in such a way that the latter half of
the process finishes as quickly as possible by speculatively parsing
and preprocessing input files in the first half of the process.
## Sponsors
- One of the most computationally-intensive stage among linker stages
is symbol resolution. To resolve symbols, we basically have to throw
all symbol strings into a hash table to match undefined symbols with
defined symbols. But this can be done in the preloading stage using
[string interning](https://en.wikipedia.org/wiki/String_interning).
It is taken for granted nowadays that compiler toolchains can be easily
installed and used for free, and people may not think too much about the
individuals behind these "free tools". mold supports many projects, but it
is essentially a one-person project. This situation is similar to the one
depicted in the following xkcd illustration.
- Object files may contain a special section called a mergeable string
section. The section contains lots of null-terminated strings, and
the linker is expected to gather all mergeable string sections and
merge their contents. So, if two object files contain the same
string literal, for example, the resulting output will contain a
single merged string. This step is computationally-intensive, but string
merging can be done in the preloading stage using string interning.
[![xkcd 2347](https://imgs.xkcd.com/comics/dependency.png)](https://xkcd.com/2347)
- Static archives (.a files) contain object files, but the static
archive's string table contains only defined symbols of member
object files and lacks other types of symbols. That makes static
archives unsuitable for speculative parsing. Therefore, the linker
should ignore the symbol table of static archive and directly read
static archive members.
If you think that the "Nebraska guy" should be rewarded, please consider
becoming our [GitHub sponsor](https://github.com/sponsors/rui314)!
- If there's a relocation that uses a GOT of a symbol, then we have to
create a GOT entry for that symbol. Otherwise, we shouldn't. That
means we need to scan all relocation tables to fix the length and
the contents of a .got section. This is computationally intensive,
but this step is parallelizable.
We thank everyone who sponsors our project. In particular, we'd like to acknowledge
the following people and organizations who have sponsored $128/month or more:
## Compatibility
### Corporate sponsors
- GNU ld, GNU gold and LLVM lld support essentially the same set of
command line options and features. mold doesn't have to be
completely compatible with them. As long as it can be used for
linking large user-land programs, I'm fine with that. It is OK to
leave some command line options unimplemented; if mold is blazingly
fast, other projects would still be happy to adopt it by modifying
their projects' build files.
<a href="https://mercury.com"><img src="docs/mercury-logo.png" align=center height=120 width=400 alt=Mercury></a>
- mold emits Linux executables and runs only on Linux. I won't avoid
Unix-ism when writing code. I don't want to think about portability
until mold becomes a thing that's worth to be ported.
<a href="https://cybozu-global.com"><img src="docs/cyboze-logo.png" align=center height=120 width=133 alt=Cybozu></a>
## Linker Script
<a href="https://www.emergetools.com"><img src="docs/emerge-tools-logo.png" align=center height=120 width=240 alt="Emerge Tools"></a><br>
Linker script is an embedded language for the linker. It is mainly
used to control how input sections are mapped to output sections and
the layout of the output, but it can also do a lot of tricky stuff.
Its feature is useful especially for embedded programming, but it's
also an awfully underdocumented and complex language.
- [G-Research](https://www.gresearch.co.uk)
- [Signal Slot Inc.](https://github.com/signal-slot)
- [GlareDB](https://github.com/GlareDB)
We have to implement a subset of the linker script language anwyay,
because on Linux, /usr/lib/x86_64-linux-gnu/libc.so is (despite its
name) not a shared object file but actually an ASCII file containing
linker script code to load the _actual_ libc.so file. But the feature
set for this purpose is very limited, and it is okay to implement them
to mold.
### Individual sponsors
Besides that, we really don't want to implement the linker script
langauge. But at the same time, we want to satisfy the user needs that
are currently satisfied with the linker script langauge. So, what
should we do? Here is my observation:
- Linker script allows to do a lot of tricky stuff, such as specifying
the exact layout of a file, inserting arbitrary bytes between
sections, etc. But most of them can be done with a post-link binary
editing tool (such as `objcopy`).
- It looks like there are two things that truely cannot be done by a
post-link editing tool: (a) mapping input sections to output
sections, and (b) applying relocations.
From the above observation, I believe we need to provide only the
following features instead of the entire linker script langauge:
- A method to specify how input sections are mapped to output
sections, and
- a method to set addresses to output sections, so that relocations
are applied based on desired adddresses.
I believe everything else can be done with a post-link binary editing
tool.
## Details
- As we aim to the 1 second goal for Chromium, every millisecond
counts. We can't ignore the latency of process exit. If we mmap a
lot of files, \_exit(2) is not instantaneous but takes a few hundred
milliseconds because the kernel has to clean up a lot of
resources. As a workaround, we should organize the linker command as
two processes; the first process forks the second process, and the
second process does the actual work. As soon as the second process
writes a result file to a filesystem, it notifies the first process,
and the first process exits. The second process can take time to
exit, because it is not an interactive process.
- At least on Linux, it looks like the filesystem's performance to
allocate new blocks to a new file is the limiting factor when
creating a new large file and filling its contents using mmap.
If you already have a large file in the buffer cache, writing to it is
much faster than creating a new fresh file and writing to it.
Based on this observation, mold overwrites to an existing
executable file if exists. My quick benchmark showed that I could
save 300 milliseconds when creating a 2 GiB output file.
Linux doesn't allow to open an executable for writing if it is
running (you'll get "text busy" error if you attempt). mold
falls back to the usual way if it fails to open an output file.
- The output from the linker should be deterministic for the sake of
[build reproducibility](https://en.wikipedia.org/wiki/Reproducible_builds)
and ease of debugging. This might add a little bit of overhead to
the linker, but that shouldn't be too much.
- A .build-id, a unique ID embedded to an output file, is usually
computed by applying a cryptographic hash function (e.g. SHA-1) to
an output file. This is a slow step, but we can speed it up by
splitting a file into small chunks, computing SHA-1 for each chunk,
and then computing SHA-1 of the concatenated SHA-1 hashes
(i.e. constructing a [Markle
Tree](https://en.wikipedia.org/wiki/Merkle_tree) of height 2).
Modern x86 processors have purpose-built instructions for SHA-1 and
can compute SHA-1 pretty quickly at about 2 GiB/s rate. Using 16
cores, a build-id for a 2 GiB executable can be computed in 60 to 70
milliseconds.
- BFD, gold, and lld support section garbage collection. That is, a
linker runs a mark-sweep garbage collection on an input graph, where
sections are vertices and relocations are edges, to discard all
sections that are not reachable from the entry point symbol
(i.e. `_start`) or a few other root sections. In mold, we are using
multiple threads to mark sections concurrently.
- Similarly, BFD, gold an lld support Identical Comdat Folding (ICF)
as a yet another size optimization. ICF merges two or more read-only
sections that happen to have the same contents and relocations.
To do that, we have to find isomorphic subgraphs from larger graphs.
I implemented a new algorithm for mold, which is 5x faster than lld
to do ICF for Chromium (from 5 seconds to 1 second).
- [Intel Threading Building
Blocks](https://github.com/oneapi-src/oneTBB) (TBB) is a good
library for parallel execution and has several concurrent
containers. We are particularly interested in using
`parallel_for_each` and `concurrent_hash_map`.
- TBB provides `tbbmalloc` which works better for multi-threaded
applications than the glib'c malloc, but it looks like
[jemalloc](https://github.com/jemalloc/jemalloc) and
[mimalloc](https://github.com/microsoft/mimalloc) are a little bit
more scalable than `tbbmalloc`.
## Size of the problem
When linking Chrome, a linker reads 3,430,966,844 bytes of data in
total. The data contains the following items:
| Data item | Number
| ------------------------ | ------
| Object files | 30,723
| Public undefined symbols | 1,428,149
| Mergeable strings | 1,579,996
| Comdat groups | 9,914,510
| Regular sections¹ | 10,345,314
| Public defined symbols | 10,512,135
| Symbols | 23,953,607
| Sections | 27,543,225
| Relocations against SHF_ALLOC sections | 39,496,375
| Relocations | 62,024,719
¹ Sections that have to be copied from input object files to an
output file. Sections that contain relocations or symbols are for
example excluded.
## Internals
In this section, I'll explain the internals of mold linker.
### A brief history of Unix and the Unix linker
Conceptually, what a linker does is pretty simple. A compiler compiles
a fragment of a program (a single source file) into a fragment of
machine code and data (an object file, which typically has the .o
extension), and a linker stiches them together into a single
executable or a shared library image.
In reality, modern linkers for Unix-like systems are much more
compilcated than the naive understanding because they have gradually
gained one feature at a time over the 50 years history of Unix, and
they are now something like a bag of lots of miscellaneous features in
which none of the features is more important than the others. It is
very easy to miss the forest for the trees, since for those who don't
know the details of the Unix linker, it is not clear which feature is
essential and which is not.
That being said, one thing is clear that at any point of Unix history,
a Unix linker has a coherent feature set for the Unix of that age. So,
let me entangle the history to see how the operating system, runtime
and linker have gained features that we see today. That should give
you an idea why a particular feature has been added to a linker in the
first place.
1. Original Unix didn't support shared library, and a program was
always loaded to a fixed address. An executable was something like
a memory dump which was just loaded to a particular address by the
kernel. After loading, the kernel started executing the program by
setting the instruction pointer to a particular address.
The most essential feature for any linker is relocation processing.
The original Unix linker of course supported that. Let me explain
what that is.
Individual object files are inevitably incomplete as a program,
because when a compiler created them, it only see a part of an
entire program. For example, if an object file contains a function
call that refers other object file, the `call` instruction in the
object cannot be complete, as the compiler has no idea as to what
is the called function's address. To deal with this, the compiler
emits a placeholder value (typically just zero) instead of a real
address and leave a metadata in an object file saying "fix offset X
of this file with an address of Y". That metadata is called
"relocation". Relocations are typically processed by the linker.
It is easy for a linker to apply relocations for the original Unix
because a program is always loaded to a fixed address. It exactly
knows the addresses of all functions and data when linking a
program.
Static library support, which is still an important feature of Unix
linker, also dates back to this early period of Unix history.
To understand what it is, imagine that you are trying to compile
a program for the early Unix. You don't want to waste time to
compile libc functions every time you compile your program (the
computers of the era was incredibly slow), so you have already
placed each libc function into a separate source file and compiled
them individually. That means, you have object files for each libc
function, e.g., printf.o, scanf.o, atoi.o, write.o, etc.
Given this configuration, all you have to do to link your program
against libc functions is to pick up a right set of libc object
files and give them to the linker along with the object files of your
program. But, keeping the linker command line in sync with the
libc functions you are using in your program is bothersome. You can
be conservative; you can specify all libc object files to the
command line, but that leads to program bloat because the linker
unconditionally link all object files given to it no matter whether
they are used or not. So, a new feature was added to the linker to
fix the problem. That is the static library, which is also called
the archive file.
An archive file is just a bundle of object files, just like zip
file but in an uncompressed form. An achive file typically has the
.a file extension and named after its contents. For example, the
archive file containing all libc objects is named `libc.a`.
If you pass an archive file along with other object files to the
linker, the linker pulls out an object file from the archive _only
when_ it is referenced by other object files. In other words,
unlike object files directly given to a linker, object files
wrapped in an archive are not linked to an output by default.
An archive works as supplements to complete your program.
Even today, you can still find a libc archive file. Run `ar t
/usr/lib/x86_64-linux-gnu/libc.a` on Linux should give you a list
of object files in the libc archive.
2. In '80s, Sun Microsystems, a leading commercial Unix vendor at the
time, added a shared library support to their Unix variant, SunOS.
(This section is incomplete.)
## Concurrency strategy
In this section, I'll explain the high level concurrency strategy of
mold.
In most places, mold adopts data parallelism. That is, we have a huge
number of piece of data of the same kind, and we process each of them
individually using parallel for-loop. For example, after identifying
the exact set of input object files, we need to scan all relocation
tables to determine the sizes of .got and .plt sections. We do that
using a parallel for-loop. The granularity of parallel processing in
this case is the relocation table.
Data parallelism is very efficient and scalable because there's no
need for threads to communicate with each other while working on each
element of data. In addition to that, data parallelism is easy to
understand, as it is just a for-loop in which multiple iterations may
be executed in parallel. We don't use high-level communication or
synchronization mechanisms such as channels, futures, promises,
latches or something like that in mold.
In some cases, we need to share a little bit of data between threads
while executing a parallel for-loop. For example, the loop to scan
relocations turns on "requires GOT" or "requires PLT" flags in a
symbol. Symbol is a shared resource, and writing to them from multiple
threads without synchronization is unsafe. To deal with it, we made
the flag an atomic variable.
The other common pattern you can find in mold which is build on top of
the parallel for-loop is the map-reduce pattern. That is, we run a
parallel for-loop on a large data set to produce a small data set and
process the small data set with a single thread. Let me take a
build-id computation as an example. Build-id is typically computed by
applying a cryptographic hash function such as SHA-1 on a linker's
output file. To compute it, we first consider an output as a sequence
of 1 MiB blocks and compute a SHA-1 hash for each block in parallel.
Then, we concatenate the SHA-1 hashes and compute a SHA-1 hash on the
hashes to get a final build-id.
Finally, we use concurrent hashmap at a few places in mold. Concurrent
hashmap is a hashmap to which multiple threads can safely insert items
in parallel. We use it in the symbol resolution stage, for example.
To resolve symbols, we basically have to throw in all defined symbols
into a hash table, so that we can find a matching defined symbol for
an undefined symbol by name. We do the hash table insertion from a
parallel for-loop which iterates over a list of input files.
Overall, even though mold is highly scalable, it succeeded to avoid
complexties you often find in complex parallel programs. From high
level, mold just serially executes linker's internal passes one by
one. Each pass is parallelized using parallel for-loops.
## Rejected ideas
In this section, I'll explain the alternative designs I currently do
not plan to implement and why I turned them down.
- Placing variable-length sections at end of an output file and start
copying file contents before fixing the output file layout
Idea: Fixing the layout of regular sections seems easy, and if we
place them at beginning of a file, we can start copying their
contents from their input files to an output file. While copying
file contents, we can compute the sizes of variable-length sections
such as .got or .plt and place them at end of the file.
Reason for rejection: I did not choose this design because I doubt
if it could actually shorten link time and I think I don't need it
anyway.
The linker has to de-duplicate comdat sections (i.e. inline
functions that are included into multiple object files), so we
cannot compute the layout of regular sections until we resolve all
symbols and de-duplicate comdats. That takes a few hundred
milliseconds. After that, we can compute the sizes of
variable-length sections in less than 100 milliseconds. It's quite
fast, so it doesn't seem to make much sense to proceed without
fixing the final file layout.
The other reason to reject this idea is because there's good a
chance for this idea to have a negative impact on linker's overall
performance. If we copy file contents before fixing the layout, we
can't apply relocations to them while copying because symbol
addresses are not available yet. If we fix the file layout first, we
can apply relocations while copying, which is effectively zero-cost
due to a very good data locality. On the other hand, if we apply
relocations long after we copy file contents, it's pretty expensive
because section contents are very likely to have been evicted from
CPU cache.
- Incremental linking
Idea: Incremental linking is a technique to patch a previous linker's
output file so that only functions or data that are updated from the
previous build are written to it. It is expected to significantly
reduce the amount of data copied from input files to an output file
and thus speed up linking. GNU BFD and gold linkers support it.
Reason for rejection: I turned it down because it (1) is
complicated, (2) doesn't seem to speed it up that much and (3) has
several practical issues. Let me explain each of them.
First, incremental linking for real C/C++ programs is not as easy as
one might think. Let me take malloc as an example. malloc is usually
defined by libc, but you can implement it in your program, and if
that's the case, the symbol `malloc` will be resolved to your
function instead of the one in libc. If you include a library that
defines malloc (such as libjemalloc or libtbbmallc) before libc,
their malloc will override libc's malloc.
Assume that you are using a nonstandard malloc. What if you remove
your malloc from your code, or remove `-ljemalloc` from your
Makefile? The linker has to include a malloc from libc, which may
include more object files to satisfy its dependencies. Such code
change can affect the entire program rather than just replacing one
function. The same is true to adding malloc to your program. Making
a local change doesn't necessarily result in a local change in the
binary level. It can easily have cascading effects.
Some ELF fancy features make incremental linking even harder to
implement. Take the weak symbol as an example. If you define `atoi`
as a weak symbol in your program, and if you are not using `atoi`
at all in your program, that symbol will be resolved to address
0. But if you start using some libc function that indirectly calls
`atoi`, then `atoi` will be included to your program, and your weak
symbol will be resolved to that function. I don't know how to
efficiently fix up a binary for this case.
This is a hard problem, so existing linkers don't try too hard to
solve it. For example, IIRC, gold falls back to full link if any
function is removed from a previous build. If you want to not annoy
users in the fallback case, you need to make full link fast anyway.
Second, incremental linking itself has an overhead. It has to detect
updated files, patch an existing output file and write additional
data to an output file for future incremental linking. GNU gold, for
instance, takes almost 30 seconds on my machine to do a null
incremental link (i.e. no object files are updated from a previous
build) for chrome. It's just too slow.
Third, there are other practical issues in incremental linking. It's
not reproducible, so your binary isn't going to be the same as other
binaries even if you are compiling the same source tree using the
same compiler toolchain. Or, it is complex and there might be a bug
in it. If something doesn't work correctly, "remove --incremental
from your Makefile and try again" could be a piece of advise, but
that isn't ideal.
So, all in all, incremental linking is tricky. I wanted to make full
link as fast as possible, so that we don't have to think about how
to workaround the slowness of full link.
- Defining a completely new file format and use it
Idea: Sometimes, the ELF file format itself seems to be a limiting
factor of improving linker's performance. We might be able to make a
far better one if we create a new file format.
Reason for rejection: I rejected the idea because it apparently has
a practical issue (backward compatibility issue) and also doesn't
seem to improve performance of linkers that much. As clearly
demonstrated by mold, we can create a fast linker for ELF. I believe
ELF isn't that bad, after all. The semantics of the existing Unix
linkers, such as the name resolution algorithm or the linker script,
have slowed the linkers down, but that's not a problem of the file
format itself.
- Watching object files using inotify(2)
Idea: When mold is running as a daemon for preloading, use
inotify(2) to watch file system updates so that it can reload files
as soon as they are updated.
Reason for rejection: Just like the maximum number of files you can
simultaneously open, the maximum number of files you can watch using
inotify(2) isn't that large. Maybe just a single instance of mold is
fine with inotify(2), but it may fail if you run multiple of it.
The other reason for not doing it is because mold is quite fast
without it anyway. Invoking stat(2) on each file for file update
check takes less than 100 milliseconds for Chrome, and if most of
the input files are not updated, parsing updated files takes almost
no time.
- [Wei Wu](https://github.com/lazyparser)
- [kyle-elliott](https://github.com/kyle-elliott)
- [Bryant Biggs](https://github.com/bryantbiggs)
- [kraptor23](https://github.com/kraptor23)
- [Jinkyu Yi](https://github.com/jincreator)
- [Pedro Navarro](https://github.com/pedronavf)
Executable
+29
View File
@@ -0,0 +1,29 @@
#!/bin/bash -x
set -e
apt-get install -y git bzip2 ninja-build pkg-config libglib2.0-dev python3-distutils-extra libpixman-1-dev
cd /
git clone --depth=1 https://github.com/foss-for-synopsys-dwc-arc-processors/qemu.git
mkdir /qemu/build
cd /qemu/build
../configure --static --extra-cflags=-Wno-error
ninja
ln -s /qemu/build/qemu-arc /qemu/build/qemu-arc64 /usr/local/bin
apt-get install -y libgmp-dev libmpfr-dev texinfo bison yacc flex
cd /
git clone --depth=1 https://github.com/foss-for-synopsys-dwc-arc-processors/binutils-gdb.git
cd /binutils-gdb
mkdir build
cd build
../configure --target=arc-linux
make -j$(nproc)
apt-get install -y mold
mkdir /build
cd /build
cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DMOLD_USE_MOLD=1 /mold
ninja
TRIPLE=arc-linux-gnu bash -x /mold/test/hello-dynamic.sh
-441
View File
@@ -1,441 +0,0 @@
#include "mold.h"
enum {
R_TLS_GOTIE = R_END + 1,
R_TLS_LE,
R_TLS_GD,
R_TLS_LD,
R_TLS_GOTDESC,
R_TLS_GOTDESC_RELAX,
R_TLS_DESC_CALL_RELAX,
R_TPOFF,
};
template <>
void PltSection<I386>::copy_buf(Context<I386> &ctx) {
u8 *buf = ctx.buf + this->shdr.sh_offset;
// Write PLT header
if (ctx.arg.pic) {
static const u8 plt0[] = {
0xff, 0xb3, 0x04, 0, 0, 0, // pushl 4(%ebx)
0xff, 0xa3, 0x08, 0, 0, 0, // jmp *8(%ebx)
0x90, 0x90, 0x90, 0x90, // nop
};
memcpy(buf, plt0, sizeof(plt0));
} else {
static const u8 plt0[] = {
0xff, 0x35, 0, 0, 0, 0, // pushl (GOTPLT+4)
0xff, 0x25, 0, 0, 0, 0, // jmp *(GOTPLT+8)
0x90, 0x90, 0x90, 0x90, // nop
};
memcpy(buf, plt0, sizeof(plt0));
*(u32 *)(buf + 2) = ctx.gotplt->shdr.sh_addr + 4;
*(u32 *)(buf + 8) = ctx.gotplt->shdr.sh_addr + 8;
}
// Write PLT entries
i64 relplt_idx = 0;
for (Symbol<I386> *sym : symbols) {
u8 *ent = buf + sym->get_plt_idx(ctx) * I386::plt_size;
if (ctx.arg.pic) {
static const u8 data[] = {
0xff, 0xa3, 0, 0, 0, 0, // jmp *foo@GOT(%ebx)
0x68, 0, 0, 0, 0, // pushl $reloc_offset
0xe9, 0, 0, 0, 0, // jmp .PLT0@PC
};
memcpy(ent, data, sizeof(data));
*(u32 *)(ent + 2) = sym->get_gotplt_addr(ctx) - ctx.gotplt->shdr.sh_addr;
} else {
static const u8 data[] = {
0xff, 0x25, 0, 0, 0, 0, // jmp *foo@GOT
0x68, 0, 0, 0, 0, // pushl $reloc_offset
0xe9, 0, 0, 0, 0, // jmp .PLT0@PC
};
memcpy(ent, data, sizeof(data));
*(u32 *)(ent + 2) = sym->get_gotplt_addr(ctx);
}
*(u32 *)(ent + 7) = relplt_idx++ * sizeof(ElfRel<I386>);
*(u32 *)(ent + 12) = this->shdr.sh_addr - sym->get_plt_addr(ctx) - 16;
}
}
template <>
void PltGotSection<I386>::copy_buf(Context<I386> &ctx) {
u8 *buf = ctx.buf + this->shdr.sh_offset;
if (ctx.arg.pic) {
static const u8 data[] = {
0xff, 0xa3, 0, 0, 0, 0, // jmp *foo@GOT(%ebx)
0x66, 0x90, // nop
};
for (i64 i = 0; i < symbols.size(); i++) {
u8 *ent = buf + i * sizeof(data);
memcpy(ent, data, sizeof(data));
*(u32 *)(ent + 2) = symbols[i]->get_got_addr(ctx) - ctx.gotplt->shdr.sh_addr;
}
} else {
static const u8 data[] = {
0xff, 0x25, 0, 0, 0, 0, // jmp *foo@GOT
0x66, 0x90, // nop
};
for (i64 i = 0; i < symbols.size(); i++) {
u8 *ent = buf + i * sizeof(data);
memcpy(ent, data, sizeof(data));
*(u32 *)(ent + 2) = symbols[i]->get_got_addr(ctx);
}
}
}
template <>
void EhFrameSection<I386>::apply_reloc(Context<I386> &ctx,
ElfRel<I386> &rel,
u64 loc, u64 val) {
u8 *base = ctx.buf + this->shdr.sh_offset;
switch (rel.r_type) {
case R_386_NONE:
return;
case R_386_32:
*(u32 *)(base + loc) = val;
return;
case R_386_PC32:
*(u32 *)(base + loc) = val - this->shdr.sh_addr - loc;
return;
}
unreachable(ctx);
}
static void write_val(Context<I386> &ctx, u64 r_type, u8 *loc, u64 val) {
switch (r_type) {
case R_386_NONE:
return;
case R_386_8:
case R_386_PC8:
*loc += val;
return;
case R_386_16:
case R_386_PC16:
*(u16 *)loc += val;
return;
case R_386_32:
case R_386_PC32:
case R_386_GOT32:
case R_386_GOT32X:
case R_386_PLT32:
case R_386_GOTOFF:
case R_386_GOTPC:
case R_386_TLS_LDM:
case R_386_TLS_GOTIE:
case R_386_TLS_LE:
case R_386_TLS_GD:
case R_386_TLS_LDO_32:
case R_386_SIZE32:
case R_386_TLS_GOTDESC:
*(u32 *)loc += val;
return;
}
unreachable(ctx);
}
template <>
void InputSection<I386>::apply_reloc_alloc(Context<I386> &ctx, u8 *base) {
ElfRel<I386> *dynrel = nullptr;
std::span<ElfRel<I386>> rels = get_rels(ctx);
i64 frag_idx = 0;
if (ctx.reldyn)
dynrel = (ElfRel<I386> *)(ctx.buf + ctx.reldyn->shdr.sh_offset +
file.reldyn_offset + this->reldyn_offset);
for (i64 i = 0; i < rels.size(); i++) {
const ElfRel<I386> &rel = rels[i];
Symbol<I386> &sym = *file.symbols[rel.r_sym];
u8 *loc = base + rel.r_offset;
const SectionFragmentRef<I386> *ref = nullptr;
if (rel_fragments && rel_fragments[frag_idx].idx == i)
ref = &rel_fragments[frag_idx++];
auto write = [&](u64 val) {
write_val(ctx, rel.r_type, loc, val);
};
#define S (ref ? ref->frag->get_addr(ctx) : sym.get_addr(ctx))
#define A (ref ? ref->addend : 0)
#define P (output_section->shdr.sh_addr + offset + rel.r_offset)
#define G (sym.get_got_addr(ctx) - ctx.got->shdr.sh_addr)
#define GOTPLT ctx.gotplt->shdr.sh_addr
switch (rel_types[i]) {
case R_NONE:
break;
case R_ABS:
write(S + A);
break;
case R_BASEREL:
*dynrel++ = {P, R_386_RELATIVE, 0};
*(u32 *)loc += S + A;
break;
case R_DYN:
*dynrel++ = {P, R_386_32, (u32)sym.get_dynsym_idx(ctx)};
*(u32 *)loc += A;
break;
case R_PC:
write(S + A - P);
break;
case R_GOT:
write(sym.get_got_addr(ctx) + A - GOTPLT);
break;
case R_GOTOFF:
write(S + A - GOTPLT);
break;
case R_GOTPC:
write(GOTPLT + A - P);
break;
case R_GOTPCREL:
write(G + GOTPLT + A - P);
break;
case R_TLS_GOTIE:
write(sym.get_gottp_addr(ctx) + A - GOTPLT);
break;
case R_TLS_LE:
write(S + A - ctx.tls_end);
break;
case R_TLS_GD:
write(sym.get_tlsgd_addr(ctx) + A - GOTPLT);
break;
case R_TLS_LD:
write(ctx.got->get_tlsld_addr(ctx) + A - GOTPLT);
break;
case R_TPOFF:
write(S + A - ctx.tls_begin);
break;
case R_TLS_GOTDESC:
write(sym.get_tlsdesc_addr(ctx) + A - GOTPLT);
break;
case R_TLS_GOTDESC_RELAX: {
static const u8 insn[] = {
0x8d, 0x05, 0, 0, 0, 0, // lea 0, %eax
};
memcpy(loc - 2, insn, sizeof(insn));
write(S + A - ctx.tls_end);
break;
}
case R_TLS_DESC_CALL_RELAX:
// call *(%rax) -> nop
loc[0] = 0x66;
loc[1] = 0x90;
break;
case R_SIZE:
write(sym.esym().st_size + A);
break;
default:
unreachable(ctx);
}
#undef S
#undef A
#undef P
#undef G
#undef GOTPLT
}
}
template <>
void InputSection<I386>::apply_reloc_nonalloc(Context<I386> &ctx, u8 *base) {
std::span<ElfRel<I386>> rels = get_rels(ctx);
i64 frag_idx = 0;
for (i64 i = 0; i < rels.size(); i++) {
const ElfRel<I386> &rel = rels[i];
if (rel.r_type == R_386_NONE)
continue;
Symbol<I386> &sym = *file.symbols[rel.r_sym];
u8 *loc = base + rel.r_offset;
if (!sym.file) {
report_undef(ctx, sym);
continue;
}
const SectionFragmentRef<I386> *ref = nullptr;
if (rel_fragments && rel_fragments[frag_idx].idx == i)
ref = &rel_fragments[frag_idx++];
auto write = [&](u64 val) {
write_val(ctx, rel.r_type, loc, val);
};
switch (rel.r_type) {
case R_386_8:
case R_386_16:
case R_386_32:
case R_386_PC8:
case R_386_PC16:
case R_386_PC32:
case R_386_GOTPC:
if (ref)
write(ref->frag->get_addr(ctx) + ref->addend);
else
write(sym.get_addr(ctx));
break;
case R_386_GOTOFF:
write(sym.get_addr(ctx) - ctx.got->shdr.sh_addr);
break;
case R_386_TLS_LDO_32:
write(sym.get_addr(ctx) - ctx.tls_begin);
break;
case R_386_SIZE32:
write(sym.esym().st_size);
break;
default:
Fatal(ctx) << *this << ": invalid relocation for non-allocated sections: "
<< rel_to_string<I386>(rel.r_type);
break;
}
}
}
template <>
void InputSection<I386>::scan_relocations(Context<I386> &ctx) {
assert(shdr.sh_flags & SHF_ALLOC);
this->reldyn_offset = file.num_dynrel * sizeof(ElfRel<I386>);
std::span<ElfRel<I386>> rels = get_rels(ctx);
bool is_writable = (shdr.sh_flags & SHF_WRITE);
// Scan relocations
for (i64 i = 0; i < rels.size(); i++) {
const ElfRel<I386> &rel = rels[i];
if (rel.r_type == R_386_NONE) {
rel_types[i] = R_NONE;
break;
}
Symbol<I386> &sym = *file.symbols[rel.r_sym];
u8 *loc = (u8 *)(contents.data() + rel.r_offset);
if (!sym.file) {
report_undef(ctx, sym);
continue;
}
if (sym.get_type() == STT_GNU_IFUNC) {
sym.flags |= NEEDS_GOT;
sym.flags |= NEEDS_PLT;
}
switch (rel.r_type) {
case R_386_8:
case R_386_16: {
Action table[][4] = {
// Absolute Local Imported data Imported code
{ NONE, ERROR, ERROR, ERROR }, // DSO
{ NONE, ERROR, ERROR, ERROR }, // PIE
{ NONE, NONE, COPYREL, PLT }, // PDE
};
dispatch(ctx, table, R_ABS, i);
break;
}
case R_386_32: {
Action table[][4] = {
// Absolute Local Imported data Imported code
{ NONE, BASEREL, DYNREL, DYNREL }, // DSO
{ NONE, BASEREL, DYNREL, DYNREL }, // PIE
{ NONE, NONE, DYNREL, PLT }, // PDE
};
dispatch(ctx, table, R_ABS, i);
break;
}
case R_386_PC8:
case R_386_PC16: {
Action table[][4] = {
// Absolute Local Imported data Imported code
{ ERROR, NONE, ERROR, ERROR }, // DSO
{ ERROR, NONE, COPYREL, PLT }, // PIE
{ NONE, NONE, COPYREL, PLT }, // PDE
};
dispatch(ctx, table, R_PC, i);
break;
}
case R_386_PC32: {
Action table[][4] = {
// Absolute Local Imported data Imported code
{ BASEREL, NONE, ERROR, ERROR }, // DSO
{ BASEREL, NONE, COPYREL, PLT }, // PIE
{ NONE, NONE, COPYREL, PLT }, // PDE
};
dispatch(ctx, table, R_PC, i);
break;
}
case R_386_GOT32:
case R_386_GOT32X:
sym.flags |= NEEDS_GOT;
rel_types[i] = R_GOT;
break;
case R_386_PLT32:
if (sym.is_imported)
sym.flags |= NEEDS_PLT;
rel_types[i] = R_PC;
break;
case R_386_GOTOFF:
rel_types[i] = R_GOTOFF;
break;
case R_386_GOTPC:
sym.flags |= NEEDS_GOT;
rel_types[i] = R_GOTPC;
break;
case R_386_TLS_GOTIE:
sym.flags |= NEEDS_GOTTP;
rel_types[i] = R_TLS_GOTIE;
break;
case R_386_TLS_LE:
sym.flags |= NEEDS_GOTTP;
rel_types[i] = R_TLS_LE;
break;
case R_386_TLS_GD:
sym.flags |= NEEDS_TLSGD;
rel_types[i] = R_TLS_GD;
break;
case R_386_TLS_LDM:
sym.flags |= NEEDS_TLSLD;
rel_types[i] = R_TLS_LD;
break;
case R_386_TLS_LDO_32:
rel_types[i] = R_TPOFF;
break;
case R_386_SIZE32:
rel_types[i] = R_SIZE;
break;
case R_386_TLS_GOTDESC:
if (ctx.arg.relax && !ctx.arg.shared) {
rel_types[i] = R_TLS_GOTDESC_RELAX;
} else {
sym.flags |= NEEDS_TLSDESC;
rel_types[i] = R_TLS_GOTDESC;
}
break;
case R_386_TLS_DESC_CALL:
if (ctx.arg.relax && !ctx.arg.shared)
rel_types[i] = R_TLS_DESC_CALL_RELAX;
else
rel_types[i] = R_NONE;
break;
default:
Error(ctx) << *this << ": unknown relocation: "
<< rel_to_string<I386>(rel.r_type);
}
}
}
-687
View File
@@ -1,687 +0,0 @@
#include "mold.h"
enum {
R_GOTPCRELX_RELAX = R_END + 1,
R_REX_GOTPCRELX_RELAX,
R_TLSGD,
R_TLSGD_RELAX_LE,
R_TLSLD,
R_TLSLD_RELAX_LE,
R_DTPOFF,
R_DTPOFF_RELAX,
R_TPOFF,
R_GOTTPOFF,
R_GOTTPOFF_RELAX,
R_GOTPC_TLSDESC,
R_GOTPC_TLSDESC_RELAX_LE,
R_TLSDESC_CALL_RELAX,
};
template <>
void PltSection<X86_64>::copy_buf(Context<X86_64> &ctx) {
u8 *buf = ctx.buf + this->shdr.sh_offset;
// Write PLT header
static const u8 plt0[] = {
0xff, 0x35, 0, 0, 0, 0, // pushq GOTPLT+8(%rip)
0xff, 0x25, 0, 0, 0, 0, // jmp *GOTPLT+16(%rip)
0x0f, 0x1f, 0x40, 0x00, // nop
};
memcpy(buf, plt0, sizeof(plt0));
*(u32 *)(buf + 2) = ctx.gotplt->shdr.sh_addr - this->shdr.sh_addr + 2;
*(u32 *)(buf + 8) = ctx.gotplt->shdr.sh_addr - this->shdr.sh_addr + 4;
// Write PLT entries
i64 relplt_idx = 0;
static const u8 data[] = {
0xff, 0x25, 0, 0, 0, 0, // jmp *foo@GOTPLT
0x68, 0, 0, 0, 0, // push $index_in_relplt
0xe9, 0, 0, 0, 0, // jmp PLT[0]
};
for (Symbol<X86_64> *sym : symbols) {
u8 *ent = buf + sym->get_plt_idx(ctx) * X86_64::plt_size;
memcpy(ent, data, sizeof(data));
*(u32 *)(ent + 2) = sym->get_gotplt_addr(ctx) - sym->get_plt_addr(ctx) - 6;
*(u32 *)(ent + 7) = relplt_idx++;
*(u32 *)(ent + 12) = this->shdr.sh_addr - sym->get_plt_addr(ctx) - 16;
}
}
template <>
void PltGotSection<X86_64>::copy_buf(Context<X86_64> &ctx) {
u8 *buf = ctx.buf + this->shdr.sh_offset;
static const u8 data[] = {
0xff, 0x25, 0, 0, 0, 0, // jmp *foo@GOT
0x66, 0x90, // nop
};
for (Symbol<X86_64> *sym : symbols) {
u8 *ent = buf + sym->get_pltgot_idx(ctx) * X86_64::pltgot_size;
memcpy(ent, data, sizeof(data));
*(u32 *)(ent + 2) = sym->get_got_addr(ctx) - sym->get_plt_addr(ctx) - 6;
}
}
template <>
void EhFrameSection<X86_64>::apply_reloc(Context<X86_64> &ctx,
ElfRel<X86_64> &rel,
u64 loc, u64 val) {
u8 *base = ctx.buf + this->shdr.sh_offset;
switch (rel.r_type) {
case R_X86_64_NONE:
return;
case R_X86_64_32:
*(u32 *)(base + loc) = val;
return;
case R_X86_64_64:
*(u64 *)(base + loc) = val;
return;
case R_X86_64_PC32:
*(u32 *)(base + loc) = val - this->shdr.sh_addr - loc;
return;
case R_X86_64_PC64:
*(u64 *)(base + loc) = val - this->shdr.sh_addr - loc;
return;
}
unreachable(ctx);
}
static void overflow_check(Context<X86_64> &ctx, InputSection<X86_64> *sec,
Symbol<X86_64> &sym, u64 r_type, u64 val) {
switch (r_type) {
case R_X86_64_8:
if (val != (u8)val)
Error(ctx) << *sec << ": relocation R_X86_64_8 against " << sym
<< " out of range: " << val << " is not in [0, 255]";
return;
case R_X86_64_PC8:
if (val != (i8)val)
Error(ctx) << *sec << ": relocation R_X86_64_PC8 against " << sym
<< " out of range: " << (i64)val << " is not in [-128, 127]";
return;
case R_X86_64_16:
if (val != (u16)val)
Error(ctx) << *sec << ": relocation R_X86_64_16 against " << sym
<< " out of range: " << val << " is not in [0, 65535]";
return;
case R_X86_64_PC16:
if (val != (i16)val)
Error(ctx) << *sec << ": relocation R_X86_64_PC16 against " << sym
<< " out of range: " << (i64)val
<< " is not in [-32768, 32767]";
return;
case R_X86_64_32:
if (val != (u32)val)
Error(ctx) << *sec << ": relocation R_X86_64_32 against " << sym
<< " out of range: " << val << " is not in [0, 4294967296]";
return;
case R_X86_64_32S:
case R_X86_64_PC32:
case R_X86_64_GOT32:
case R_X86_64_GOTPC32:
case R_X86_64_GOTPCREL:
case R_X86_64_GOTPCRELX:
case R_X86_64_REX_GOTPCRELX:
case R_X86_64_PLT32:
case R_X86_64_TLSGD:
case R_X86_64_TLSLD:
case R_X86_64_TPOFF32:
case R_X86_64_DTPOFF32:
case R_X86_64_GOTTPOFF:
case R_X86_64_GOTPC32_TLSDESC:
case R_X86_64_SIZE32:
case R_X86_64_TLSDESC_CALL:
if (val != (i32)val)
Error(ctx) << *sec << ": relocation " << rel_to_string<X86_64>(r_type)
<< " against " << sym << " out of range: " << (i64)val
<< " is not in [-2147483648, 2147483647]";
return;
case R_X86_64_NONE:
case R_X86_64_64:
case R_X86_64_PC64:
case R_X86_64_TPOFF64:
case R_X86_64_DTPOFF64:
case R_X86_64_GOT64:
case R_X86_64_GOTPCREL64:
case R_X86_64_GOTPC64:
case R_X86_64_SIZE64:
return;
}
unreachable(ctx);
}
static void write_val(Context<X86_64> &ctx, u64 r_type, u8 *loc, u64 val) {
switch (r_type) {
case R_X86_64_NONE:
return;
case R_X86_64_8:
case R_X86_64_PC8:
*loc = val;
return;
case R_X86_64_16:
case R_X86_64_PC16:
*(u16 *)loc = val;
return;
case R_X86_64_32:
case R_X86_64_32S:
case R_X86_64_PC32:
case R_X86_64_GOT32:
case R_X86_64_GOTPC32:
case R_X86_64_GOTPCREL:
case R_X86_64_GOTPCRELX:
case R_X86_64_REX_GOTPCRELX:
case R_X86_64_PLT32:
case R_X86_64_TLSGD:
case R_X86_64_TLSLD:
case R_X86_64_TPOFF32:
case R_X86_64_DTPOFF32:
case R_X86_64_GOTTPOFF:
case R_X86_64_GOTPC32_TLSDESC:
case R_X86_64_SIZE32:
case R_X86_64_TLSDESC_CALL:
*(u32 *)loc = val;
return;
case R_X86_64_64:
case R_X86_64_PC64:
case R_X86_64_TPOFF64:
case R_X86_64_DTPOFF64:
case R_X86_64_GOT64:
case R_X86_64_GOTPCREL64:
case R_X86_64_GOTPC64:
case R_X86_64_SIZE64:
*(u64 *)loc = val;
return;
}
unreachable(ctx);
}
static u32 relax_gotpcrelx(u8 *loc) {
switch ((loc[0] << 8) | loc[1]) {
case 0xff15: return 0x90e8; // call *0(%rip) -> call 0
case 0xff25: return 0x90e9; // jmp *0(%rip) -> jmp 0
}
return 0;
}
static u32 relax_rex_gotpcrelx(u8 *loc) {
switch ((loc[0] << 16) | (loc[1] << 8) | loc[2]) {
case 0x488b05: return 0x488d05; // mov 0(%rip), %rax -> lea 0(%rip), %rax
case 0x488b0d: return 0x488d0d; // mov 0(%rip), %rcx -> lea 0(%rip), %rcx
case 0x488b15: return 0x488d15; // mov 0(%rip), %rdx -> lea 0(%rip), %rdx
case 0x488b1d: return 0x488d1d; // mov 0(%rip), %rbx -> lea 0(%rip), %rbx
case 0x488b25: return 0x488d25; // mov 0(%rip), %rsp -> lea 0(%rip), %rsp
case 0x488b2d: return 0x488d2d; // mov 0(%rip), %rbp -> lea 0(%rip), %rbp
case 0x488b35: return 0x488d35; // mov 0(%rip), %rsi -> lea 0(%rip), %rsi
case 0x488b3d: return 0x488d3d; // mov 0(%rip), %rdi -> lea 0(%rip), %rdi
case 0x4c8b05: return 0x4c8d05; // mov 0(%rip), %r8 -> lea 0(%rip), %r8
case 0x4c8b0d: return 0x4c8d0d; // mov 0(%rip), %r9 -> lea 0(%rip), %r9
case 0x4c8b15: return 0x4c8d15; // mov 0(%rip), %r10 -> lea 0(%rip), %r10
case 0x4c8b1d: return 0x4c8d1d; // mov 0(%rip), %r11 -> lea 0(%rip), %r11
case 0x4c8b25: return 0x4c8d25; // mov 0(%rip), %r12 -> lea 0(%rip), %r12
case 0x4c8b2d: return 0x4c8d2d; // mov 0(%rip), %r13 -> lea 0(%rip), %r13
case 0x4c8b35: return 0x4c8d35; // mov 0(%rip), %r14 -> lea 0(%rip), %r14
case 0x4c8b3d: return 0x4c8d3d; // mov 0(%rip), %r15 -> lea 0(%rip), %r15
}
return 0;
}
static u32 relax_gottpoff(u8 *loc) {
switch ((loc[0] << 16) | (loc[1] << 8) | loc[2]) {
case 0x488b05: return 0x48c7c0; // mov 0(%rip), %rax -> mov $0, %rax
case 0x488b0d: return 0x48c7c1; // mov 0(%rip), %rcx -> mov $0, %rcx
case 0x488b15: return 0x48c7c2; // mov 0(%rip), %rdx -> mov $0, %rdx
case 0x488b1d: return 0x48c7c3; // mov 0(%rip), %rbx -> mov $0, %rbx
case 0x488b25: return 0x48c7c4; // mov 0(%rip), %rsp -> mov $0, %rsp
case 0x488b2d: return 0x48c7c5; // mov 0(%rip), %rbp -> mov $0, %rbp
case 0x488b35: return 0x48c7c6; // mov 0(%rip), %rsi -> mov $0, %rsi
case 0x488b3d: return 0x48c7c7; // mov 0(%rip), %rdi -> mov $0, %rdi
case 0x4c8b05: return 0x49c7c0; // mov 0(%rip), %r8 -> mov $0, %r8
case 0x4c8b0d: return 0x49c7c1; // mov 0(%rip), %r9 -> mov $0, %r9
case 0x4c8b15: return 0x49c7c2; // mov 0(%rip), %r10 -> mov $0, %r10
case 0x4c8b1d: return 0x49c7c3; // mov 0(%rip), %r11 -> mov $0, %r11
case 0x4c8b25: return 0x49c7c4; // mov 0(%rip), %r12 -> mov $0, %r12
case 0x4c8b2d: return 0x49c7c5; // mov 0(%rip), %r13 -> mov $0, %r13
case 0x4c8b35: return 0x49c7c6; // mov 0(%rip), %r14 -> mov $0, %r14
case 0x4c8b3d: return 0x49c7c7; // mov 0(%rip), %r15 -> mov $0, %r15
}
return 0;
}
// Apply relocations to SHF_ALLOC sections (i.e. sections that are
// mapped to memory at runtime) based on the result of
// scan_relocations().
template <>
void InputSection<X86_64>::apply_reloc_alloc(Context<X86_64> &ctx, u8 *base) {
ElfRel<X86_64> *dynrel = nullptr;
std::span<ElfRel<X86_64>> rels = get_rels(ctx);
i64 frag_idx = 0;
if (ctx.reldyn)
dynrel = (ElfRel<X86_64> *)(ctx.buf + ctx.reldyn->shdr.sh_offset +
file.reldyn_offset + this->reldyn_offset);
for (i64 i = 0; i < rels.size(); i++) {
const ElfRel<X86_64> &rel = rels[i];
Symbol<X86_64> &sym = *file.symbols[rel.r_sym];
u8 *loc = base + rel.r_offset;
const SectionFragmentRef<X86_64> *ref = nullptr;
if (rel_fragments && rel_fragments[frag_idx].idx == i)
ref = &rel_fragments[frag_idx++];
auto write = [&](u64 val) {
overflow_check(ctx, this, sym, rel.r_type, val);
write_val(ctx, rel.r_type, loc, val);
};
#define S (ref ? ref->frag->get_addr(ctx) : sym.get_addr(ctx))
#define A (ref ? ref->addend : rel.r_addend)
#define P (output_section->shdr.sh_addr + offset + rel.r_offset)
#define G (sym.get_got_addr(ctx) - ctx.got->shdr.sh_addr)
#define GOT ctx.got->shdr.sh_addr
switch (rel_types[i]) {
case R_NONE:
break;
case R_ABS:
write(S + A);
break;
case R_BASEREL:
*dynrel++ = {P, R_X86_64_RELATIVE, 0, (i64)(S + A)};
*(u64 *)loc = S + A;
break;
case R_DYN:
*dynrel++ = {P, R_X86_64_64, (u32)sym.get_dynsym_idx(ctx), A};
*(u64 *)loc = A;
break;
case R_PC:
write(S + A - P);
break;
case R_GOT:
write(G + A);
break;
case R_GOTPC:
write(GOT + A - P);
break;
case R_GOTPCREL:
write(G + GOT + A - P);
break;
case R_GOTPCRELX_RELAX: {
u32 insn = relax_gotpcrelx(loc - 2);
loc[-2] = insn >> 8;
loc[-1] = insn;
write(S + A - P);
break;
}
case R_REX_GOTPCRELX_RELAX: {
u32 insn = relax_rex_gotpcrelx(loc - 3);
loc[-3] = insn >> 16;
loc[-2] = insn >> 8;
loc[-1] = insn;
write(S + A - P);
break;
}
case R_TLSGD:
write(sym.get_tlsgd_addr(ctx) + A - P);
break;
case R_TLSGD_RELAX_LE: {
// Relax GD to LE
static const u8 insn[] = {
0x64, 0x48, 0x8b, 0x04, 0x25, 0, 0, 0, 0, // mov %fs:0, %rax
0x48, 0x8d, 0x80, 0, 0, 0, 0, // lea 0(%rax), %rax
};
memcpy(loc - 4, insn, sizeof(insn));
*(u32 *)(loc + 8) = S - ctx.tls_end + A + 4;
i++;
break;
}
case R_TLSLD:
write(ctx.got->get_tlsld_addr(ctx) + A - P);
break;
case R_TLSLD_RELAX_LE: {
// Relax LD to LE
static const u8 insn[] = {
0x66, 0x66, 0x66, // (padding)
0x64, 0x48, 0x8b, 0x04, 0x25, 0, 0, 0, 0, // mov %fs:0, %rax
};
memcpy(loc - 3, insn, sizeof(insn));
i++;
break;
}
case R_DTPOFF:
write(S + A - ctx.tls_begin);
break;
case R_DTPOFF_RELAX:
write(S + A - ctx.tls_end);
break;
case R_TPOFF:
write(S + A - ctx.tls_end);
break;
case R_GOTTPOFF:
write(sym.get_gottp_addr(ctx) + A - P);
break;
case R_GOTTPOFF_RELAX: {
u32 insn = relax_gottpoff(loc - 3);
loc[-3] = insn >> 16;
loc[-2] = insn >> 8;
loc[-1] = insn;
write(S + A - ctx.tls_end + 4);
break;
}
case R_GOTPC_TLSDESC:
write(sym.get_tlsdesc_addr(ctx) + A - P);
break;
case R_GOTPC_TLSDESC_RELAX_LE: {
static const u8 insn[] = {
0x48, 0xc7, 0xc0, 0, 0, 0, 0, // mov $0, %rax
};
memcpy(loc - 3, insn, sizeof(insn));
write(S + A - ctx.tls_end + 4);
break;
}
case R_SIZE:
write(sym.esym().st_size + A);
break;
case R_TLSDESC_CALL_RELAX:
// call *(%rax) -> nop
loc[0] = 0x66;
loc[1] = 0x90;
break;
default:
unreachable(ctx);
}
#undef S
#undef A
#undef P
#undef G
#undef GOT
}
}
// This function is responsible for applying relocations against
// non-SHF_ALLOC sections (i.e. sections that are not mapped to memory
// at runtime).
//
// Relocations against non-SHF_ALLOC sections are much easier to
// handle than that against SHF_ALLOC sections. It is because, since
// they are not mapped to memory, they don't contain any variable or
// function and never need PLT or GOT. Non-SHF_ALLOC sections are
// mostly debug info sections.
//
// Relocations against non-SHF_ALLOC sections are not scanned by
// scan_relocations.
template <>
void InputSection<X86_64>::apply_reloc_nonalloc(Context<X86_64> &ctx, u8 *base) {
std::span<ElfRel<X86_64>> rels = get_rels(ctx);
i64 frag_idx = 0;
for (i64 i = 0; i < rels.size(); i++) {
const ElfRel<X86_64> &rel = rels[i];
if (rel.r_type == R_X86_64_NONE)
continue;
Symbol<X86_64> &sym = *file.symbols[rel.r_sym];
u8 *loc = base + rel.r_offset;
if (!sym.file) {
report_undef(ctx, sym);
continue;
}
const SectionFragmentRef<X86_64> *ref = nullptr;
if (rel_fragments && rel_fragments[frag_idx].idx == i)
ref = &rel_fragments[frag_idx++];
auto write = [&](u64 val) {
overflow_check(ctx, this, sym, rel.r_type, val);
write_val(ctx, rel.r_type, loc, val);
};
switch (rel.r_type) {
case R_X86_64_8:
case R_X86_64_16:
case R_X86_64_32:
case R_X86_64_32S:
case R_X86_64_64:
if (ref)
write(ref->frag->get_addr(ctx) + ref->addend);
else
write(sym.get_addr(ctx) + rel.r_addend);
break;
case R_X86_64_DTPOFF32:
case R_X86_64_DTPOFF64:
write(sym.get_addr(ctx) + rel.r_addend - ctx.tls_begin);
break;
case R_X86_64_SIZE32:
case R_X86_64_SIZE64:
write(sym.esym().st_size + rel.r_addend);
break;
default:
Fatal(ctx) << *this << ": invalid relocation for non-allocated sections: "
<< rel_to_string<X86_64>(rel.r_type);
break;
}
}
}
// Linker has to create data structures in an output file to apply
// some type of relocations. For example, if a relocation refers a GOT
// or a PLT entry of a symbol, linker has to create an entry in .got
// or in .plt for that symbol. In order to fix the file layout, we
// need to scan relocations.
template <>
void InputSection<X86_64>::scan_relocations(Context<X86_64> &ctx) {
assert(shdr.sh_flags & SHF_ALLOC);
this->reldyn_offset = file.num_dynrel * sizeof(ElfRel<X86_64>);
std::span<ElfRel<X86_64>> rels = get_rels(ctx);
bool is_writable = (shdr.sh_flags & SHF_WRITE);
// Scan relocations
for (i64 i = 0; i < rels.size(); i++) {
const ElfRel<X86_64> &rel = rels[i];
if (rel.r_type == R_X86_64_NONE) {
rel_types[i] = R_NONE;
continue;
}
Symbol<X86_64> &sym = *file.symbols[rel.r_sym];
u8 *loc = (u8 *)(contents.data() + rel.r_offset);
if (!sym.file) {
report_undef(ctx, sym);
continue;
}
if (sym.get_type() == STT_GNU_IFUNC) {
sym.flags |= NEEDS_GOT;
sym.flags |= NEEDS_PLT;
}
switch (rel.r_type) {
case R_X86_64_8:
case R_X86_64_16:
case R_X86_64_32:
case R_X86_64_32S: {
// Dynamic linker does not support 8, 16 or 32-bit dynamic
// relocations for these types of relocations. We report an
// error if we cannot relocate them even at load-time.
Action table[][4] = {
// Absolute Local Imported data Imported code
{ NONE, ERROR, ERROR, ERROR }, // DSO
{ NONE, ERROR, ERROR, ERROR }, // PIE
{ NONE, NONE, COPYREL, PLT }, // PDE
};
dispatch(ctx, table, R_ABS, i);
break;
}
case R_X86_64_64: {
// Unlike the above, we can use R_X86_64_RELATIVE and R_86_64_64
// relocations.
Action table[][4] = {
// Absolute Local Imported data Imported code
{ NONE, BASEREL, DYNREL, DYNREL }, // DSO
{ NONE, BASEREL, DYNREL, DYNREL }, // PIE
{ NONE, NONE, DYNREL, PLT }, // PDE
};
dispatch(ctx, table, R_ABS, i);
break;
}
case R_X86_64_PC8:
case R_X86_64_PC16:
case R_X86_64_PC32: {
Action table[][4] = {
// Absolute Local Imported data Imported code
{ ERROR, NONE, ERROR, ERROR }, // DSO
{ ERROR, NONE, COPYREL, PLT }, // PIE
{ NONE, NONE, COPYREL, PLT }, // PDE
};
dispatch(ctx, table, R_PC, i);
break;
}
case R_X86_64_PC64: {
Action table[][4] = {
// Absolute Local Imported data Imported code
{ BASEREL, NONE, ERROR, ERROR }, // DSO
{ BASEREL, NONE, COPYREL, PLT }, // PIE
{ NONE, NONE, COPYREL, PLT }, // PDE
};
dispatch(ctx, table, R_PC, i);
break;
}
case R_X86_64_GOT32:
case R_X86_64_GOT64:
sym.flags |= NEEDS_GOT;
rel_types[i] = R_GOT;
break;
case R_X86_64_GOTPC32:
case R_X86_64_GOTPC64:
sym.flags |= NEEDS_GOT;
rel_types[i] = R_GOTPC;
break;
case R_X86_64_GOTPCREL:
case R_X86_64_GOTPCREL64:
sym.flags |= NEEDS_GOT;
rel_types[i] = R_GOTPCREL;
break;
case R_X86_64_GOTPCRELX: {
if (rel.r_addend != -4)
Fatal(ctx) << *this << ": bad r_addend for R_X86_64_GOTPCRELX";
if (ctx.arg.relax && !sym.is_imported && sym.is_relative(ctx) &&
relax_gotpcrelx(loc - 2)) {
rel_types[i] = R_GOTPCRELX_RELAX;
} else {
sym.flags |= NEEDS_GOT;
rel_types[i] = R_GOTPCREL;
}
break;
}
case R_X86_64_REX_GOTPCRELX:
if (rel.r_addend != -4)
Fatal(ctx) << *this << ": bad r_addend for R_X86_64_REX_GOTPCRELX";
if (ctx.arg.relax && !sym.is_imported && sym.is_relative(ctx) &&
relax_rex_gotpcrelx(loc - 3)) {
rel_types[i] = R_REX_GOTPCRELX_RELAX;
} else {
sym.flags |= NEEDS_GOT;
rel_types[i] = R_GOTPCREL;
}
break;
case R_X86_64_PLT32:
if (sym.is_imported)
sym.flags |= NEEDS_PLT;
rel_types[i] = R_PC;
break;
case R_X86_64_TLSGD: {
if (i + 1 == rels.size())
Fatal(ctx) << *this
<< ": TLSGD reloc must be followed by PLT32 or GOTPCREL";
if (ctx.arg.relax && !ctx.arg.shared && !sym.is_imported) {
rel_types[i++] = R_TLSGD_RELAX_LE;
} else {
sym.flags |= NEEDS_TLSGD;
rel_types[i] = R_TLSGD;
}
break;
}
case R_X86_64_TLSLD:
if (i + 1 == rels.size())
Fatal(ctx) << *this
<< ": TLSGD reloc must be followed by PLT32 or GOTPCREL";
if (sym.is_imported)
Fatal(ctx) << *this << ": TLSLD reloc refers external symbol " << sym;
if (ctx.arg.relax && !ctx.arg.shared) {
rel_types[i++] = R_TLSLD_RELAX_LE;
} else {
sym.flags |= NEEDS_TLSLD;
rel_types[i] = R_TLSLD;
}
break;
case R_X86_64_DTPOFF32:
case R_X86_64_DTPOFF64:
if (sym.is_imported)
Fatal(ctx) << *this << ": DTPOFF reloc refers external symbol " << sym;
if (ctx.arg.relax && !ctx.arg.shared)
rel_types[i] = R_DTPOFF_RELAX;
else
rel_types[i] = R_DTPOFF;
break;
case R_X86_64_TPOFF32:
case R_X86_64_TPOFF64:
rel_types[i] = R_TPOFF;
break;
case R_X86_64_GOTTPOFF:
ctx.has_gottp_rel = true;
if (ctx.arg.relax && !ctx.arg.shared && !sym.is_imported &&
relax_gottpoff(loc - 3)) {
rel_types[i] = R_GOTTPOFF_RELAX;
} else {
sym.flags |= NEEDS_GOTTP;
rel_types[i] = R_GOTTPOFF;
}
break;
case R_X86_64_GOTPC32_TLSDESC:
if (memcmp(loc - 3, "\x48\x8d\x05", 3))
Fatal(ctx) << *this << ": GOTPC32_TLSDESC relocation is used"
<< " against an invalid code sequence";
if (ctx.arg.relax && !ctx.arg.shared) {
rel_types[i] = R_GOTPC_TLSDESC_RELAX_LE;
} else {
sym.flags |= NEEDS_TLSDESC;
rel_types[i] = R_GOTPC_TLSDESC;
}
break;
case R_X86_64_SIZE32:
case R_X86_64_SIZE64:
rel_types[i] = R_SIZE;
break;
case R_X86_64_TLSDESC_CALL:
if (ctx.arg.relax && !ctx.arg.shared)
rel_types[i] = R_TLSDESC_CALL_RELAX;
else
rel_types[i] = R_NONE;
break;
default:
Error(ctx) << *this << ": unknown relocation: "
<< rel_to_string<X86_64>(rel.r_type);
}
}
}
-118
View File
@@ -1,118 +0,0 @@
#include "mold.h"
struct ArHdr {
char ar_name[16];
char ar_date[12];
char ar_uid[6];
char ar_gid[6];
char ar_mode[8];
char ar_size[10];
char ar_fmag[2];
};
template <typename E>
std::vector<MemoryMappedFile<E> *>
read_thin_archive_members(Context<E> &ctx, MemoryMappedFile<E> *mb) {
u8 *begin = mb->data(ctx);
u8 *data = begin + 8;
std::vector<MemoryMappedFile<E> *> vec;
std::string_view strtab;
while (data < begin + mb->size()) {
// Each header is aligned to a 2 byte boundary.
if ((begin - data) % 2)
data++;
ArHdr &hdr = *(ArHdr *)data;
u8 *body = data + sizeof(hdr);
u64 size = atol(hdr.ar_size);
// Read a string table.
if (!memcmp(hdr.ar_name, "// ", 3)) {
strtab = {(char *)body, size};
data = body + size;
continue;
}
// Skip a symbol table.
if (!memcmp(hdr.ar_name, "/ ", 2)) {
data = body + size;
continue;
}
if (hdr.ar_name[0] != '/')
Fatal(ctx) << mb->name << ": filename is not stored as a long filename";
const char *start = strtab.data() + atoi(hdr.ar_name + 1);
std::string name(start, (const char *)strstr(start, "/\n"));
std::string path = name.starts_with('/') ?
name : std::string(path_dirname(mb->name)) + "/" + name;
vec.push_back(MemoryMappedFile<E>::must_open(ctx, path));
data = body;
}
return vec;
}
template <typename E>
std::vector<MemoryMappedFile<E> *>
read_fat_archive_members(Context<E> &ctx, MemoryMappedFile<E> *mb) {
u8 *begin = mb->data(ctx);
u8 *data = begin + 8;
std::vector<MemoryMappedFile<E> *> vec;
std::string_view strtab;
while (begin + mb->size() - data >= 2) {
if ((begin - data) % 2)
data++;
ArHdr &hdr = *(ArHdr *)data;
u8 *body = data + sizeof(hdr);
u64 size = atol(hdr.ar_size);
data = body + size;
if (!memcmp(hdr.ar_name, "// ", 3)) {
strtab = {(char *)body, size};
continue;
}
if (!memcmp(hdr.ar_name, "/ ", 2) ||
!memcmp(hdr.ar_name, "__.SYMDEF/", 10))
continue;
std::string name;
if (hdr.ar_name[0] == '/') {
const char *start = strtab.data() + atoi(hdr.ar_name + 1);
name = {start, (const char *)strstr(start, "/\n")};
} else {
name = {hdr.ar_name, strchr(hdr.ar_name, '/')};
}
vec.push_back(mb->slice(ctx, name, body - begin, size));
}
return vec;
}
template <typename E>
std::vector<MemoryMappedFile<E> *>
read_archive_members(Context<E> &ctx, MemoryMappedFile<E> *mb) {
switch (get_file_type(ctx, mb)) {
case FileType::AR:
return read_fat_archive_members(ctx, mb);
case FileType::THIN_AR:
return read_thin_archive_members(ctx, mb);
default:
unreachable(ctx);
}
}
#define INSTANTIATE(E) \
template std::vector<MemoryMappedFile<E> *> \
read_fat_archive_members(Context<E> &, MemoryMappedFile<E> *); \
template std::vector<MemoryMappedFile<E> *> \
read_thin_archive_members(Context<E> &, MemoryMappedFile<E> *); \
template std::vector<MemoryMappedFile<E> *> \
read_archive_members(Context<E> &, MemoryMappedFile<E> *);
INSTANTIATE(X86_64);
INSTANTIATE(I386);
-40
View File
@@ -1,40 +0,0 @@
#!/bin/bash -x
# This is a shell script to build a statically-linked mold
# executable using Docker, so that it is easy to build mold
# on non-Ubuntu 20.04 machines.
#
# A docker image used for building mold is persistent.
# Run `docker image rm mold-build-ubuntu20` to remove the image
# from disk.
set -e
# If the existing file is not statically-linked, remove it.
[ -f mold ] && ! ldd mold 2>&1 | grep -q 'not a dynamic executable' && \
rm mold
cat <<EOF | docker build -t mold-build-ubuntu20 -
FROM ubuntu:20.04
RUN apt-get update && \
TZ=Europe/London apt-get install -y tzdata && \
apt-get install -y build-essential git clang lld cmake \
libstdc++-10-dev libxxhash-dev zlib1g-dev libssl-dev && \
rm -rf /var/lib/apt/lists/*
EOF
if ! [ -d oneTBB ]; then
git clone https://github.com/oneapi-src/oneTBB.git
(cd oneTBB; git checkout --quiet v2020.3)
fi
docker run -it --rm -v `pwd`/oneTBB:/oneTBB -u $(id -u):$(id -g) \
mold-build-ubuntu20 \
make -C /oneTBB -j$(nproc) extra_inc=big_iron.inc
tbb_bindir=$(ls -d oneTBB/build/linux_intel64_*_release)
docker run -it --rm -v `pwd`:/mold -u $(id -u):$(id -g) \
mold-build-ubuntu20 \
make -C /mold -j$(nproc) \
EXTRA_CPPFLAGS=-IoneTBB/include \
EXTRA_LDFLAGS="-fuse-ld=lld -static -L$tbb_bindir"
-850
View File
@@ -1,850 +0,0 @@
#include "mold.h"
#include <sstream>
#include <sys/stat.h>
#include <sys/types.h>
#include <tbb/global_control.h>
#include <unistd.h>
#include <unordered_set>
static const char helpmsg[] = R"(
Options:
--help Report usage information
-v, --version Report version information
-V Report version and target information
-(, --start-group Ignored
-), --end-group Ignored
-C DIR, --directory DIR Change to DIR before doing anything
-E, --export-dynamic Put symbols in the dynamic symbol table
--no-export-dynamic
-F LIBNAME, --filter LIBNAME
Set DT_FILTER to the specified value
-I FILE, --dynamic-linker FILE
Set dynamic linker path
--no-dynamic-linker
-L DIR, --library-path DIR Add DIR to library search path
-M, --print-map Write map file to stdout
-N, --omagic Do not page align data, do not make text readonly
--no-omagic
-O NUMBER Ignored
-S, --strip-debug Strip .debug_* sections
-T FILE, --script FILE Read linker script
-X, --discard-locals Discard temporary local symbols
-e SYMBOL, --entry SYMBOL Set program entry point
-f SHLIB, --auxiliary SHLIB Set DT_AUXILIARY to the specified value
-h LIBNAME, --soname LIBNAME
Set shared library name
-l LIBNAME Search for a given library
-m EMULATION Ignored
-o FILE, --output FILE Set output filename
-r, --relocatable Generate relocatable output
-s, --strip-all Strip .symtab section
-u SYMBOL, --undefined SYMBOL
Force to resolve SYMBOL
--Bdynamic Link against shared libraries (default)
--Bstatic Do not link against shared libraries
--Bsymbolic Bind global symbols locally
--Bsymbolic-functions Bind global functions locally
--Map FILE Write map file to a given file
--allow-multiple-definition Allow multiple definitions
--as-needed Only set DT_NEEDED if used
--no-as-needed
--build-id [none,md5,sha1,sha256,uuid,HEXSTRING]
Generate build ID
--no-build-id
--chroot DIR Set a given path to root directory
--color-diagnostics Ignored
--compress-debug-sections [none,zlib,zlib-gabi,zlib-gnu]
Compress .debug_* sections
--demangle Demangle C++ symbols in log messages (default)
--no-demangle
--disable-new-dtags Ignored
--dynamic-list Read a list of dynamic symbols
--eh-frame-hdr Create .eh_frame_hdr section
--no-eh-frame-hdr
--enable-new-dtags Ignored
--exclude-libs LIB,LIB,.. Mark all symbols in given libraries hidden
--fatal-warnings Ignored
--no-fatal-warnings Ignored
--fini SYMBOL Call SYMBOL at unload-time
--fork Spawn a child process (default)
--no-fork
--gc-sections Remove unreferenced sections
--no-gc-sections
--gdb-index Ignored
--hash-style [sysv,gnu,both]
Set hash style
--icf Fold identical code
--no-icf
--image-base ADDR Set the base address to a given value
--init SYMBOL Call SYMBOl at load-time
--no-undefined Report undefined symbols (even with --shared)
--perf Print performance statistics
--pie, --pic-executable Create a position independent executable
--no-pie, --no-pic-executable
--plugin Ignored
--plugin-opt Ignored
--pop-state Pop state of flags governing input file handling
--preload
--print-gc-sections Print removed unreferenced sections
--no-print-gc-sections
--print-icf-sections Print folded identical sections
--no-print-icf-sections
--push-state Pop state of flags governing input file handling
--quick-exit Use quick_exit to exit (default)
--no-quick-exit
--relax Optimize instructions (default)
--no-relax
--repro Embed input files to .repro section
--retain-symbols-file FILE Keep only symbols listed in FILE
--rpath DIR Add DIR to runtime search path
--rpath-link DIR Ignored
--run COMMAND ARG... Run COMMAND with mold as /usr/bin/ld
--shared, --Bshareable Create a share library
--sort-common Ignored
--sort-section Ignored
--spare-dynamic-tags NUMBER Reserve give number of tags in .dynamic section
--static Do not link against shared libraries
--stats Print input statistics
--sysroot DIR Set target system root directory
--thread-count COUNT Use COUNT number of threads
--threads Use multiple threads (default)
--no-threads
--trace Print name of each input file
--unique PATTERN Don't merge input sections that match a given pattern
--unresolved-symbols [report-all,ignore-all,ignore-in-object-files,ignore-in-shared-libs]
How to handle unresolved symbols
--version-script FILE Read version script
--warn-common Warn about common symbols
--no-warn-common
--warn-unresolved-symbols Report unresolved symbols as warnings
--error-unresolved-symbols
Report unresolved symbols as errors (default)
--whole-archive Include all objects from static archives
--no-whole-archive
--wrap SYMBOL Use wrapper function for a given symbol
-z defs Report undefined symbols (even with --shared)
-z nodefs
-z execstack Require executable stack
-z noexecstack
-z initfirst Mark DSO to be initialized first at runtime
-z interpose Mark object to interpose all DSOs but executable
-z keep-text-section-prefix Keep .text.{hot,unknown,unlikely,startup,exit} as separate sections in the final binary
-z nokeep-text-section-prefix
-z lazy Enable lazy function resolution (default)
-z nocopyreloc Do not create copy relocations
-z nodelete Mark DSO non-deletable at runtime
-z nodlopen Mark DSO not available to dlopen
-z nodump Mark DSO not available to dldump
-z now Disable lazy function resolution
-z origin Mark object requiring immediate $ORIGIN processing at runtime
-z relro Make some sections read-only after relocation (default)
-z norelro
-z text Report error if DT_TEXTREL is set
-z notext
-z textoff
mold: supported targets: elf32-i386 elf64-x86-64
mold: supported emulations: elf_i386 elf_x86_64)";
template <typename E>
static std::vector<std::string_view>
read_response_file(Context<E> &ctx, std::string_view path) {
std::vector<std::string_view> vec;
MemoryMappedFile<E> *mb =
MemoryMappedFile<E>::must_open(ctx, std::string(path));
u8 *data = mb->data(ctx);
auto read_quoted = [&](i64 i, char quote) {
std::string buf;
while (i < mb->size() && data[i] != quote) {
if (data[i] == '\\') {
buf.append(1, data[i + 1]);
i += 2;
} else {
buf.append(1, data[i++]);
}
}
if (i >= mb->size())
Fatal(ctx) << path << ": premature end of input";
vec.push_back(save_string(ctx, buf));
return i + 1;
};
auto read_unquoted = [&](i64 i) {
std::string buf;
while (i < mb->size() && !isspace(data[i]))
buf.append(1, data[i++]);
vec.push_back(save_string(ctx, buf));
return i;
};
for (i64 i = 0; i < mb->size();) {
if (isspace(data[i]))
i++;
else if (data[i] == '\'')
i = read_quoted(i + 1, '\'');
else if (data[i] == '\"')
i = read_quoted(i + 1, '\"');
else
i = read_unquoted(i);
}
return vec;
}
template <typename E>
std::vector<std::string_view>
expand_response_files(Context<E> &ctx, char **argv) {
std::vector<std::string_view> vec;
for (i64 i = 0; argv[i]; i++) {
if (argv[i][0] == '@')
append(vec, read_response_file(ctx, argv[i] + 1));
else
vec.push_back(argv[i]);
}
return vec;
}
static std::vector<std::string> add_dashes(std::string name) {
// Multi-letter linker options can be preceded by either a single
// dash or double dashes except ones starting with "o", which must
// be preceded by double dashes. For example, "-omagic" is
// interpreted as "-o magic". If you really want to specify the
// "omagic" option, you have to pass "--omagic".
if (name[0] == 'o')
return {"--" + name};
return {"-" + name, "--" + name};
}
template <typename E>
bool read_arg(Context<E> &ctx, std::span<std::string_view> &args,
std::string_view &arg, std::string name) {
if (name.size() == 1) {
if (args[0] == "-" + name) {
if (args.size() == 1)
Fatal(ctx) << "option -" << name << ": argument missing";
arg = args[1];
args = args.subspan(2);
return true;
}
if (args[0].starts_with("-" + name)) {
arg = args[0].substr(name.size() + 1);
args = args.subspan(1);
return true;
}
return false;
}
for (std::string opt : add_dashes(name)) {
if (args[0] == opt) {
if (args.size() == 1)
Fatal(ctx) << "option -" << name << ": argument missing";
arg = args[1];
args = args.subspan(2);
return true;
}
if (args[0].starts_with(opt + "=")) {
arg = args[0].substr(opt.size() + 1);
args = args.subspan(1);
return true;
}
}
return false;
}
bool read_flag(std::span<std::string_view> &args, std::string name) {
for (std::string opt : add_dashes(name)) {
if (args[0] == opt) {
args = args.subspan(1);
return true;
}
}
return false;
}
static bool read_z_flag(std::span<std::string_view> &args, std::string name) {
if (args.size() >= 2 && args[0] == "-z" && args[1] == name) {
args = args.subspan(2);
return true;
}
if (!args.empty() && args[0] == "-z" + name) {
args = args.subspan(1);
return true;
}
return false;
}
template <typename E>
std::string create_response_file(Context<E> &ctx) {
std::string buf;
std::stringstream out;
std::string cwd = get_current_dir();
out << "-C " << cwd.substr(1) << "\n";
if (cwd != "/") {
out << "--chroot ..";
i64 depth = std::count(cwd.begin(), cwd.end(), '/');
for (i64 i = 1; i < depth; i++)
out << "/..";
out << "\n";
}
for (i64 i = 1; i < ctx.cmdline_args.size(); i++) {
std::string_view arg = ctx.cmdline_args[i];
if (arg == "-repro" || arg == "--repro") {
i++;
continue;
}
out << arg << "\n";
}
return out.str();
}
template <typename E>
static i64 parse_hex(Context<E> &ctx, std::string opt, std::string_view value) {
if (!value.starts_with("0x") && !value.starts_with("0X"))
Fatal(ctx) << "option -" << opt << ": not a hexadecimal number";
value = value.substr(2);
if (value.find_first_not_of("0123456789abcdefABCDEF") != value.npos)
Fatal(ctx) << "option -" << opt << ": not a hexadecimal number";
return std::stol(std::string(value), nullptr, 16);
}
template <typename E>
static i64 parse_number(Context<E> &ctx, std::string opt,
std::string_view value) {
size_t nread;
i64 ret = std::stol(std::string(value), &nread, 0);
if (value.size() != nread)
Fatal(ctx) << "option -" << opt << ": not a number: " << value;
return ret;
}
template <typename E>
static std::vector<u8> parse_hex_build_id(Context<E> &ctx,
std::string_view arg) {
assert(arg.starts_with("0x") || arg.starts_with("0X"));
if (arg.size() % 2)
Fatal(ctx) << "invalid build-id: " << arg;
if (arg.substr(2).find_first_not_of("0123456789abcdefABCDEF") != arg.npos)
Fatal(ctx) << "invalid build-id: " << arg;
arg = arg.substr(2);
auto fn = [](char c) {
if ('0' <= c && c <= '9')
return c - '0';
if ('a' <= c && c <= 'f')
return c - 'a' + 10;
assert('A' <= c && c <= 'F');
return c - 'A' + 10;
};
std::vector<u8> vec(arg.size() / 2);
for (i64 i = 0; i < vec.size(); i++)
vec[i] = (fn(arg[i * 2]) << 4) | fn(arg[i * 2 + 1]);
return vec;
}
static std::vector<std::string_view>
split_by_comma_or_colon(std::string_view str) {
std::vector<std::string_view> vec;
for (;;) {
i64 pos = str.find_first_of(",:");
if (pos == str.npos) {
vec.push_back(str);
break;
}
vec.push_back(str.substr(0, pos));
str = str.substr(pos);
}
return vec;
}
static i64 get_default_thread_count() {
// mold doesn't scale above 32 threads.
int n = tbb::global_control::active_value(
tbb::global_control::max_allowed_parallelism);
return std::min(n, 32);
}
static std::string_view trim(std::string_view str) {
size_t pos = str.find_first_not_of(" \t");
if (pos == str.npos)
return "";
str = str.substr(pos);
pos = str.find_last_not_of(" \t");
if (pos == str.npos)
return str;
return str.substr(0, pos + 1);
}
template <typename E>
static void read_retain_symbols_file(Context<E> &ctx, std::string_view path) {
MemoryMappedFile<E> *mb =
MemoryMappedFile<E>::must_open(ctx, std::string(path));
std::string_view data((char *)mb->data(ctx), mb->size());
ctx.arg.retain_symbols_file.reset(new std::unordered_set<std::string_view>);
while (!data.empty()) {
size_t pos = data.find('\n');
std::string_view name;
if (pos == data.npos) {
name = data;
data = "";
} else {
name = data.substr(0, pos);
data = data.substr(pos + 1);
}
name = trim(name);
if (!name.empty())
ctx.arg.retain_symbols_file->insert(name);
}
}
static bool is_file(std::string_view path) {
struct stat st;
return stat(std::string(path).c_str(), &st) == 0 &&
(st.st_mode & S_IFMT) != S_IFDIR;
}
template <typename E>
void parse_nonpositional_args(Context<E> &ctx,
std::vector<std::string_view> &remaining) {
std::span<std::string_view> args = ctx.cmdline_args;
args = args.subspan(1);
ctx.arg.thread_count = get_default_thread_count();
bool version_shown = false;
while (!args.empty()) {
std::string_view arg;
if (read_flag(args, "help")) {
SyncOut(ctx) << "Usage: " << ctx.cmdline_args[0]
<< " [options] file...\n" << helpmsg;
exit(0);
}
if (read_arg(ctx, args, arg, "o") || read_arg(ctx, args, arg, "output")) {
ctx.arg.output = arg;
} else if (read_arg(ctx, args, arg, "dynamic-linker") ||
read_arg(ctx, args, arg, "I")) {
ctx.arg.dynamic_linker = arg;
} else if (read_arg(ctx, args, arg, "no-dynamic-linker")) {
ctx.arg.dynamic_linker = "";
} else if (read_flag(args, "v")) {
SyncOut(ctx) << get_version_string();
version_shown = true;
} else if (read_flag(args, "version")) {
SyncOut(ctx) << get_version_string();
exit(0);
} else if (read_flag(args, "V")) {
SyncOut(ctx) << get_version_string()
<< "\n Supported emulations:\n elf_x86_64\n elf_i386";
version_shown = true;
} else if (read_flag(args, "export-dynamic") || read_flag(args, "E")) {
ctx.arg.export_dynamic = true;
} else if (read_flag(args, "no-export-dynamic")) {
ctx.arg.export_dynamic = false;
} else if (read_flag(args, "Bsymbolic")) {
ctx.arg.Bsymbolic = true;
} else if (read_flag(args, "Bsymbolic-functions")) {
ctx.arg.Bsymbolic_functions = true;
} else if (read_arg(ctx, args, arg, "exclude-libs")) {
append(ctx.arg.exclude_libs, split_by_comma_or_colon(arg));
} else if (read_arg(ctx, args, arg, "e") ||
read_arg(ctx, args, arg, "entry")) {
ctx.arg.entry = arg;
} else if (read_arg(ctx, args, arg, "Map")) {
ctx.arg.Map = arg;
ctx.arg.print_map = true;
} else if (read_flag(args, "print-map") || read_flag(args, "M")) {
ctx.arg.print_map = true;
} else if (read_flag(args, "static") || read_flag(args, "Bstatic")) {
ctx.arg.is_static = true;
remaining.push_back("-Bstatic");
} else if (read_flag(args, "Bdynamic")) {
ctx.arg.is_static = false;
remaining.push_back("-Bdynamic");
} else if (read_flag(args, "shared") || read_flag(args, "Bshareable")) {
ctx.arg.shared = true;
} else if (read_arg(ctx, args, arg, "spare-dynamic-tags")) {
ctx.arg.spare_dynamic_tags = parse_number(ctx, "spare-dynamic-tags", arg);
} else if (read_flag(args, "demangle")) {
ctx.arg.demangle = true;
} else if (read_flag(args, "no-demangle")) {
ctx.arg.demangle = false;
} else if (read_arg(ctx, args, arg, "y") ||
read_arg(ctx, args, arg, "trace-symbol")) {
ctx.arg.trace_symbol.push_back(arg);
} else if (read_arg(ctx, args, arg, "filler")) {
ctx.arg.filler = parse_hex(ctx, "filler", arg);
} else if (read_arg(ctx, args, arg, "L") ||
read_arg(ctx, args, arg, "library-path")) {
ctx.arg.library_paths.push_back(arg);
} else if (read_arg(ctx, args, arg, "sysroot")) {
ctx.arg.sysroot = arg;
} else if (read_arg(ctx, args, arg, "unique")) {
ctx.arg.unique.reset(new std::regex(glob_to_regex(arg)));
} else if (read_arg(ctx, args, arg, "unresolved-symbols")) {
if (arg == "report-all" || arg == "ignore-in-shared-libs")
ctx.arg.unresolved_symbols = UnresolvedKind::ERROR;
else if (arg == "ignore-all" || arg == "ignore-in-object-files")
ctx.arg.unresolved_symbols = UnresolvedKind::IGNORE;
else
Fatal(ctx) << "unknown --unresolved-symbols argument: " << arg;
} else if (read_arg(ctx, args, arg, "u") ||
read_arg(ctx, args, arg, "undefined")) {
ctx.arg.undefined.push_back(arg);
} else if (read_arg(ctx, args, arg, "init")) {
ctx.arg.init = arg;
} else if (read_arg(ctx, args, arg, "fini")) {
ctx.arg.fini = arg;
} else if (read_arg(ctx, args, arg, "hash-style")) {
if (arg == "sysv") {
ctx.arg.hash_style_sysv = true;
ctx.arg.hash_style_gnu = false;
} else if (arg == "gnu") {
ctx.arg.hash_style_sysv = false;
ctx.arg.hash_style_gnu = true;
} else if (arg == "both") {
ctx.arg.hash_style_sysv = true;
ctx.arg.hash_style_gnu = true;
} else {
Fatal(ctx) << "invalid --hash-style argument: " << arg;
}
} else if (read_arg(ctx, args, arg, "soname") ||
read_arg(ctx, args, arg, "h")) {
ctx.arg.soname = arg;
} else if (read_flag(args, "allow-multiple-definition")) {
ctx.arg.allow_multiple_definition = true;
} else if (read_flag(args, "trace")) {
ctx.arg.trace = true;
} else if (read_flag(args, "eh-frame-hdr")) {
ctx.arg.eh_frame_hdr = true;
} else if (read_flag(args, "no-eh-frame-hdr")) {
ctx.arg.eh_frame_hdr = false;
} else if (read_flag(args, "pie") || read_flag(args, "pic-executable")) {
ctx.arg.pic = true;
ctx.arg.pie = true;
} else if (read_flag(args, "no-pie") ||
read_flag(args, "no-pic-executable")) {
ctx.arg.pic = false;
ctx.arg.pie = false;
} else if (read_flag(args, "relax")) {
ctx.arg.relax = true;
} else if (read_flag(args, "no-relax")) {
ctx.arg.relax = false;
} else if (read_flag(args, "r") || read_flag(args, "relocatable")) {
ctx.arg.relocatable = true;
} else if (read_flag(args, "perf")) {
ctx.arg.perf = true;
} else if (read_flag(args, "stats")) {
ctx.arg.stats = true;
Counter::enabled = true;
} else if (read_arg(ctx, args, arg, "C") ||
read_arg(ctx, args, arg, "directory")) {
ctx.arg.directory = arg;
} else if (read_arg(ctx, args, arg, "chroot")) {
ctx.arg.chroot = arg;
} else if (read_flag(args, "warn-common")) {
ctx.arg.warn_common = true;
} else if (read_flag(args, "no-warn-common")) {
ctx.arg.warn_common = false;
} else if (read_arg(ctx, args, arg, "compress-debug-sections")) {
if (arg == "zlib" || arg == "zlib-gabi")
ctx.arg.compress_debug_sections = COMPRESS_GABI;
else if (arg == "zlib-gnu")
ctx.arg.compress_debug_sections = COMPRESS_GNU;
else if (arg == "none")
ctx.arg.compress_debug_sections = COMPRESS_NONE;
else
Fatal(ctx) << "invalid --compress-debug-sections argument: " << arg;
} else if (read_arg(ctx, args, arg, "wrap")) {
ctx.arg.wrap.insert(arg);
} else if (read_flag(args, "omagic") || read_flag(args, "N")) {
ctx.arg.omagic = true;
ctx.arg.is_static = true;
} else if (read_flag(args, "no-omagic")) {
ctx.arg.omagic = false;
} else if (read_arg(ctx, args, arg, "retain-symbols-file")) {
read_retain_symbols_file(ctx, arg);
} else if (read_flag(args, "repro")) {
ctx.arg.repro = true;
} else if (read_z_flag(args, "now")) {
ctx.arg.z_now = true;
} else if (read_z_flag(args, "lazy")) {
ctx.arg.z_now = false;
} else if (read_z_flag(args, "execstack")) {
ctx.arg.z_execstack = true;
} else if (read_z_flag(args, "noexecstack")) {
ctx.arg.z_execstack = false;
} else if (read_z_flag(args, "relro")) {
ctx.arg.z_relro = true;
} else if (read_z_flag(args, "norelro")) {
ctx.arg.z_relro = false;
} else if (read_z_flag(args, "defs")) {
ctx.arg.z_defs = true;
} else if (read_z_flag(args, "nodefs")) {
ctx.arg.z_defs = false;
} else if (read_z_flag(args, "nodlopen")) {
ctx.arg.z_dlopen = false;
} else if (read_z_flag(args, "nodelete")) {
ctx.arg.z_delete = false;
} else if (read_z_flag(args, "nocopyreloc")) {
ctx.arg.z_copyreloc = false;
} else if (read_z_flag(args, "nodump")) {
ctx.arg.z_dump = false;
} else if (read_z_flag(args, "initfirst")) {
ctx.arg.z_initfirst = true;
} else if (read_z_flag(args, "interpose")) {
ctx.arg.z_interpose = true;
} else if (read_z_flag(args, "muldefs")) {
ctx.arg.allow_multiple_definition = true;
} else if (read_z_flag(args, "keep-text-section-prefix")) {
ctx.arg.z_keep_text_section_prefix = true;
} else if (read_z_flag(args, "nokeep-text-section-prefix")) {
ctx.arg.z_keep_text_section_prefix = false;
} else if (read_z_flag(args, "text")) {
ctx.arg.z_text = true;
} else if (read_z_flag(args, "notext") || read_z_flag(args, "textoff")) {
ctx.arg.z_text = false;
} else if (read_z_flag(args, "origin")) {
ctx.arg.z_origin = true;
} else if (read_flag(args, "no-undefined")) {
ctx.arg.z_defs = true;
} else if (read_flag(args, "fatal-warnings")) {
ctx.arg.fatal_warnings = true;
} else if (read_flag(args, "no-fatal-warnings")) {
ctx.arg.fatal_warnings = false;
} else if (read_flag(args, "fork")) {
ctx.arg.fork = true;
} else if (read_flag(args, "no-fork")) {
ctx.arg.fork = false;
} else if (read_flag(args, "gc-sections")) {
ctx.arg.gc_sections = true;
} else if (read_flag(args, "no-gc-sections")) {
ctx.arg.gc_sections = false;
} else if (read_flag(args, "print-gc-sections")) {
ctx.arg.print_gc_sections = true;
} else if (read_flag(args, "no-print-gc-sections")) {
ctx.arg.print_gc_sections = false;
} else if (read_arg(ctx, args, arg, "icf")) {
if (arg == "all")
ctx.arg.icf = true;
else if (arg == "none")
ctx.arg.icf = false;
else
Fatal(ctx) << "unknown --icf argument: " << arg;
} else if (read_flag(args, "no-icf")) {
ctx.arg.icf = false;
} else if (read_arg(ctx, args, arg, "image-base")) {
ctx.arg.image_base = parse_number(ctx, "image-base", arg);
} else if (read_flag(args, "quick-exit")) {
ctx.arg.quick_exit = true;
} else if (read_flag(args, "no-quick-exit")) {
ctx.arg.quick_exit = false;
} else if (read_flag(args, "print-icf-sections")) {
ctx.arg.print_icf_sections = true;
} else if (read_flag(args, "no-print-icf-sections")) {
ctx.arg.print_icf_sections = false;
} else if (read_flag(args, "quick-exit")) {
ctx.arg.quick_exit = true;
} else if (read_flag(args, "no-quick-exit")) {
ctx.arg.quick_exit = false;
} else if (read_arg(ctx, args, arg, "thread-count")) {
ctx.arg.thread_count = parse_number(ctx, "thread-count", arg);
} else if (read_flag(args, "threads")) {
ctx.arg.thread_count = get_default_thread_count();
} else if (read_flag(args, "no-threads")) {
ctx.arg.thread_count = 1;
} else if (read_flag(args, "discard-all") || read_flag(args, "x")) {
ctx.arg.discard_all = true;
} else if (read_flag(args, "discard-locals") || read_flag(args, "X")) {
ctx.arg.discard_locals = true;
} else if (read_flag(args, "strip-all") || read_flag(args, "s")) {
ctx.arg.strip_all = true;
} else if (read_flag(args, "strip-debug") || read_flag(args, "S")) {
ctx.arg.strip_all = true;
} else if (read_flag(args, "warn-unresolved-symbols")) {
ctx.arg.unresolved_symbols = UnresolvedKind::WARN;
} else if (read_flag(args, "error-unresolved-symbols")) {
ctx.arg.unresolved_symbols = UnresolvedKind::ERROR;
} else if (read_arg(ctx, args, arg, "rpath")) {
if (!ctx.arg.rpaths.empty())
ctx.arg.rpaths += ":";
ctx.arg.rpaths += arg;
} else if (read_arg(ctx, args, arg, "R")) {
if (is_file(arg))
Fatal(ctx) << "-R" << arg
<< ": -R as an alias for --just-symbols is not supported";
if (!ctx.arg.rpaths.empty())
ctx.arg.rpaths += ":";
ctx.arg.rpaths += arg;
} else if (read_flag(args, "build-id")) {
ctx.arg.build_id.kind = BuildId::HASH;
ctx.arg.build_id.hash_size = 20;
} else if (read_arg(ctx, args, arg, "build-id")) {
if (arg == "none") {
ctx.arg.build_id.kind = BuildId::NONE;
} else if (arg == "uuid") {
ctx.arg.build_id.kind = BuildId::UUID;
} else if (arg == "md5") {
ctx.arg.build_id.kind = BuildId::HASH;
ctx.arg.build_id.hash_size = 16;
} else if (arg == "sha1") {
ctx.arg.build_id.kind = BuildId::HASH;
ctx.arg.build_id.hash_size = 20;
} else if (arg == "sha256") {
ctx.arg.build_id.kind = BuildId::HASH;
ctx.arg.build_id.hash_size = 32;
} else if (arg.starts_with("0x") || arg.starts_with("0X")) {
ctx.arg.build_id.kind = BuildId::HEX;
ctx.arg.build_id.value = parse_hex_build_id(ctx, arg);
} else {
Fatal(ctx) << "invalid --build-id argument: " << arg;
}
} else if (read_flag(args, "no-build-id")) {
ctx.arg.build_id.kind = BuildId::NONE;
} else if (read_arg(ctx, args, arg, "auxiliary") ||
read_arg(ctx, args, arg, "f")) {
ctx.arg.auxiliary.push_back(arg);
} else if (read_arg(ctx, args, arg, "filter") ||
read_arg(ctx, args, arg, "F")) {
ctx.arg.filter.push_back(arg);
} else if (read_flag(args, "preload")) {
ctx.arg.preload = true;
} else if (read_arg(ctx, args, arg, "O")) {
} else if (read_flag(args, "O0")) {
} else if (read_flag(args, "O1")) {
} else if (read_flag(args, "O2")) {
} else if (read_flag(args, "verbose")) {
} else if (read_arg(ctx, args, arg, "plugin")) {
} else if (read_arg(ctx, args, arg, "plugin-opt")) {
} else if (read_flag(args, "color-diagnostics")) {
} else if (read_flag(args, "gdb-index")) {
} else if (read_arg(ctx, args, arg, "m")) {
} else if (read_flag(args, "eh-frame-hdr")) {
} else if (read_flag(args, "start-group")) {
} else if (read_flag(args, "end-group")) {
} else if (read_flag(args, "(")) {
} else if (read_flag(args, ")")) {
} else if (read_flag(args, "fatal-warnings")) {
} else if (read_flag(args, "enable-new-dtags")) {
} else if (read_flag(args, "disable-new-dtags")) {
} else if (read_flag(args, "nostdlib")) {
} else if (read_flag(args, "allow-shlib-undefined")) {
} else if (read_flag(args, "no-allow-shlib-undefined")) {
} else if (read_flag(args, "no-add-needed")) {
} else if (read_flag(args, "no-copy-dt-needed-entries")) {
} else if (read_flag(args, "no-undefined-version")) {
} else if (read_arg(ctx, args, arg, "sort-section")) {
} else if (read_flag(args, "sort-common")) {
} else if (read_flag(args, "warn-once")) {
} else if (read_flag(args, "nodefaultlibs")) {
} else if (read_flag(args, "warn-constructors")) {
} else if (read_arg(ctx, args, arg, "rpath-link")) {
} else if (read_z_flag(args, "combreloc")) {
} else if (read_z_flag(args, "nocombreloc")) {
} else if (read_arg(ctx, args, arg, "version-script")) {
remaining.push_back("--version-script");
remaining.push_back(arg);
} else if (read_arg(ctx, args, arg, "dynamic-list")) {
remaining.push_back("--dynamic-list");
remaining.push_back(arg);
} else if (read_flag(args, "as-needed")) {
remaining.push_back("-as-needed");
} else if (read_flag(args, "no-as-needed")) {
remaining.push_back("-no-as-needed");
} else if (read_flag(args, "whole-archive")) {
remaining.push_back("-whole-archive");
} else if (read_flag(args, "no-whole-archive")) {
remaining.push_back("-no-whole-archive");
} else if (read_arg(ctx, args, arg, "l")) {
remaining.push_back("-l");
remaining.push_back(arg);
} else if (read_arg(ctx, args, arg, "script") ||
read_arg(ctx, args, arg, "T")) {
remaining.push_back(arg);
} else if (read_flag(args, "push-state")) {
remaining.push_back("-push-state");
} else if (read_flag(args, "pop-state")) {
remaining.push_back("-pop-state");
} else {
if (args[0] == "-z" && args.size() >= 2)
Fatal(ctx) << "mold: unknown command line option: -z " << args[1];
if (args[0][0] == '-')
Fatal(ctx) << "mold: unknown command line option: " << args[0];
remaining.push_back(args[0]);
args = args.subspan(1);
}
}
if (ctx.arg.shared) {
ctx.arg.pic = true;
ctx.arg.dynamic_linker = "";
}
if (ctx.arg.pic)
ctx.arg.image_base = 0;
if (ctx.arg.retain_symbols_file) {
ctx.arg.strip_all = false;
ctx.arg.discard_all = false;
}
if (ctx.arg.relocatable)
ctx.arg.is_static = true;
if (!ctx.arg.shared) {
if (!ctx.arg.filter.empty())
Fatal(ctx) << "-filter may not be used without -shared";
if (!ctx.arg.auxiliary.empty())
Fatal(ctx) << "-auxiliary may not be used without -shared";
}
if (char *env = getenv("MOLD_REPRO"); env && env[0])
ctx.arg.repro = true;
if (ctx.arg.output.empty())
ctx.arg.output = "a.out";
if (version_shown && remaining.empty())
exit(0);
}
#define INSTANTIATE(E) \
template \
std::vector<std::string_view> \
expand_response_files(Context<E> &ctx, char **argv); \
\
template \
bool read_arg(Context<E> &ctx, std::span<std::string_view> &args, \
std::string_view &arg, \
std::string name); \
\
template std::string create_response_file(Context<E> &ctx); \
\
template \
void parse_nonpositional_args(Context<E> &ctx, \
std::vector<std::string_view> &remaining)
INSTANTIATE(X86_64);
INSTANTIATE(I386);
-110
View File
@@ -1,110 +0,0 @@
// This file implements a multi-threaded zlib compression routine.
//
// Multiple pieces of raw compressed data in zlib-format can be merged
// just by concatenation as long as each zlib stream is flushed with
// Z_SYNC_FLUSH. In this file, we split input data into multiple
// shards, compress them individually and concatenate them. We then
// append a header, a trailer and a checksum so that the concatenated
// data is valid zlib-format data.
//
// Using threads to compress data has a downside. Since the dictionary
// is reset on boundaries of shards, compression ratio is sacrificed
// a little bit. However, if a shard size is large enough, that loss
// is negligible in practice.
#include "mold.h"
#include <tbb/parallel_for_each.h>
#include <zlib.h>
static constexpr i64 SHARD_SIZE = 1024 * 1024;
static std::vector<std::string_view> split(std::string_view input) {
std::vector<std::string_view> shards;
while (input.size() >= SHARD_SIZE) {
shards.push_back(input.substr(0, SHARD_SIZE));
input = input.substr(SHARD_SIZE);
}
if (!input.empty())
shards.push_back(input);
return shards;
}
static std::vector<u8> do_compress(std::string_view input) {
// Initialize zlib stream. Since debug info is generally compressed
// pretty well, we chose compression level 3.
z_stream strm;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
int r = deflateInit2(&strm, 3, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY);
assert(r == Z_OK);
// Set an input buffer
strm.avail_in = input.size();
strm.next_in = (u8 *)input.data();
// Set an output buffer. deflateBound() returns an upper bound
// on the compression size. +16 for Z_SYNC_FLUSH.
std::vector<u8> buf(deflateBound(&strm, strm.avail_in) + 16);
strm.avail_out = buf.size();
strm.next_out = buf.data();
r = deflate(&strm, Z_SYNC_FLUSH);
assert(r == Z_OK);
assert(strm.avail_out > 0);
buf.resize(buf.size() - strm.avail_out);
deflateEnd(&strm);
return buf;
}
Compressor::Compressor(std::string_view input) {
std::vector<std::string_view> inputs = split(input);
std::vector<u64> adlers(inputs.size());
shards.resize(inputs.size());
// Compress each shard
tbb::parallel_for((i64)0, (i64)inputs.size(), [&](i64 i) {
adlers[i] = adler32(1, (u8 *)inputs[i].data(), inputs[i].size());
shards[i] = do_compress(inputs[i]);
});
// Combine checksums
checksum = adlers[0];
for (i64 i = 1; i < inputs.size(); i++)
checksum = adler32_combine(checksum, adlers[i], inputs[i].size());
}
i64 Compressor::size() const {
i64 size = 2; // +2 for header
for (const std::vector<u8> &shard : shards)
size += shard.size();
return size + 6; // +6 for trailer and checksum
}
void Compressor::write_to(u8 *buf) {
// Write a zlib-format header
buf[0] = 0x78;
buf[1] = 0x9c;
// Copy compressed data
std::vector<i64> offsets(shards.size());
offsets[0] = 2; // +2 for header
for (i64 i = 1; i < shards.size(); i++)
offsets[i] = offsets[i - 1] + shards[i - 1].size();
tbb::parallel_for((i64)0, (i64)shards.size(), [&](i64 i) {
memcpy(&buf[offsets[i]], shards[i].data(), shards[i].size());
});
// Write a trailer
u8 *end = buf + size();
end[-6] = 3;
end[-5] = 0;
// Write a checksum
write32be(end - 4, checksum);
}
Executable
+219
View File
@@ -0,0 +1,219 @@
#!/bin/bash
#
# This script creates a mold binary distribution. The output is written in
# `dist` directory as `mold-$version-$arch-linux.tar.gz` (e.g.,
# `mold-1.0.3-x86_64-linux.tar.gz`).
#
# The mold executable created by this script is statically linked to
# libstdc++ but dynamically linked to libc, libm, libz, and librt, as
# these libraries almost always exist on any Linux system. We can't
# statically link libc because doing so would disable dlopen(), which is
# necessary to open the LTO linker plugin.
#
# This script aims to produce reproducible outputs. That means if you run
# the script twice on the same git commit, it should produce bit-by-bit
# identical binary files. This property is crucial as a countermeasure
# against supply chain attacks. With this, you can verify that the binary
# files distributed on the GitHub release pages are created from the
# commit with release tags by rebuilding the binaries yourself.
#
# Debian provides snapshot.debian.org to host all historical binary
# packages. We use it to construct Podman images pinned to a
# particular timestamp.
#
# We aim to use a reasonably old Debian version because we'll dynamically
# link glibc to mold, and a binary linked against a newer version of glibc
# won't work on a system with an older version of glibc.
#
# We want to build mold with Clang rather than GCC because mold's
# Identical Code Folding works best with the LLVM address significance
# table (.llvm_addrsig). Building a release binary with GCC yields a
# slightly larger binary than Clang's.
#
# We need a recent version of Clang to build mold. If it's not available
# via apt-get, we'll build it ourselves.
#
# You may need to install qemu-user-static package to build non-native
# binaries.
set -e -x
cd "$(dirname $0)"
usage() {
echo "Usage: $0 [ x86_64 | aarch64 | arm | riscv64 | ppc64le | s390x | loongarch64 ]"
exit 1
}
case $# in
0)
arch=$(uname -m)
if [ $arch = arm64 ]; then
arch=aarch64
elif [[ $arch = arm* ]]; then
arch=arm
fi
;;
1)
arch="$1"
;;
*)
usage
esac
# Create a Podman image.
if [ "$GITHUB_REPOSITORY" = '' ]; then
image=mold-builder-$arch
image_build="podman build --arch $arch -t $image -"
else
# If this script is running on GitHub Actions, we want to cache
# the created container image in GitHub's container repostiory.
image=ghcr.io/$GITHUB_REPOSITORY/mold-builder-$arch
image_build="podman build --arch $arch -t $image --output=type=registry --layers --cache-to $image --cache-from $image -"
fi
case $arch in
x86_64)
# Debian 9 (Stretch) released in June 2017.
# We use a Google-provided mirror (gcr.io) of the official Docker hub
# (docker.io) because docker.io has a strict rate limit policy.
cat <<EOF | $image_build
FROM mirror.gcr.io/library/debian:stretch@sha256:c5c5200ff1e9c73ffbf188b4a67eb1c91531b644856b4aefe86a58d2f0cb05be
ENV DEBIAN_FRONTEND=noninteractive TZ=UTC
RUN sed -i -e '/^deb/d' -e 's/^# deb /deb [trusted=yes] /g' /etc/apt/sources.list && \
echo 'Acquire::Retries "10"; Acquire::http::timeout "10"; Acquire::Check-Valid-Until "false";' > /etc/apt/apt.conf.d/80-retries && \
apt-get update && \
apt-get install -y --no-install-recommends wget file make gcc g++ zlib1g-dev libssl-dev && \
rm -rf /var/lib/apt/lists
# Build CMake 3.27
RUN mkdir /build && \
cd /build && \
wget -O- --no-check-certificate --progress=dot:mega https://cmake.org/files/v3.27/cmake-3.27.7.tar.gz | tar xzf - --strip-components=1 && \
./bootstrap --parallel=\$(nproc) && \
make -j\$(nproc) && \
make install && \
rm -rf /build
# Build GCC 14
RUN mkdir /build && \
cd /build && \
wget -O- --no-check-certificate --progress=dot:mega https://ftpmirror.gnu.org/gcc/gcc-14.2.0/gcc-14.2.0.tar.gz | tar xzf - --strip-components=1 && \
mkdir gmp mpc mpfr && \
wget -O- --no-check-certificate --progress=dot:mega https://ftpmirror.gnu.org/gmp/gmp-6.3.0.tar.gz | tar xzf - --strip-components=1 -C gmp && \
wget -O- --no-check-certificate --progress=dot:mega https://ftpmirror.gnu.org/mpc/mpc-1.3.1.tar.gz | tar xzf - --strip-components=1 -C mpc && \
wget -O- --no-check-certificate --progress=dot:mega https://ftpmirror.gnu.org/mpfr/mpfr-4.2.1.tar.gz | tar xzf - --strip-components=1 -C mpfr && \
./configure --prefix=/usr --enable-languages=c,c++ --disable-bootstrap --disable-multilib && \
make -j\$(nproc) && \
make install && \
ln -sf /usr/lib64/libstdc++.so.6 /usr/lib/x86_64-linux-gnu/libstdc++.so.6 && \
rm -rf /build
# Build GNU binutils 2.43
RUN mkdir /build && \
cd /build && \
wget -O- --no-check-certificate --progress=dot:mega https://ftpmirror.gnu.org/binutils/binutils-2.43.tar.gz | tar xzf - --strip-components=1 && \
./configure --prefix=/usr && \
make -j\$(nproc) && \
make install && \
rm -fr /build
# Build Python 3.12.7
RUN mkdir /build && \
cd /build && \
wget -O- --no-check-certificate --progress=dot:mega https://www.python.org/ftp/python/3.12.7/Python-3.12.7.tgz | tar xzf - --strip-components=1 && \
./configure && \
make -j\$(nproc) && \
make install && \
rm -rf /build
# Build LLVM 19
RUN mkdir /build && \
cd /build && \
wget -O- --no-check-certificate --progress=dot:mega https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-19.1.7.tar.gz | tar xzf - --strip-components=1 && \
mkdir b && \
cd b && \
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS=clang ../llvm && \
cmake --build . -j\$(nproc) && \
cmake --install . --strip && \
rm -rf /build
EOF
;;
aarch64 | arm | ppc64le | s390x)
# Debian 11 (Bullseye) released in August 2021
#
# We don't want to build Clang for these targets with Qemu becuase
# that'd take extremely long time. Also I believe old build machines
# are usually x86-64.
cat <<EOF | $image_build
FROM mirror.gcr.io/library/debian:bullseye-20240904@sha256:8ccc486c29a3ad02ad5af7f1156e2152dff3ba5634eec9be375269ef123457d8
ENV DEBIAN_FRONTEND=noninteractive TZ=UTC
RUN sed -i -e '/^deb/d' -e 's/^# deb /deb [trusted=yes] /g' /etc/apt/sources.list && \
echo 'Acquire::Retries "10"; Acquire::http::timeout "10"; Acquire::Check-Valid-Until "false";' > /etc/apt/apt.conf.d/80-retries && \
apt-get update && \
apt-get install -y --no-install-recommends build-essential gcc-10 g++-10 clang-16 cmake && \
ln -sf /usr/bin/clang-16 /usr/bin/clang && \
ln -sf /usr/bin/clang++-16 /usr/bin/clang++ && \
rm -rf /var/lib/apt/lists
EOF
;;
riscv64)
cat <<EOF | $image_build
FROM mirror.gcr.io/riscv64/debian:unstable-20240926@sha256:25654919c2926f38952cdd14b3300d83d13f2d820715f78c9f4b7a1d9399bf48
ENV DEBIAN_FRONTEND=noninteractive TZ=UTC
RUN sed -i -e '/^URIs/d' -e 's/^# http/URIs: http/' /etc/apt/sources.list.d/debian.sources && \
echo 'Acquire::Retries "10"; Acquire::http::timeout "10"; Acquire::Check-Valid-Until "false";' > /etc/apt/apt.conf.d/80-retries && \
apt-get update && \
apt-get install -y --no-install-recommends build-essential gcc-14 g++-14 clang-18 cmake && \
ln -sf /usr/bin/clang-18 /usr/bin/clang && \
ln -sf /usr/bin/clang++-18 /usr/bin/clang++ && \
rm -rf /var/lib/apt/lists
EOF
;;
loongarch64)
# LoongArch build is not reproducible yet
cat <<EOF | $image_build
FROM mirror.gcr.io/loongarch64/debian:sid
ENV DEBIAN_FRONTEND=noninteractive TZ=UTC
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential gcc-14 g++-14 clang-19 cmake && \
ln -sf /usr/bin/clang-19 /usr/bin/clang && \
ln -sf /usr/bin/clang++-19 /usr/bin/clang++ && \
rm -rf /var/lib/apt/lists
EOF
;;
*)
usage
;;
esac
version=$(sed -n 's/^project(mold VERSION \(.*\))/\1/p' CMakeLists.txt)
dest=mold-$version-$arch-linux
# Source tarballs available on GitHub don't contain .git history.
# Clone the repo if missing.
[ -d .git ] || git clone --branch v$version --depth 1 --bare https://github.com/rui314/mold .git
# We use the timestamp of the last Git commit as the file timestamp
# for build artifacts.
timestamp="$(git log -1 --format=%ci)"
# Build mold in a container.
mkdir -p dist
podman run --arch $arch -it --rm --userns=host --pids-limit=-1 --network=none \
-v "$(pwd):/mold:ro" -v "$(pwd)/dist:/dist" $image bash -c "
set -e
mkdir /build
cd /build
cmake -DCMAKE_BUILD_TYPE=Release -DMOLD_MOSTLY_STATIC=1 -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ /mold
cmake --build . -j\$(nproc)
cmake --install .
cmake -DMOLD_USE_MOLD=1 .
cmake --build . -j\$(nproc)
ctest --output-on-failure -j\$(nproc)
cmake --install . --prefix $dest --strip
find $dest -print | xargs touch --no-dereference --date='$timestamp'
find $dest -print | sort | tar -cf - --no-recursion --files-from=- | gzip -9nc > /dist/$dest.tar.gz
cp mold /dist
sha256sum /dist/$dest.tar.gz
"
+2 -2
View File
@@ -31,7 +31,7 @@ If a program is statically-linked, there's no dynamic loader that
rewrites the GOT entries. Therefore, if a program is
statically-linked, a libc's startup routine does that on behalf of the
dynamic loader. Concretely, a startup routine interprets all dynamic
relocations between `__rela_iplt_start` and `__rela_iplt_start`
relocations between `__rela_iplt_start` and `__rela_iplt_stop`
symbols. It is linker's responsibility to emit dynamic relocations
for IFUNC symbols even if it is linking a statically-linked program
and mark the beginning and the ending of a `.rela.dyn` section with
@@ -41,7 +41,7 @@ The bug was my linker didn't define `__rela_iplt_start` and
`__rela_iplt_stop` symbols. Since these symbols are weak, they are
initialized to zero. From the point of the initializer function,
there's no dynamic relocations between `__rela_iplt_start` and
`__rela_iplt_start` symbols. That left GOT entries for IFUNC symbols
`__rela_iplt_stop` symbols. That left GOT entries for IFUNC symbols
untouched.
The proper fix was to emit dynamic relocations for IFUNC symbols and
+1
View File
@@ -0,0 +1 @@
<svg version="1.1" viewBox="0.0 0.0 600.0 371.0" fill="none" stroke="none" stroke-linecap="square" stroke-miterlimit="10" width="600" height="371" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"><path fill="#ffffff" d="M0 0L600.0 0L600.0 371.0L0 371.0L0 0Z" fill-rule="nonzero"/><path stroke="#333333" stroke-width="1.0" stroke-linecap="butt" d="M82.5 275.5L581.5 275.5" fill-rule="nonzero"/><path stroke="#cccccc" stroke-width="1.0" stroke-linecap="butt" d="M82.5 231.5L581.5 231.5" fill-rule="nonzero"/><path stroke="#cccccc" stroke-width="1.0" stroke-linecap="butt" d="M82.5 186.5L581.5 186.5" fill-rule="nonzero"/><path stroke="#cccccc" stroke-width="1.0" stroke-linecap="butt" d="M82.5 142.5L581.5 142.5" fill-rule="nonzero"/><path stroke="#cccccc" stroke-width="1.0" stroke-linecap="butt" d="M82.5 98.5L581.5 98.5" fill-rule="nonzero"/><path stroke="#cccccc" stroke-width="1.0" stroke-linecap="butt" d="M82.5 53.5L581.5 53.5" fill-rule="nonzero"/><clipPath id="id_0"><path d="M82.55 53.916668L581.45 53.916668L581.45 275.45L82.55 275.45L82.55 53.916668Z" clip-rule="nonzero"/></clipPath><path stroke="#000000" stroke-width="2.0" stroke-linecap="butt" stroke-opacity="0.0" clip-path="url(#id_0)" d="M158.0 275.0L136.0 275.0L136.0 229.0C136.0 227.89543 136.89543 227.0 138.0 227.0L156.0 227.0C157.10457 227.0 158.0 227.89543 158.0 229.0Z" fill-rule="nonzero"/><path fill="#4285f4" clip-path="url(#id_0)" d="M158.0 275.0L136.0 275.0L136.0 229.0C136.0 227.89543 136.89543 227.0 138.0 227.0L156.0 227.0C157.10457 227.0 158.0 227.89543 158.0 229.0Z" fill-rule="nonzero"/><path stroke="#000000" stroke-width="2.0" stroke-linecap="butt" stroke-opacity="0.0" clip-path="url(#id_0)" d="M307.0 275.0L285.0 275.0L285.0 91.0C285.0 89.89543 285.89542 89.0 287.0 89.0L305.0 89.0C306.10458 89.0 307.0 89.89543 307.0 91.0Z" fill-rule="nonzero"/><path fill="#4285f4" clip-path="url(#id_0)" d="M307.0 275.0L285.0 275.0L285.0 91.0C285.0 89.89543 285.89542 89.0 287.0 89.0L305.0 89.0C306.10458 89.0 307.0 89.89543 307.0 91.0Z" fill-rule="nonzero"/><path stroke="#000000" stroke-width="2.0" stroke-linecap="butt" stroke-opacity="0.0" clip-path="url(#id_0)" d="M182.0 275.0L160.0 275.0L160.0 244.0C160.0 242.89543 160.89543 242.0 162.0 242.0L180.0 242.0C181.10457 242.0 182.0 242.89543 182.0 244.0Z" fill-rule="nonzero"/><path fill="#ea4335" clip-path="url(#id_0)" d="M182.0 275.0L160.0 275.0L160.0 244.0C160.0 242.89543 160.89543 242.0 162.0 242.0L180.0 242.0C181.10457 242.0 182.0 242.89543 182.0 244.0Z" fill-rule="nonzero"/><path stroke="#000000" stroke-width="2.0" stroke-linecap="butt" stroke-opacity="0.0" clip-path="url(#id_0)" d="M331.0 275.0L309.0 275.0L309.0 131.0C309.0 129.89543 309.89542 129.0 311.0 129.0L329.0 129.0C330.10458 129.0 331.0 129.89543 331.0 131.0Z" fill-rule="nonzero"/><path fill="#ea4335" clip-path="url(#id_0)" d="M331.0 275.0L309.0 275.0L309.0 131.0C309.0 129.89543 309.89542 129.0 311.0 129.0L329.0 129.0C330.10458 129.0 331.0 129.89543 331.0 131.0Z" fill-rule="nonzero"/><path stroke="#000000" stroke-width="2.0" stroke-linecap="butt" stroke-opacity="0.0" clip-path="url(#id_0)" d="M480.0 275.0L458.0 275.0L458.0 156.0C458.0 154.89543 458.89542 154.0 460.0 154.0L478.0 154.0C479.10458 154.0 480.0 154.89543 480.0 156.0Z" fill-rule="nonzero"/><path fill="#ea4335" clip-path="url(#id_0)" d="M480.0 275.0L458.0 275.0L458.0 156.0C458.0 154.89543 458.89542 154.0 460.0 154.0L478.0 154.0C479.10458 154.0 480.0 154.89543 480.0 156.0Z" fill-rule="nonzero"/><path stroke="#000000" stroke-width="2.0" stroke-linecap="butt" stroke-opacity="0.0" clip-path="url(#id_0)" d="M206.0 275.0L184.0 275.0L184.0 270.0C184.0 268.89542 184.89543 268.0 186.0 268.0L204.0 268.0C205.10457 268.0 206.0 268.89542 206.0 270.0Z" fill-rule="nonzero"/><path fill="#fbbc04" clip-path="url(#id_0)" d="M206.0 275.0L184.0 275.0L184.0 270.0C184.0 268.89542 184.89543 268.0 186.0 268.0L204.0 268.0C205.10457 268.0 206.0 268.89542 206.0 270.0Z" fill-rule="nonzero"/><path stroke="#000000" stroke-width="2.0" stroke-linecap="butt" stroke-opacity="0.0" clip-path="url(#id_0)" d="M355.0 275.0L333.0 275.0L333.0 254.0C333.0 252.89543 333.89542 252.0 335.0 252.0L353.0 252.0C354.10458 252.0 355.0 252.89543 355.0 254.0Z" fill-rule="nonzero"/><path fill="#fbbc04" clip-path="url(#id_0)" d="M355.0 275.0L333.0 275.0L333.0 254.0C333.0 252.89543 333.89542 252.0 335.0 252.0L353.0 252.0C354.10458 252.0 355.0 252.89543 355.0 254.0Z" fill-rule="nonzero"/><path stroke="#000000" stroke-width="2.0" stroke-linecap="butt" stroke-opacity="0.0" clip-path="url(#id_0)" d="M504.0 275.0L482.0 275.0L482.0 250.0C482.0 248.89543 482.89542 248.0 484.0 248.0L502.0 248.0C503.10458 248.0 504.0 248.89543 504.0 250.0Z" fill-rule="nonzero"/><path fill="#fbbc04" clip-path="url(#id_0)" d="M504.0 275.0L482.0 275.0L482.0 250.0C482.0 248.89543 482.89542 248.0 484.0 248.0L502.0 248.0C503.10458 248.0 504.0 248.89543 504.0 250.0Z" fill-rule="nonzero"/><path stroke="#000000" stroke-width="2.0" stroke-linecap="butt" stroLine truncated

After

Width:  |  Height:  |  Size: 99 KiB

+46
View File
@@ -0,0 +1,46 @@
# Coding Guidelines
mold is written in C++20, but as is the case with every C++ project,
it has local coding rules. In this document, I'll explain some of them
and try to give justifications for why I chose such rules.
## DOs
- Always use `i64` (which is a type alias for `int64_t` in mold) for
integers unless you have a reason not to. For example, even if you know
that a loop counter won't exceed 100, you should stop thinking about it
and just use `i64`.
Justification: Local variables are usually on CPU registers, so on
64-bit CPUs, there's no performance peanlty on choosing `i64` over
`i32`. Even if a compiler has to spill register values to the stack,
I don't think there's an observable difference between `i32` and
`i64`. Therefore, extra 32 bits are essentially free. On 32-bit CPUs,
they are not free, but that's OK because we are writing mold for modern
computers. mold will still run on 32-bit computers but a bit slowly.
By always using `i64`, we can eliminate the need to think about the
"right" size for each variable. It also reduces the risk of integer
overflow.
Exceptions: If you have to allocate a very large number (e.g. millions)
of the same object, its size matters. In that case, use a smaller type.
## DON'Ts
- Don't use `auto` unless its actual type is obvious in the very narrow
context. Currently, we use `auto` only for lambdas.
Justification: I think `auto` makes code writing easier but code reading
harder, because readers have to make a guess as to what is the actual
type of `auto`. If you are already familiar with the existing codebase,
you may be able to guess it easily, but that's not always the case.
I want to keep the mold codebase friendly to first-time readers.
- Don't over-use inheritance. In mold, most classes don't have parents,
and even if they do, their class hierarchy is very shallow. Currently
its height is just two (i.e. abstract classes and their implementations).
Justification: Designing class hierarchies is fun as it feels like
taxonomy, but I don't think that always help writing code. It looks like
simpler class hierarchy makes its code simpler.
Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

+491
View File
@@ -0,0 +1,491 @@
[This document was written in 2020, and the contents are outdated.
Specifically, we no longer believe that object preloading is a good
idea. That being said, most of the points in this document still hold
even today. Therefore, I'll keep this document as-is.]
## Design and implementation of mold
For the rest of this documentation, I'll explain the design and the
implementation of mold. If you are only interested in using mold, you
don't need to read the below.
### Motivation
Here is why I'm writing a new linker:
- Even though lld has significantly improved the situation, linking is
still one of the slowest steps in a build. It is especially
annoying when I changed one line of code and had to wait for a few
seconds or even more for a linker to complete. It should be
instantaneous. There's a need for a faster linker.
- The number of cores on a PC has increased a lot lately, and this
trend is expected to continue. However, the existing linkers can't
take the advantage of the trend because they don't scale well for more
cores. I have a 64-core/128-thread machine, so my goal is to create
a linker that uses the CPU nicely. mold should be much faster than
other linkers on 4 or 8-core machines too, though.
- It looks to me that the designs of the existing linkers are somewhat
too similar, and I believe there are a lot of drastically different
designs that haven't been explored yet. Developers generally don't
care about linkers as long as they work correctly, and they don't
even think about creating a new one. So there may be lots of low
hanging fruits there in this area.
### Basic design
- In order to achieve a `cp`-like performance, the most important
thing is to fix the layout of an output file as quickly as possible, so
that we can start copying actual data from input object files to an
output file as soon as possible.
- Copying data from input files to an output file is I/O-bounded, so
there should be room for doing computationally-intensive tasks while
copying data from one file to another.
- We should allow the linker to preload object files from disk and
parse them in memory before a complete set of input object files
is ready. To do so, we need
to split the linker into two in such a way that the latter half of
the process finishes as quickly as possible by speculatively parsing
and preprocessing input files in the first half of the process.
- One of the most computationally-intensive stage among linker stages
is symbol resolution. To resolve symbols, we basically have to throw
all symbol strings into a hash table to match undefined symbols with
defined symbols. But this can be done in the preloading stage using
[string interning](https://en.wikipedia.org/wiki/String_interning).
- Object files may contain a special section called a mergeable string
section. The section contains lots of null-terminated strings, and
the linker is expected to gather all mergeable string sections and
merge their contents. So, if two object files contain the same
string literal, for example, the resulting output will contain a
single merged string. This step is computationally intensive, but string
merging can be done in the preloading stage using string interning.
- Static archives (.a files) contain object files, but the static
archive's string table contains only defined symbols of member
object files and lacks other types of symbols. That makes static
archives unsuitable for speculative parsing. Therefore, the linker
should ignore the symbol table of static archive and directly read
static archive members.
- If there's a relocation that uses a GOT of a symbol, then we have to
create a GOT entry for that symbol. Otherwise, we shouldn't. That
means we need to scan all relocation tables to fix the length and
the contents of a .got section. This is computationally intensive,
but this step is parallelizable.
### Linker Script
Linker script is an embedded language for the linker. It is mainly
used to control how input sections are mapped to output sections and
the layout of the output, but it can also do a lot of tricky stuff.
Its feature is useful especially for embedded programming, but it's
also an awfully underdocumented and complex language.
We have to implement a subset of the linker script language anwyay,
because on Linux, /usr/lib/x86_64-linux-gnu/libc.so is (despite its
name) not a shared object file but actually an ASCII file containing
linker script code to load the _actual_ libc.so file. But the feature
set for this purpose is very limited, and it is okay to implement them
to mold.
Besides that, we really don't want to implement the linker script
language. But at the same time, we want to satisfy the user needs that
are currently satisfied with the linker script language. So, what
should we do? Here is my observation:
- Linker script allows doing a lot of tricky stuff, such as specifying
the exact layout of a file, inserting arbitrary bytes between
sections, etc. But most of them can be done with a post-link binary
editing tool (such as `objcopy`).
- It looks like there are two things that truly cannot be done by a
post-link editing tool: (a) mapping input sections to output
sections, and (b) applying relocations.
From the above observation, I believe we need to provide only the
following features instead of the entire linker script language:
- A method to specify how input sections are mapped to output
sections, and
- a method to set addresses to output sections, so that relocations
are applied based on desired addresses.
I believe everything else can be done with a post-link binary editing
tool.
### Details
- As we aim to the 1-second goal for Chromium, every millisecond
counts. We can't ignore the latency of process exit. If we mmap a
lot of files, \_exit(2) is not instantaneous but takes a few hundred
milliseconds because the kernel has to clean up a lot of
resources. As a workaround, we should organize the linker command as
two processes; the first process forks the second process, and the
second process does the actual work. As soon as the second process
writes a result file to a filesystem, it notifies the first process,
and the first process exits. The second process can take time to
exit, because it is not an interactive process.
- At least on Linux, it looks like the filesystem's performance to
allocate new blocks to a new file is the limiting factor when
creating a new large file and filling its contents using mmap.
If you already have a large file in the buffer cache, writing to it is
much faster than creating a new fresh file and writing to it.
Based on this observation, mold overwrites to an existing
executable file if exists. My quick benchmark showed that I could
save 300 milliseconds when creating a 2 GiB output file.
Linux doesn't allow to open an executable for writing if it is
running (you'll get a "text busy" error if you attempt). mold
falls back to the usual way if it fails to open an output file.
- The output from the linker should be deterministic for the sake of
[build reproducibility](https://en.wikipedia.org/wiki/Reproducible_builds)
and ease of debugging. This might add a little bit of overhead to
the linker, but that shouldn't be too much.
- A .build-id, a unique ID embedded to an output file, is usually
computed by applying a cryptographic hash function (e.g. SHA-1) to
an output file. This is a slow step, but we can speed it up by
splitting a file into small chunks, computing SHA-1 for each chunk,
and then computing SHA-1 of the concatenated SHA-1 hashes
(i.e. constructing a [Merkle
Tree](https://en.wikipedia.org/wiki/Merkle_tree) of height 2).
Modern x86 processors have purpose-built instructions for SHA-1 and
can compute SHA-1 pretty quickly at about 2 GiB/s. Using 16
cores, a build-id for a 2 GiB executable can be computed in 60 to 70
milliseconds.
- BFD, gold, and lld support section garbage collection. That is, a
linker runs a mark-sweep garbage collection on an input graph, where
sections are vertices and relocations are edges, to discard all
sections that are not reachable from the entry point symbol
(i.e. `_start`) or a few other root sections. In mold, we are using
multiple threads to mark sections concurrently.
- Similarly, BFD, gold an lld support Identical Comdat Folding (ICF)
as yet another size optimization. ICF merges two or more read-only
sections that happen to have the same contents and relocations.
To do that, we have to find isomorphic subgraphs from larger graphs.
I implemented a new algorithm for mold, which is 5x faster than lld
to do ICF for Chromium (from 5 seconds to 1 second).
- [Intel Threading Building
Blocks](https://github.com/oneapi-src/oneTBB) (TBB) is a good
library for parallel execution and has several concurrent
containers. We are particularly interested in using
`parallel_for_each` and `concurrent_hash_map`.
- TBB provides `tbbmalloc` which works better for multi-threaded
applications than the glib'c malloc, but it looks like
[jemalloc](https://github.com/jemalloc/jemalloc) and
[mimalloc](https://github.com/microsoft/mimalloc) are a little bit
more scalable than `tbbmalloc`.
### Size of the problem
When linking Chrome, a linker reads 3,430,966,844 bytes of data in
total. The data contains the following items:
| Data item | Number
| ------------------------ | ------
| Object files | 30,723
| Public undefined symbols | 1,428,149
| Mergeable strings | 1,579,996
| Comdat groups | 9,914,510
| Regular sections¹ | 10,345,314
| Public defined symbols | 10,512,135
| Symbols | 23,953,607
| Sections | 27,543,225
| Relocations against SHF_ALLOC sections | 39,496,375
| Relocations | 62,024,719
¹ Sections that have to be copied from input object files to an
output file. Sections that contain relocations or symbols are for
example excluded.
### Internals
In this section, I'll explain the internals of mold linker.
#### A brief history of Unix and the Unix linker
Conceptually, what a linker does is pretty simple. A compiler compiles
a fragment of a program (a single source file) into a fragment of
machine code and data (an object file, which typically has the .o
extension), and a linker stitches them together into a single
executable or a shared library image.
In reality, modern linkers for Unix-like systems are much more
complicated than the naive understanding because they have gradually
gained one feature at a time over the 50 years history of Unix, and
they are now something like a bag of lots of miscellaneous features in
which none of the features is more important than the others. It is
very easy to miss the forest for the trees, since for those who don't
know the details of the Unix linker, it is not clear which feature is
essential and which is not.
That being said, one thing is clear that at any point of Unix history,
a Unix linker has a coherent feature set for the Unix of that age. So,
let me entangle the history to see how the operating system, runtime,
and linker have gained features that we see today. That should give
you an idea of why a particular feature has been added to a linker in the
first place.
1. Original Unix didn't support shared libraries, and a program was
always loaded to a fixed address. An executable was something like
a memory dump that was just loaded to a particular address by the
kernel. After loading, the kernel started executing the program by
setting the instruction pointer to a particular address.
The most essential feature for any linker is relocation processing.
The original Unix linker of course supported that. Let me explain
what that is.
Individual object files are inevitably incomplete as a program,
because when a compiler created them, it only see a part of an
entire program. For example, if an object file contains a function
call that refers to another object file, the `call` instruction in the
object cannot be complete, as the compiler has no idea as to what
is the called function's address. To deal with this, the compiler
emits a placeholder value (typically just zero) instead of a real
address and leaves metadata in an object file saying "fix offset X
of this file with an address of Y". That metadata is called
"relocation". Relocations are typically processed by the linker.
It is easy for a linker to apply relocations for the original Unix
because a program is always loaded to a fixed address. It exactly
knows the addresses of all functions and data when linking a
program.
Static library support, which is still an important feature of Unix
linker, also dates back to this early period of Unix history.
To understand what it is, imagine that you are trying to compile
a program for the early Unix. You don't want to waste time to
compile libc functions every time you compile your program (the
computers of the era were incredibly slow), so you have already
placed each libc function into a separate source file and compiled
them individually. That means you have object files for each libc
function, e.g., printf.o, scanf.o, atoi.o, write.o, etc.
Given this configuration, all you have to do to link your program
against libc functions is to pick up the right set of libc object
files and give them to the linker along with the object files of your
program. But, keeping the linker command line in sync with the
libc functions you are using in your program is bothersome. You can
be conservative; you can specify all libc object files to the
command line, but that leads to program bloat because the linker
unconditionally link all object files given to it no matter whether
they are used or not. So, a new feature was added to the linker to
fix the problem. That is the static library, which is also called
the archive file.
An archive file is just a bundle of object files, just like zip
file but in an uncompressed form. An archive file typically has the
.a file extension and named after its contents. For example, the
archive file containing all libc objects is named `libc.a`.
If you pass an archive file along with other object files to the
linker, the linker pulls out an object file from the archive _only
when_ it is referenced by other object files. In other words,
unlike object files directly given to a linker, object files
wrapped in an archive are not linked to the output by default.
An archive works as a supplement to complete your program.
Even today, you can still find a libc archive file. Run `ar t
/usr/lib/x86_64-linux-gnu/libc.a` on Linux should give you a list
of object files in the libc archive.
2. In the '80s, Sun Microsystems, a leading commercial Unix vendor at the
time, added shared library support to their Unix variant, SunOS.
(This section is incomplete.)
### Concurrency strategy
In this section, I'll explain the high-level concurrency strategy of
mold.
In most places, mold adopts data parallelism. That is, we have a huge
number of pieces of data of the same kind, and we process each of them
individually using parallel for-loop. For example, after identifying
the exact set of input object files, we need to scan all relocation
tables to determine the sizes of .got and .plt sections. We do that
using a parallel for-loop. The granularity of parallel processing in
this case is the relocation table.
Data parallelism is very efficient and scalable because there's no
need for threads to communicate with each other while working on each
element of data. In addition to that, data parallelism is easy to
understand, as it is just a for-loop in which multiple iterations may
be executed in parallel. We don't use high-level communication or
synchronization mechanisms such as channels, futures, promises,
latches or something like that in mold.
In some cases, we need to share a little bit of data between threads
while executing a parallel for-loop. For example, the loop to scan
relocations turns on "requires GOT" or "requires PLT" flags in a
symbol. Symbol is a shared resource, and writing to them from multiple
threads without synchronization is unsafe. To deal with it, we made
the flag an atomic variable.
The other common pattern you can find in mold which is build on top of
the parallel for-loop is the map-reduce pattern. That is, we run a
parallel for-loop on a large data set to produce a small data set and
process the small data set with a single thread. Let me take a
build-id computation as an example. Build-id is typically computed by
applying a cryptographic hash function such as SHA-1 on a linker's
output file. To compute it, we first consider an output as a sequence
of 1 MiB blocks and compute a SHA-1 hash for each block in parallel.
Then, we concatenate the SHA-1 hashes and compute a SHA-1 hash on the
hashes to get a final build-id.
Finally, we use concurrent hashmap at a few places in mold. Concurrent
hashmap is a hashmap to which multiple threads can safely insert items
in parallel. We use it in the symbol resolution stage, for example.
To resolve symbols, we basically have to throw in all defined symbols
into a hash table, so that we can find a matching defined symbol for
an undefined symbol by name. We do the hash table insertion from a
parallel for-loop which iterates over a list of input files.
Overall, even though mold is highly scalable, it succeeded to avoid
complexties you often find in complex parallel programs. From high
level, mold just serially executes the linker's internal passes one by
one. Each pass is parallelized using parallel for-loops.
### Rejected ideas
In this section, I'll explain the alternative designs I currently do
not plan to implement and why I turned them down.
- Placing variable-length sections at end of an output file and start
copying file contents before fixing the output file layout
Idea: Fixing the layout of regular sections seems easy, and if we
place them at beginning of a file, we can start copying their
contents from their input files to an output file. While copying
file contents, we can compute the sizes of variable-length sections
such as .got or .plt and place them at end of the file.
Reason for rejection: I did not choose this design because I doubt
if it could actually shorten link time and I think I don't need it
anyway.
The linker has to de-duplicate comdat sections (i.e. inline
functions that are included in multiple object files), so we
cannot compute the layout of regular sections until we resolve all
symbols and de-duplicate comdats. That takes a few hundred
milliseconds. After that, we can compute the sizes of
variable-length sections in less than 100 milliseconds. It's quite
fast, so it doesn't seem to make much sense to proceed without
fixing the final file layout.
The other reason to reject this idea is because there's good a
chance for this idea to have a negative impact on linker's overall
performance. If we copy file contents before fixing the layout, we
can't apply relocations to them while copying because symbol
addresses are not available yet. If we fix the file layout first, we
can apply relocations while copying, which is effectively zero-cost
due to a very good data locality. On the other hand, if we apply
relocations long after we copy file contents, it's pretty expensive
because section contents are very likely to have been evicted from
CPU cache.
- Incremental linking
Idea: Incremental linking is a technique to patch a previous linker's
output file so that only functions or data that are updated from the
previous build are written to it. It is expected to significantly
reduce the amount of data copied from input files to an output file
and thus speed up linking. GNU BFD and gold linkers support it.
Reason for rejection: I turned it down because it (1) is
complicated, (2) doesn't seem to speed it up that much and (3) has
several practical issues. Let me explain each of them.
First, incremental linking for real C/C++ programs is not as easy as
one might think. Let me take malloc as an example. malloc is usually
defined by libc, but you can implement it in your program, and if
that's the case, the symbol `malloc` will be resolved to your
function instead of the one in libc. If you include a library that
defines malloc (such as libjemalloc or libtbbmallc) before libc,
their malloc will override libc's malloc.
Assume that you are using a nonstandard malloc. What if you remove
your malloc from your code, or remove `-ljemalloc` from your
Makefile? The linker has to include a malloc from libc, which may
include more object files to satisfy its dependencies. Such code
change can affect the entire program rather than just replacing one
function. The same is true for adding malloc to your program. Making
a local change doesn't necessarily result in a local change in the
binary level. It can easily have cascading effects.
Some ELF fancy features make incremental linking even harder to
implement. Take the weak symbol as an example. If you define `atoi`
as a weak symbol in your program, and if you are not using `atoi`
at all in your program, that symbol will be resolved to address
0. But if you start using some libc function that indirectly calls
`atoi`, then `atoi` will be included in your program, and your weak
symbol will be resolved to that function. I don't know how to
efficiently fix up a binary for this case.
This is a hard problem, so existing linkers don't try too hard to
solve it. For example, IIRC, gold falls back to full link if any
function is removed from a previous build. If you want to not annoy
users in the fallback case, you need to make full link fast anyway.
Second, incremental linking itself has an overhead. It has to detect
updated files, patch an existing output file and write additional
data to an output file for future incremental linking. GNU gold, for
instance, takes almost 30 seconds on my machine to do a null
incremental link (i.e. no object files are updated from a previous
build) for chrome. It's just too slow.
Third, there are other practical issues in incremental linking. It's
not reproducible, so your binary isn't going to be the same as other
binaries even if you are compiling the same source tree using the
same compiler toolchain. Or, it is complex and there might be a bug
in it. If something doesn't work correctly, "remove --incremental
from your Makefile and try again" could be a piece of advice, but
that isn't ideal.
So, all in all, incremental linking is tricky. I wanted to make full
link as fast as possible, so that we don't have to think about how
to work around the slowness of full link.
- Defining a completely new file format and use it
Idea: Sometimes, the ELF file format itself seems to be a limiting
factor in improving the linker's performance. We might be able to make a
far better one if we create a new file format.
Reason for rejection: I rejected the idea because it apparently has
a practical issue (backward compatibility issue) and also doesn't
seem to improve the performance of linkers that much. As clearly
demonstrated by mold, we can create a fast linker for ELF. I believe
ELF isn't that bad, after all. The semantics of the existing Unix
linkers, such as the name resolution algorithm or the linker script,
have slowed the linkers down, but that's not a problem of the file
format itself.
- Watching object files using inotify(2)
Idea: When mold is running as a daemon for preloading, use
inotify(2) to watch file system updates so that it can reload files
as soon as they are updated.
Reason for rejection: Just like the maximum number of files you can
simultaneously open, the maximum number of files you can watch using
inotify(2) isn't that large. Maybe just a single instance of mold is
fine with inotify(2), but it may fail if you run multiple of it.
The other reason for not doing it is because mold is quite fast
without it anyway. Invoking stat(2) on each file for file update
check takes less than 100 milliseconds for Chrome, and if most of
the input files are not updated, parsing updated files takes almost
no time.
Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

+55
View File
@@ -0,0 +1,55 @@
This page explains the following warning message and how to fix it.
mold emits this message when it sees an object file that may not be
compatible with mold.
```
mold: warning: foo.o: this file may cause a segmentation fault because it requires an executable stack. See https://github.com/rui314/mold/tree/main/docs/execstack.md for more info.
```
# Background
On modern computers, the stack area (to which local variables are
stored) cannot contain executable code. If the control reaches the
stack area, the CPU refuses to execute any code there and the program
is usually terminated due to segmentation fault.
This is a security measure. The stack area used to be executable (old
CPUs generally execute any code as long as it is in a readable memory
region), but that provided an easy attack vector to a malicious user.
They wrote executable code to the stack area using some buffer
overflow bug and jumped there to run arbitrary code in a remote server
process.
To prevent this type of attack, the stack area is no longer executable
since the early 2000s. On Linux, the stack's executable-ness is
controlled by a bit in an executable, and the loader respects that
bit. The bit is set by the linker.
GCC had (and still has) a feature that depends on the executable
stack, so they invented a way to tell the linker to mark the stack
executable. Specifically, if an object file contains a
`.note.GNU-stack` section with the `SHF_EXECSTACK` bit, GNU linker
silently makes the stack of an output file executable.
But the GNU linker's behavior is dangerous. If you accidentally link
an object file that has that marker section, the entire stack area
silently becomes executable, disabling the security mechanism.
Therefore, mold simply ignores that marker section. If you are using
mold, you need to explicitly pass `-z execstack` to the linker to make
the stack executable.
# What caused this issue?
You are likely to use GCC's [Nested
Functions](https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html)
feature which still depends on the executable stack.
# How to fix it?
If you know what you are doing, pass `-z execstack` to mold. Beware
that this will significantly weaken your program's security.
If you don't want to pass `-z execstack`, rewrite your code so that
your code does not depend on the executable stack.
+158
View File
@@ -0,0 +1,158 @@
The very concept of linking is simple: a compiler compiles a piece of
source code into an object file (a file containing machine code), and
a linker combines object files into a single executable or a shared
library file. However, the actual implementation of the linker for
modern systems is much more complicated because hardware, operating
system, compiler and linker all have many more features.
In this file, I'll explain random topics in the glossary format that
you need to understand to read mold code.
## DSO
A .so file. Short for Dynamic Shared Object. Often called as a
shared library, a dynamic libray or a shared object as well.
An DSO contains common functions and data that are used by multiple
executables and/or other DSOs. At runtime, a DSO is loaded to a
contiguous region in the virtual address.
## Object file
A .o file. An object file contains machine code and data, but it
cannot be executed because it's not self-contained. For example,
if you compile a C source file containing a call of `printf`,
the actual function code of `printf` is not included in the resulting
object file. You include `stdio.h`, but that teaches the compiler
only about `printf`'s type, and the compiler still don't know what
`printf` actually does. Therefore, it cannot emit code for `printf`.
You need to link an object file with other object file or a shared
library to make it exectuable.
## Virtual address space
A pointer has a value like 0x803020 which is an address of the
pointee. But it doesn't mean that the pointee resides at the
physical memory address 0x803020 on the computer. Modern CPUs
contains so-called Mmeory Management Unit (MMU), and all access to
the memory are first translated by MMU to the physical address.
The address before translation is called the "virtual address".
Unless you are doing the kernel programming, all addresses you
handle are virtual addresses.
The OS kernel controls the MMU so that each process owns the entire
virtual address space. So, even if two process uses the same virtual
address, they don't conflict. They are mapped to different physical
addresses.
The existence of MMU has several implications to the linker. First,
we can link the main executable to a specific address. On process
startup, there's no code or data in the virtual address space, so
the mapping of the main executable always succeed. However, it's not
true to DSOs because they are loaded after the main executable and
possibly other DSOs. Therefore, shared libraries must be linked in a
way that they can be loaded to any address in the virtual address
space.
## Relocation
A piece of information for the linker as to how to link object files
or a dynamic objects.
Object files can refer functions or data in other object files. For
example, if you compile a function which calls a non-local function
`foo`, the resulting code contains something like this:
```
26: e8 00 00 00 00 callq 2b <bar+0xb>
27: R_X86_64_PLT32 foo-0x4
```
The above `callq` is the instruction to call a function at the
machine code level. It's opcode is `0xe8` in x86-64, so the
instruction begins with `0xe8`. The following four bytes are
displacement; that is, the address of the branch target relative to
the end of this `callq` instruction. Notice that the displacement is
0. The compiler couldn't fill the displacement because it has no
idea as to where `foo` will be at runtime. So, the compiler write 0
as a placeholder and instead write a relocation `R_X86_64_PLT32`
with `foo` as its associated symbol. The linker reads this
relocation, computes the offsets between this call instruction and
function `foo` and overwrite the placeholder value 0 with an actual
displacement.
There are many different types of relocations. For example, if you
want to fix up not with a displacement but with an absolute address
of a symbol, you need to use `R_X86_64_ABS64` instead.
## Static library
A .a file. Often called as an archive file or just archive as well.
A static library is a container just like tar or zip. Actually,
there's no technical reason to not use tar or (uncompressed) zip,
but traditionally the .a file format is used by the linker.
A static library contains object files and can be passed to the
linker along with other object files and/or archives.
A linker pulls out object files from an archive only if it is needed
to resolve undefined symbols. In other words, object files in an
archive are not linked by default and used as a complement to supply
missing definitions. This is ideal for a library because you don't
want to link library functions unless you are actually using them.
Contrary to archive files, object files directly given to a linker
are always linked to the output.
To maximize the benefit of archive files, a library often used as a
static library is broken down to small files to separate each
function individually (for example, look at
https://git.musl-libc.org/cgit/musl/tree/src/stdio). By doing this,
you import only used functions.
A static file is created by `ar`, whose command line arguments are
similar to `tar`. A static library contains the symbol table which
offers a quick way to look up an object file for a defined symbol,
but mold does not use the static library's symbol table. mold
doesdn't need a symbol table to exist in an archive, and if exists,
mold just ignores it.
See also: DSO (dynamic library)
## Symbol
A symbol is a label assigned to a specific location in an input file
or an output file. For example, if you define function `foo` and
compile it, the resulting object file contains a symbol `foo`
pointing to the beginning of the machine code for `foo`.
Usually, a symbol name is a function or a variable name. If an
object is anonymous (such the one for a string literal), a compiler
generated a unique symbol, which often starts with `.` to avoid
conflict with user-defined symbols.
For C++, symbol name is a complex "mangled" name. We need to mangle
identifiers because a simple name such as `foo` cannot be uniquely
identify a function or a data in C++, because for example `foo` may
be in a namespace or defined as a static member in some class. If
`foo` is an overloaded function, we need to distinguish different
`foo`s by its type. Therefore, C++ compiler mangles an identifier by
appending nmaepsace names, type information and such so that
different things get different names.
For example, a function `int foo(int)` in a namespace `bar` is
mangled as `_ZN3bar3fooEi`.
A symbol can be either defined or undefined. A defined symbol points
to some location in a file which may contain the function's machine
code or the variable's initial value. An undefined symbol does not
point to anywhere. It needs to be merged with a defined symbol with
the same name at link-time. This merging process is called "name
resolution".
For example, if your program is using `printf`, it usually contains
`printf` as an undefined symbol. You need to link it with `libc.a`
or `libc.so`, which contain a defined symbol of `printf`, to make a
complete program.
Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

+551 -684
View File
File diff suppressed because it is too large. Load diff
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 KiB

+935
View File
@@ -0,0 +1,935 @@
mold(1) -- a modern linker
==========================
## SYNOPSIS
`mold` [_option_...] _file_...
## DESCRIPTION
`mold` is a faster drop-in replacement for the default GNU ld(1).
### How to use
See <https://github.com/rui314/mold#how-to-use>.
### Compatibility
`mold` is designed to be a drop-in replacement for the GNU linkers for
linking user-land programs. If your user-land program cannot be built due to
missing command-line options, please file a bug at
<https://github.com/rui314/mold/issues>.
`mold` supports a very limited set of linker script features, which is just
sufficient to read `/usr/lib/x86_64-linux-gnu/libc.so` on Linux systems (on
Linux, that file is contrary to its name not a shared library but an ASCII
linker script that loads a real `libc.so` file.)
Beyond that, we have no plan to support any additional linker script features.
The linker script is an ad-hoc, over-designed, complex language which we
believe needs to be replaced by a simpler mechanism. We have a plan to add a
replacement for the linker script to `mold` instead.
### Archive symbol resolution
Traditionally, Unix linkers are sensitive to the order in which input files
appear on the command line. They process input files from the first (leftmost)
file to the last (rightmost) file one-by-one. While reading input files, they
maintain sets of defined and undefined symbols. When visiting an archive file
(`.a` files), they pull out object files to resolve as many undefined symbols
as possible and move on to the next input file. Object files that weren't
pulled out will never have a chance for a second look.
Due to this behavior, you usually have to add archive files at the end of a
command line, so that when a linker reaches archive files, it knows what
symbols remain as undefined.
If you put archive files at the beginning of a command line, a linker doesn't
have any undefined symbols, and thus no object files will be pulled out from
archives. You can change the processing order by using the `--start-group` and
`--end-group` options, though they make a linker slower.
`mold`, as well as the LLVM lld(1) linker, takes a different approach. They
remember which symbols can be resolved from archive files instead of
forgetting them after processing each archive. Therefore, `mold` and lld(1)
can "go back" in a command line to pull out object files from archives if they
are needed to resolve remaining undefined symbols. They are not sensitive to
the input file order.
`--start-group` and `--end-group` are still accepted by `mold` and lld(1)
for compatibility with traditional linkers, but they are silently ignored.
### Dynamic symbol resolution
Some Unix linker features are difficult to understand without comprehending
the semantics of dynamic symbol resolution. Therefore, even though it's not
specific to `mold`, we'll explain it here.
We use "ELF module" or just "module" as a collective term to refer to an
executable or a shared library file in the ELF format.
An ELF module may have lists of imported symbols and exported symbols, as well
as a list of shared library names from which imported symbols should be
imported. The point is that imported symbols are not bound to any specific
shared library until runtime.
Here is how the Unix dynamic linker resolves dynamic symbols. Upon the start
of an ELF program, the dynamic linker constructs a list of ELF modules which,
as a whole, consist of a complete program. The executable file is always at
the beginning of the list followed by its dependent shared libraries. An
imported symbol is searched from the beginning of the list to the end. If two
or more modules define the same symbol, the one that appears first in the list
takes precedence over the others.
This Unix semantics are contrary to systems such as Windows that have a
two-level namespace for dynamic symbols. On Windows, for example, dynamic
symbols are represented as a tuple of (`symbol-name`, `shared-library-name`),
so that each dynamic symbol is guaranteed to be resolved from some specific
library.
Typically, an ELF module that exports a symbol also imports the same symbol.
Such a symbol is usually resolved to itself, but that's not the case if a
module that appears before it in the symbol search list provides another
definition of the same symbol.
Let's take `malloc` as an example. Assume that you define your version of
`malloc` in your main executable file. Then, all `malloc` calls from any
module are resolved to your function instead of the one in libc, because the
executable is always at the beginning of the dynamic symbol search list. Note
that even `malloc` calls within libc are resolved to your definition since
libc exports and imports `malloc`. Therefore, by defining `malloc` yourself,
you can overwrite a library function, and the `malloc` in libc becomes dead
code.
These Unix semantics are tricky and sometimes considered harmful. For example,
assume that you accidentally define `atoi` as a global function in your
executable that behaves completely differently from the one in the C standard.
Then, all `atoi` function calls from any modules (even function calls within
libc) are redirected to your function instead of the one in libc, which will
very likely cause a problem. That is a somewhat surprising consequence for an
accidental name conflict. On the other hand, this semantic is sometimes useful
because it allows users to override library functions without rebuilding
modules containing them.
Whether good or bad, you should keep these semantics in mind to understand
Unix linkers' behaviors.
### Build reproducibility
`mold`'s output is deterministic. That is, if you pass the same object files
and the same command-line options to the same version of `mold`, it is
guaranteed that `mold` produces the bit-for-bit identical output. The linker's
internal randomness, such as the timing of thread scheduling or iteration
orders of hash tables, doesn't affect the output.
`mold` does not have any host-specific default settings. This is contrary to the
GNU linkers, for which some configurable values, such as system-dependent
library search paths, are hard-coded. `mold` depends only on its command-line
arguments.
## OPTION NOTATIONS
Multi-letter long options may precede either a single dash or double dashes,
except for those starting with the letter "o". For historical reasons, long
options beginning with "o" must precede double dashes.
For example, you can spell `--as-needed` as `-as-needed`, but `--omagic` must
not be spelled as `-omagic`. `-omagic` will be interpreted not as `--omagic`
but as `-o magic`.
## MOLD-SPECIFIC OPTIONS
* `--chroot`=_dir_:
Set _dir_ as the root directory.
* `--color-diagnostics`=[ _auto_ | _always_ | _never_ ]:
Show diagnostic messages in color using ANSI escape sequences. `auto` means
that `mold` prints out messages in color only if the standard output is
connected to a TTY. Default is `auto`.
* `--color-diagnostics`:
Synonym for `--color-diagnostics=auto`.
* `--no-color-diagnostics`:
Synonym for `--color-diagnostics=never`.
* `--detach`, `--no-detach`:
Permit or do not permit mold to create a debug info file in the background.
* `--fork`, `--no-fork`:
Spawn a child process and let it do the actual linking. When linking a large
program, the OS kernel can take a few hundred milliseconds to terminate a
`mold` process. `--fork` hides that latency. By default, it does fork.
* `--perf`:
Print performance statistics.
* `--print-dependencies`:
Print out dependency information for input files.
Each line of the output for this option shows which file depends on which
file to use a specific symbol. This option is useful for debugging why some
object file in a static archive got linked or why some shared library is
kept in an output file's dependency list even with `--as-needed`.
* `--relocatable-merge-sections`:
By default, `mold` doesn't merge input sections by name when merging input
object files into a single output object file for `-r`. For example,
`.text.foo` and `.text.bar` aren't merged for `-r` even though they are
merged into `.text` based on the default section merging rules.
This option changes the behavior so that `mold` merges input sections by
name by the default section merging rules.
* `--repro`:
Archive input files, as well as a text file containing command line options,
in a tar file so that you can run `mold` with the exact same inputs again.
This is useful for reporting a bug with a reproducer. The output filename is
`path/to/output.tar`, where `path/to/output` is an output filename specified
by `-o`.
* `--reverse-sections`:
Reverse the order of input sections before assigning them the offsets in the
output file.
This option is useful for finding bugs that depend on the initialization
order of global objects. In C++, constructors of global objects in a single
source file are guaranteed to be executed in the source order, but there's
no such guarantee across compilation units. Usually, constructors are
executed in the order given to the linker, but depending on it is a mistake.
By reversing the order of input sections using `--reverse-sections`, you can
easily test that your program works in the reversed initialization order.
* `--run` _command_ _arg_...:
Run _command_ with `mold` as `/usr/bin/ld`. Specifically, `mold` runs a
given command with the `LD_PRELOAD` environment set to intercept exec(3)
family functions and replaces `argv[0]` with itself if it is `ld`,
`ld.gold`, or `ld.lld`.
* `--separate-debug-file`, `--separate-debug-file`=_file_:
Bundle debug info sections into a separate file instead of embedding them in
an output executable or a shared library. mold creates a debug info file in
the background by default, so that you can start running your executable as
soon as possible.
By default, the debug info file is created in the same directory as is the
output file, with the `.dbg` file extension. That filename is embedded into
the output file so that `gdb` can automatically find the debug info file for
the output file. For more info about gdb features related to separate debug
files, see
<https://sourceware.org/gdb/current/onlinedocs/gdb.html/Separate-Debug-Files.html>.
mold holds a file lock with flock(2) while creating a debug info file in the
background.
If you don't want to create a debug info file in the background, pass the
`--no-detach` option.
* `--shuffle-sections`, `--shuffle-sections`=_number_:
Randomize the output by shuffling the order of input sections before
assigning them the offsets in the output file. If a _number_ is given, it's
used as a seed for the random number generator, so that the linker produces
the same output for the same seed. If no seed is given, a random number is
used as a seed.
This option is useful for benchmarking. Modern CPUs are sensitive to a
program's memory layout. A seemingly benign change in program layout, such
as a small size increase of a function in the middle of a program, can
affect the program's performance. Therefore, even if you write new code and
get a good benchmark result, it is hard to say whether the new code improves
the program's performance; it is possible that the new memory layout happens
to perform better.
By running a benchmark multiple times with randomized memory layouts using
`--shuffle-sections`, you can isolate your program's real performance number
from the randomness caused by memory layout changes.
* `--spare-program-headers`=_number_:
Append the given number of `PT_NULL` entries to the end of the program
header, so that post-link processing tools can easily add new segments by
overwriting the null entries.
Note that ELF requires all `PT_LOAD` segments to be sorted by `p_vaddr`.
Therefore, if you add a new LOAD segment, you may need to sort the entire
program header.
* `--stats`:
Print input statistics.
* `--thread-count`=_count_:
Use _count_ number of threads.
* `--threads`, `--no-threads`:
Use multiple threads. By default, `mold` uses as many threads as the number of
cores or 32, whichever is smaller. The reason it is capped at 32 is because
`mold` doesn't scale well beyond that point. To use only one thread, pass
`--no-threads` or `--thread-count=1`.
* `--quick-exit`, `--no-quick-exit`:
Use or do not use `quick_exit` to exit.
* `-z rewrite-endbr`, `-z norewrite-endbr`:
As a security measure, some CPU instruction sets have recently gained a
feature to protect control flow integrity by disallowing indirect branches
by default. If the feature is enabled, the instruction that is executed
immediately after an indirect branch must be an branch target marker
instruction, or a CPU-level fault will raise. The marker instruction is also
known as "landing pad" instruction, to which indirect branches can land.
This feature makes ROP attacks harder to conduct.
To use the feature, a function whose pointer is taken needs to begin with a
landing pad because a function call via a function pointer is compiled to an
indirect branch. On the other hand, if a function is called only directly
(i.e. referred to only by _direct_ branch instructions), it doesn't have to
begin with it.
By default, the compiler always emits a landing pad at the beginning of each
global function because it doesn't know whether or not the function's
pointer is taken in another translation unit. As a result, the resulting
binary has more attack surface than necessary.
If `--rewrite-endbr` is given, mold conducts a whole program analysis
to identify functions whose addresses are actually taken and rewrites
landing pads with no-ops for non-address-taken functions, reducing the
attack surface.
This feature is currently available only on x86-64.
## GNU-COMPATIBLE OPTIONS
* `--help`:
Report usage information to stdout and exit.
* `-v`, `--version`:
Report version information to stdout.
* `-V`:
Report version and target information to stdout.
* `-E`, `--export-dynamic`, `--no-export-dynamic`:
When creating an executable, using the `-E` option causes all global symbols
to be put into the dynamic symbol table, so that the symbols are visible
from other ELF modules at runtime.
By default, or if `--no-export-dynamic` is given, only symbols that are
referenced by DSOs at link-time are exported from an executable.
* `-F` _libname_, `--filter`=_libname_:
Set the `DT_FILTER` dynamic section field to _libname_.
* `-I` _file_, `--dynamic-linker`=_file_, `--no-dynamic-linker`:
Set the dynamic linker path to _file_. If no `-I` option is given, or if
`--no-dynamic-linker` is given, no dynamic linker path is set to an output
file. This is contrary to the GNU linkers which set a default dynamic linker
path in that case. This difference doesn't usually make any difference
because the compiler driver always passes `-I` to the linker.
* `-L` _dir_, `--library-path`=_dir_:
Add _dir_ to the list of library search paths from which `mold` searches
libraries for the `-l` option.
Unlike the GNU linkers, `mold` does not have default search paths. This
difference doesn't usually make any difference because the compiler driver
always passes all necessary search paths to the linker.
* `-M`, `--print-map`:
Write a map file to stdout.
* `-N`, `--omagic`, `--no-omagic`:
Force `mold` to emit an output file with an old-fashioned memory layout.
First, it makes the first data segment not aligned to a page boundary.
Second, text segments are marked as writable if the option is given.
* `-S`, `--strip-debug`:
Omit `.debug_*` sections from the output file.
* `-T` _file_, `--script`=_file_:
Read linker script from _file_.
* `-X`, `--discard-locals`:
Discard temporary local symbols to reduce the sizes of the symbol table and
the string table. Temporary local symbols are local symbols starting with
`.L`. Compilers usually generate such symbols for unnamed program elements
such as string literals or floating-point literals.
* `-e` _symbol_, `--entry`=_symbol_:
Use _symbol_ as the entry point symbol instead of the default entry
point symbol _start.
* `-f` _shlib_, `--auxiliary`=_shlib_:
Set the `DT_AUXILIARY` dynamic section field to _shlib_.
* `-h` _libname_, `--soname`=_libname_:
Set the `DT_SONAME` dynamic section field to _libname_. This option is used
when creating a shared object file. Typically, when you create `libfoo.so`,
you want to pass `--soname=foo` to a linker.
* `-l` _libname_:
Search for `lib`_libname_`.so` or `lib`_libname_`.a` from library search
paths.
* `-m` _target_:
Choose a _target_.
* `-o` _file_, `--output`=_file_:
Use _file_ as the output file name instead of the default name `a.out`.
* `-r`, `--relocatable`:
Instead of generating an executable or a shared object file, combine input
object files to generate another object file that can be used as an input to
a linker.
* `-s`, `--strip-all`:
Omit `.symtab` section from the output file.
* `-u` _symbol_, `--undefined`=_symbol_:
If _symbol_ remains as an undefined symbol after reading all object files,
and if there is a static archive that contains an object file defining
_symbol_, pull out the object file and link it so that the output file
contains a definition of _symbol_.
* `-y` _symbol_, `--trace-symbol`=_symbol_:
Trace references to _symbol_.
* `--Bdynamic`:
Link against shared libraries.
* `--Bstatic`:
Do not link against shared libraries.
* `--Bsymbolic`:
When creating a shared library, make global symbols export-only (i.e. do not
import the same symbol). As a result, references within a shared library are
always resolved locally, negating symbol override at runtime. See "Dynamic
symbol resolution" for more information about symbol imports and exports.
* `--Bsymbolic-functions`:
This option has the same effect as `--Bsymbolic` but works only for function
symbols. Data symbols remain being both imported and exported.
* `--Bsymbolic-non-weak`:
This option has the same effect as `--Bsymbolic` but works only for non-weak
symbols. Weak symbols remain being both imported and exported.
* `--Bsymbolic-non-weak-functions`:
This option has the same effect as `--Bsymbolic` but works only for non-weak
function symbols. Data symbols and weak function symbols remain being both
imported and exported.
* `--Bno-symbolic`:
Cancel `--Bsymbolic`, `--Bsymbolic-functions`, `--Bsymbolic-non-weak` and
`--Bsymbolic-non-weak-functions`.
* `--Map`=_file_:
Write map file to _file_.
* `--Tbss`=_address_:
Alias for `--section-start=.bss=`_address_.
* `--Tdata`=_address_:
Alias for `--section-start=.data=`_address_.
* `--Ttext`=_address_:
Alias for `--section-start=.text=`_address_.
* `--allow-multiple-definition`:
Normally, the linker reports an error if there are more than one definition
of a symbol. This option changes the default behavior so that it doesn't
report an error for duplicate definitions and instead use the first
definition.
* `--allow-shlib-undefined`, `--no-allow-shlib-undefined`:
Even if mold succeeds in linking a main executable without undefined symbol
errors, you may still encounter symbol lookup errors at runtime because the
dynamic linker cannot find some symbols in shared libraries in any ELF
module. This occurs because mold ignores undefined symbols in shared
libraries by default.
If you pass `--no-allow-shlib-undefined`, mold verifies that undefined
symbols in shared libraries given to the linker can be resolved at
link-time. In other words, this converts the runtime error to a link-time
error.
Note that you need to pass all shared libraries, including indirectly
dependent ones, to the linker as arguments for `-l`. If a shared library
depends on a library that's not passed to the linker, the verification will
be skipped for that file.
* `--as-needed`, `--no-as-needed`:
By default, shared libraries given to the linker are unconditionally added
to the list of required libraries in an output file. However, shared
libraries after `--as-needed` are added to the list only when at least one
symbol is actually used by the output file. In other words, shared libraries
after `--as-needed` are not added to the list of needed libraries if they
are not needed by a program.
The `--no-as-needed` option restores the default behavior for subsequent
files.
* `--build-id`=[ `md5` | `sha1` | `sha256` | `fast` | `uuid` | `0x`_hexstring_ | `none` ]:
Create a `.note.gnu.build-id` section containing a byte string to uniquely
identify an output file. `sha256` compute a 256-bit cryptographic hash of an
output file and set it to build-id. `md5` and `sha1` compute the same hash
but truncate it to 128 and 160 bits, respectively, before setting it to
build-id. `uuid` sets a random 128-bit UUID. `0x`_hexstring_ sets
_hexstring_. `fast` is a synonym for `sha256`.
* `--build-id`:
Synonym for `--build-id=sha256`.
* `--no-build-id`:
Synonym for `--build-id=none`.
* `--compress-debug-sections`=[ `zlib` | `zlib-gabi` | `zstd` | `none` ]:
Compress DWARF debug info (`.debug_*` sections) using the zlib or zstd
compression algorithm. `zlib-gabi` is an alias for `zlib`.
* `--defsym`=_symbol_=_value_:
Define _symbol_ as an alias for _value_.
_value_ is either an integer (in decimal or hexadecimal with `0x` prefix) or
a symbol name. If an integer is given as a value, _symbol_ is defined as an
absolute symbol with the given value.
* `--default-symver`:
Use soname as a symbol version and append that version to all symbols.
* `--demangle`, `--no-demangle`:
Demangle C++ and Rust symbols in log messages.
* `--dependency-file`=_file_:
Write a dependency file to _file_. The contents of the written file is
readable by make(1), which defines only one rule with the linker's output
file as a target and all input files as its prerequisites. Users are
expected to include the generated dependency file into a Makefile to
automate the dependency management. This option is analogous to the
compiler's `-MM -MF` options.
* `--dynamic-list`=_file_:
Read a list of dynamic symbols from _file_. Same as
`--export-dynamic-symbol-list`, except that it implies `--Bsymbolic`. If
_file_ does not exist in the current directory, it is searched from library
search paths for the sake of compatibility with GNU ld.
* `--eh-frame-hdr`, `--no-eh-frame-hdr`:
Create `.eh_frame_hdr` section.
* `--emit-relocs`:
The linker usually "consumes" relocation sections. That is, the linker
applies relocations to other sections, and relocation sections themselves
are discarded.
The `--emit-relocs` instructs the linker to leave relocation sections in the
output file. Some post-link binary analysis or optimization tools such as
LLVM Bolt need them.
* `--enable-new-dtags`, `--disable-new-dtags`:
By default, `mold` emits `DT_RUNPATH` for `--rpath`. If you pass
`--disable-new-dtags`, `mold` emits `DT_RPATH` for `--rpath` instead.
* `--execute-only`:
Traditionally, setting the executable bit to 1 for a memory page implies
that the page also become readable, which allows machine code to be read
as data at runtime. That is actually what an attacker often does after
gaining a limited control of a process to find pieces of machine code
they can use to gain the full control of the process. As a mitigation,
recent processors including some ARM64 ones allows "execute-only" pages.
If a page is execute-only, you can call a function there as long as you
know its address but can't read it as data.
This option marks text segments as execute-only by setting just the "X"
bit instead of "RX". Note that on most systems, the absence of the "R"
bit in the text segment serves just as a hint. If you run a program
linked with `--execute-only` on a processor that doesn't support
execute-only pages, your executable will likely still function normally,
but the text segment will remain readable.
* `--exclude-libs`=_libraries_ ...:
Mark all symbols in the given _libraries_ hidden.
* `--export-dynamic-symbol`=_symbol_:
Put symbols matching _symbol_ in the dynamic symbol table. _symbol_ may be a
glob pattern in the same syntax as for the `--export-dynamic-symbol-list` or
`--version-script` options.
* `--export-dynamic-symbol-list`=_file_:
Read a list of dynamic symbols from _file_.
* `--fatal-warnings`, `--no-fatal-warnings`:
Treat warnings as errors.
* `--fini`=_symbol_:
Call _symbol_ at unload-time.
* `--gc-sections`, `--no-gc-sections`:
Remove unreferenced sections.
* `--gdb-index`:
Create a `.gdb_index` section to speed up GNU debugger. To use this, you
need to compile source files with the `-ggnu-pubnames` compiler flag.
* `--hash-style`=[ `sysv` | `gnu` | `both` | `none` ]:
Set hash style.
* `--icf`=[ `safe` | `all` | `none` ], `--no-icf`:
It is not uncommon for a program to contain many identical functions that
differ only in name. For example, a C++ template `std::vector` is very
likely to be instantiated to the identical code for `std::vector<int>` and
`std::vector<unsigned>` because the container cares only about the size of
the parameter type. Identical Code Folding (ICF) is a size optimization to
identify and merge such identical functions.
If `--icf=all` is given, `mold` tries to merge all identical functions. This
reduces the size of the output most, but it is not a "safe" optimization. It
is guaranteed in C and C++ that two pointers pointing two different
functions will never be equal, but `--icf=all` breaks that assumption as two
identical functions have the same address after merging. So a care must be
taken when you use this flag that your program does not depend on the
function pointer uniqueness.
`--icf=safe` is a flag to merge functions only when it is safe to do so.
That is, if a program does not take an address of a function, it is safe to
merge that function with other function, as you cannot compare a function
pointer with something else without taking an address of a function.
`--icf=safe` needs to be used with a compiler that supports `.llvm_addrsig`
section which contains the information as to what symbols are address-taken.
LLVM/Clang supports that section by default. Since GCC does not support it
yet, you cannot use `--icf=safe` with GCC (it doesn't do any harm but can't
optimize at all.)
`--icf=none` and `--no-icf` disables ICF.
* `--ignore-data-address-equality`:
Make ICF to merge not only functions but also data. This option should be
used in combination with `--icf=all`.
* `--image-base`=_addr_:
Set the base address to _addr_.
* `--init`=_symbol_:
Call _symbol_ at load-time.
* `--no-undefined`:
Report undefined symbols (even with `--shared`).
* `--noinhibit-exec`:
Create an output file even if errors occur.
* `--package-metadata`=_percent-encoded-string_:
Embed a specified string into the `.note.package` section. This option
is designed for build scripts that generate binary packages, such as
`.rpm` or `.deb`, to include package metadata in each executable. It
simplifies the process of identifying the corresponding package for a
given executable or core file.
An argument to this option is treated as percent-encoded and decoded
before being inserted into the section, allowing you to avoid the use of
the comma (`,`) character in the argument. This is useful because the
compiler replaces all occurrences of commas in `-Wl,` with spaces before
forwarding them to the linker. Note that `mold` always interprets the
argument as percent-encoded, so you also need to escape all occurrences
of `%` as `%25`.
* `--pack-dyn-relocs`=[ `relr` | `none` ]:
If `relr` is specified, all `R_*_RELATIVE` relocations are put into
`.relr.dyn` section instead of `.rel.dyn` or `.rela.dyn` section. Since
`.relr.dyn` section uses a space-efficient encoding scheme, specifying this
flag can reduce the size of the output. This is typically most effective for
position-independent executable.
Note that a runtime loader has to support `.relr.dyn` to run executables or
shared libraries linked with `--pack-dyn-relocs=relr`. As of 2022, only
ChromeOS, Android and Fuchsia support it.
* `--pie`, `--pic-executable`, `--no-pie`, `--no-pic-executable`:
Create a position-independent executable.
* `--print-gc-sections`, `--no-print-gc-sections`:
Print removed unreferenced sections.
* `--print-icf-sections`, `--no-print-icf-sections`:
Print folded identical sections.
* `--push-state`, `--pop-state`:
`--push-state` saves the current values of `--as-needed`, `--whole-archive`,
`--static`, and `--start-lib`. The saved values can be restored by
pop-state.
`--push-state` and `--pop-state` pairs can nest.
These options are useful when you want to construct linker command line
options programmatically. For example, if you want to link `libfoo.so` by
as-needed basis but don't want to change the global state of `--as-needed`,
you can append `--push-state --as-needed -lfoo --pop-state` to the linker
command line options.
* `--relax, --no-relax`:
Rewrite machine instructions with more efficient ones for some relocations.
The feature is enabled by default.
* `--require-defined`=_symbol_:
Like `--undefined`, except the new symbol must be defined by the end of the
link.
* `--retain-symbols-file`=_file_:
Keep only symbols listed in _file_. _file_ is a text file containing a
symbol name on each line. `mold` discards all local symbols as well as
global symbol that are not in _file_. Note that this option removes symbols
only from `.symtab` section and does not affect `.dynsym` section, which is
used for dynamic linking.
* `--rpath`=_dir_:
Add _dir_ to runtime search paths.
* `--section-start`=_section_=_address_:
Set _address_ to section. _address_ is a hexadecimal number that may start
with an optional `0x`.
* `--shared`, `--Bshareable`:
Create a share library.
* `--spare-dynamic-tags`=_number_:
Append the given number of `DT_NULL` entries to the end of the `.dynamic`
section, so that post-link processing tools can easily add new dynamic tags
by overwriting the null entries.
* `--start-lib`, `--end-lib`:
Handle object files between `--start-lib` and `--end-lib` as if they were in
an archive file. That means object files between them are linked only when
they are needed to resolve undefined symbols. The options are useful if you
want to link object files only when they are needed but want to avoid the
overhead of running ar(3).
* `--static`:
Do not link against shared libraries.
* `--sysroot`=_dir_:
Set target system root directory to _dir_.
* `--trace`:
Print name of each input file.
* `--undefined-glob`=_pattern_:
Synonym for `--undefined`, except that `--undefined-glob` takes a glob
pattern instead of just a single symbol name.
* `--undefined-version`, `--no-undefined-version`:
By default, `mold` warns on a symbol specified by a version script or by
`--export-dynamic-symbol` if it is not defined. You can silence the warning
by `--undefined-version`.
* `--unique`=_pattern_:
Don't merge input sections that match the given glob pattern _pattern_.
* `--unresolved-symbols`=[ `report-all` | `ignore-all` | `ignore-in-object-files` | `ignore-in-shared-libs` ]:
How to handle undefined symbols.
* `--version-script`=_file_:
Read version script from _file_. If _file_ does not exist in the current
directory, it is searched from library search paths for the sake of
compatibility with GNU ld.
* `--warn-common`, `--no-warn-common`:
Warn about common symbols.
* `--warn-once`:
Only warn once for each undefined symbol instead of warn for each relocation
referring an undefined symbol.
* `--warn-unresolved-symbols`, `--error-unresolved-symbols`:
Normally, the linker reports an error for unresolved symbols.
`--warn-unresolved-symbols` option turns it into a warning.
`--error-unresolved-symbols` option restores the default behavior.
* `--whole-archive`, `--no-whole-archive`:
When archive files (`.a` files) are given to the linker, only object files
that are needed to resolve undefined symbols are extracted from them and
linked to an output file. `--whole-archive` changes that behavior for
subsequent archives so that the linker extracts all object files and links
them to an output. For example, if you are creating a shared object file and
you want to include all archive members to the output, you should pass
`--whole-archive`. `--no-whole-archive` restores the default behavior for
subsequent archives.
* `--wrap`=_symbol_:
Make _symbol_ be resolved to `__wrap_`_symbol_. The original symbol can be
resolved as `__real_`_symbol_. This option is typically used for wrapping an
existing function.
* `-z cet-report`=[ `warning` | `error` | `none` ]:
Intel Control-flow Enforcement Technology (CET) is a new x86 feature
available since Tiger Lake which is released in 2020. It defines new
instructions to harden security to protect programs from control hijacking
attacks. You can tell the compiler to use the feature by specifying the
`-fcf-protection` flag.
`-z cet-report` flag is used to make sure that all object files were
compiled with a correct `-fcf-protection` flag. If `warning` or `error` are
given, `mold` prints out a warning or an error message if an object file was
not compiled with the compiler flag.
`mold` looks for `GNU_PROPERTY_X86_FEATURE_1_IBT` bit and
`GNU_PROPERTY_X86_FEATURE_1_SHSTK` bit in `.note.gnu.property` section to
determine whether or not an object file was compiled with `-fcf-protection`.
* `-z now`, `-z lazy`:
By default, functions referring to other ELF modules are resolved by the
dynamic linker when they are called for the first time. `-z now` marks an
executable or a shared library file so that all dynamic symbols are resolved
when a file is loaded to memory. `-z lazy` restores the default behavior.
* `-z origin`:
Mark object requiring immediate `$ORIGIN` processing at runtime.
* `-z ibt`:
Turn on `GNU_PROPERTY_X86_FEATURE_1_IBT` bit in `.note.gnu.property` section
to indicate that the output uses IBT-enabled PLT. This option implies `-z
ibtplt`.
* `-z ibtplt`:
Generate Intel Branch Tracking (IBT)-enabled PLT which is the default on
x86-64. This is the default.
* `-z execstack`, `-z noexecstack`:
By default, the pages for the stack area (i.e. the pages where local
variables reside) are not executable for security reasons. `-z execstack`
makes it executable. `-z noexecstack` restores the default behavior.
* `-z keep-text-section-prefix`, `-z nokeep-text-section-prefix`:
Keep `.text.hot`, `.text.unknown`, `.text.unlikely`, `.text.startup`, and
`.text.exit` as separate sections in the final binary instead of merging
them as `.text`.
* `-z rodynamic`:
Make the `.dynamic` section read-only.
* `-z relro`, `-z norelro`:
Some sections such as `.dynamic` have to be writable only during a module is
being loaded to memory. Once the dynamic linker finishes its job, such
sections won't be mutated by anyone. As a security mitigation, it is
preferred to make such segments read-only during program execution.
`-z relro` puts such sections into a special segment called `relro`. The
dynamic linker makes a relro segment read-only after it finishes its job.
By default, `mold` generates a relro segment. `-z norelro` disables the
feature.
* `-z sectionheader`, `-z nosectionheader`:
`-z nosectionheader` tell the linker to omit the section header.
By default, the linker does not omit the section header.
* `-z separate-loadable-segments`, `-z separate-code`, `-z noseparate-code`:
If one memory page contains multiple segments, the page protection bits are
set in such a way that the needed attributes (writable or executable) are
satisfied for all segments. This usually happens at a boundary of two
segments with two different attributes.
`separate-loadable-segments` adds paddings between segments with different
attributes so that they do not share the same page. This is the default.
`separate-code` adds paddings only between executable and non-executable
segments.
`noseparate-code` does not add any paddings between segments.
* `-z defs`, `-z nodefs`:
Report undefined symbols (even with `--shared`).
* `-z shstk`:
Enforce shadow stack by turning `GNU_PROPERTY_X86_FEATURE_1_SHSTK` bit in
`.note.gnu.property` output section. Shadow stack is part of Intel
Control-flow Enforcement Technology (CET), which is available since Tiger
Lake (2020).
* `-z start_stop_visibility`=[ `hidden` | `protected` ]:
If a section name is valid as a C identifier (i.e., it matches
`/^[_a-zA-Z][_a-zA-Z0-9]*$/`), mold creates `__start_SECNAME` and
`__stop_SECNAME` symbols to mark the beginning and end of the section,
where `SECNAME` is the section name.
You can make these marker symbols visible from other ELF modules by passing
`-z start_stop_visibility=protected`. Default is `hidden`.
* `-z text`, `-z notext`, `-z textoff`:
`mold` by default reports an error if dynamic relocations are created in
read-only sections. If `-z notext` or `-z textoff` are given, `mold` creates
such dynamic relocations without reporting an error. `-z text` restores the
default behavior.
* `-z max-page-size`=_number_:
Some CPU ISAs support multiple memory page sizes. This option specifies the
maximum page size that an output binary can run on. In general, binaries
built for a larger page size can run on a system with a smaller page size,
but not vice versa. The default value is 4 KiB for i386, x86-64, and RISC-V,
and 64 KiB for ARM64.
* `-z nodefaultlib`:
Make the dynamic loader ignore default search paths.
* `-z nodelete`:
Mark DSO non-deletable at runtime.
* `-z nodlopen`:
Mark DSO not available to dlopen(3). This option makes it possible for the
linker to optimize thread-local variable accesses by rewriting instructions
for some targets.
* `-z nodump`:
Mark DSO not available to dldump(3).
* `-z nocopyreloc`:
Do not create copy relocations.
* `-z initfirst`:
Mark DSO to be initialized first at runtime.
* `-z interpose`:
Mark object to interpose all DSOs but executable.
* `-(`, `-)`, `-EL`, `-O`_number_, `--dc`, `--dp`, `--end-group`, `--no-add-needed`, `--no-copy-dt-needed-entries`, `--nostdlib`, `--rpath-link=Ar dir`, `--sort-common`, `--sort-section`, `--start-group`, `--warn-constructors`, `--warn-once`, `--fix-cortex-a53-835769`, `--fix-cortex-a53-843419`, `-z combreloc`, `-z common-page-size`, `-z nocombreloc`:
Ignored
## ENVIRONMENT VARIABLES
* `MOLD_JOBS`:
If this variable is set to `1`, only one `mold` process will run at a time.
If a new mold process is initiated while another is already active, the new
process will wait until the active one completes before starting.
The primary reason for this environment variable is to minimize peak memory
usage. Since mold is designed to operate with high parallelism, running
multiple mold instances simultaneously may not be beneficial. If you execute
N instances of mold concurrently, it could require N times the time and N
times the memory. On the other hand, running them one after the other might
still take N times longer, but the peak memory usage would be the same as
running just a single instance.
If your build system invokes multiple linker processes simultaneously and
some of them often get killed due to out-of-memory errors, you might
consider setting this environment variable to `1` to see if it addresses the
OOM issue.
Currently, any value other than `1` is silently ignored.
* `MOLD_DEBUG`:
If this variable is set to a non-empty string, `mold` embeds its
command-line options in the output file's `.comment` section.
* `MOLD_REPRO`:
Setting this variable to a non-empty string has the same effect as passing
the `--repro` option.
## SEE ALSO
gold(1), ld(1), elf(5), ld.so(8)
## AUTHOR
Rui Ueyama <ruiu@cs.stanford.edu>
## BUGS
Report bugs to <https://github.com/rui314/mold/issues>.
-702
View File
@@ -1,702 +0,0 @@
#pragma once
#include <cstdint>
#include <endian.h>
#include <string>
#if __BYTE_ORDER == __BIG_ENDIAN
#error "mold does not support big-endian hosts"
#endif
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t i8;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
template <typename E>
static std::string rel_to_string(u32 r_type);
struct X86_64;
struct I386;
static constexpr u32 SHN_UNDEF = 0;
static constexpr u32 SHN_ABS = 0xfff1;
static constexpr u32 SHN_COMMON = 0xfff2;
static constexpr u32 SHN_XINDEX = 0xffff;
static constexpr u32 SHT_NULL = 0;
static constexpr u32 SHT_PROGBITS = 1;
static constexpr u32 SHT_SYMTAB = 2;
static constexpr u32 SHT_STRTAB = 3;
static constexpr u32 SHT_RELA = 4;
static constexpr u32 SHT_HASH = 5;
static constexpr u32 SHT_DYNAMIC = 6;
static constexpr u32 SHT_NOTE = 7;
static constexpr u32 SHT_NOBITS = 8;
static constexpr u32 SHT_REL = 9;
static constexpr u32 SHT_SHLIB = 10;
static constexpr u32 SHT_DYNSYM = 11;
static constexpr u32 SHT_INIT_ARRAY = 14;
static constexpr u32 SHT_FINI_ARRAY = 15;
static constexpr u32 SHT_PREINIT_ARRAY = 16;
static constexpr u32 SHT_GROUP = 17;
static constexpr u32 SHT_SYMTAB_SHNDX = 18;
static constexpr u32 SHT_GNU_HASH = 0x6ffffff6;
static constexpr u32 SHT_GNU_VERDEF = 0x6ffffffd;
static constexpr u32 SHT_GNU_VERNEED = 0x6ffffffe;
static constexpr u32 SHT_GNU_VERSYM = 0x6fffffff;
static constexpr u32 SHT_X86_64_UNWIND = 0x70000001;
static constexpr u32 SHF_WRITE = 0x1;
static constexpr u32 SHF_ALLOC = 0x2;
static constexpr u32 SHF_EXECINSTR = 0x4;
static constexpr u32 SHF_MERGE = 0x10;
static constexpr u32 SHF_STRINGS = 0x20;
static constexpr u32 SHF_INFO_LINK = 0x40;
static constexpr u32 SHF_LINK_ORDER = 0x80;
static constexpr u32 SHF_GROUP = 0x200;
static constexpr u32 SHF_TLS = 0x400;
static constexpr u32 SHF_COMPRESSED = 0x800;
static constexpr u32 SHF_EXCLUDE = 0x80000000;
static constexpr u32 GRP_COMDAT = 1;
static constexpr u32 STT_NOTYPE = 0;
static constexpr u32 STT_OBJECT = 1;
static constexpr u32 STT_FUNC = 2;
static constexpr u32 STT_SECTION = 3;
static constexpr u32 STT_FILE = 4;
static constexpr u32 STT_COMMON = 5;
static constexpr u32 STT_TLS = 6;
static constexpr u32 STT_GNU_IFUNC = 10;
static constexpr u32 STB_LOCAL = 0;
static constexpr u32 STB_GLOBAL = 1;
static constexpr u32 STB_WEAK = 2;
static constexpr u32 STB_GNU_UNIQUE = 10;
static constexpr u32 STV_DEFAULT = 0;
static constexpr u32 STV_INTERNAL = 1;
static constexpr u32 STV_HIDDEN = 2;
static constexpr u32 STV_PROTECTED = 3;
static constexpr u32 VER_NDX_LOCAL = 0;
static constexpr u32 VER_NDX_GLOBAL = 1;
static constexpr u32 VER_NDX_LAST_RESERVED = 1;
static constexpr u32 VER_FLG_BASE = 1;
static constexpr u32 VER_FLG_WEAK = 2;
static constexpr u32 VER_FLG_INFO = 4;
static constexpr u32 VERSYM_HIDDEN = 0x8000;
static constexpr u32 PT_NULL = 0;
static constexpr u32 PT_LOAD = 1;
static constexpr u32 PT_DYNAMIC = 2;
static constexpr u32 PT_INTERP = 3;
static constexpr u32 PT_NOTE = 4;
static constexpr u32 PT_SHLIB = 5;
static constexpr u32 PT_PHDR = 6;
static constexpr u32 PT_TLS = 7;
static constexpr u32 PT_GNU_EH_FRAME = 0x6474e550;
static constexpr u32 PT_GNU_STACK = 0x6474e551;
static constexpr u32 PT_GNU_RELRO = 0x6474e552;
static constexpr u32 PF_X = 1;
static constexpr u32 PF_W = 2;
static constexpr u32 PF_R = 4;
static constexpr u32 ET_NONE = 0;
static constexpr u32 ET_REL = 1;
static constexpr u32 ET_EXEC = 2;
static constexpr u32 ET_DYN = 3;
static constexpr u32 ELFDATA2LSB = 1;
static constexpr u32 ELFDATA2MSB = 2;
static constexpr u32 ELFCLASS32 = 1;
static constexpr u32 ELFCLASS64 = 2;
static constexpr u32 EV_CURRENT = 1;
static constexpr u32 EM_386 = 3;
static constexpr u32 EM_X86_64 = 62;
static constexpr u32 EI_CLASS = 4;
static constexpr u32 EI_DATA = 5;
static constexpr u32 EI_VERSION = 6;
static constexpr u32 EI_OSABI = 7;
static constexpr u32 EI_ABIVERSION = 8;
static constexpr u32 ELFOSABI_NONE = 0;
static constexpr u32 ELFOSABI_GNU = 3;
static constexpr u32 DT_NULL = 0;
static constexpr u32 DT_NEEDED = 1;
static constexpr u32 DT_PLTRELSZ = 2;
static constexpr u32 DT_PLTGOT = 3;
static constexpr u32 DT_HASH = 4;
static constexpr u32 DT_STRTAB = 5;
static constexpr u32 DT_SYMTAB = 6;
static constexpr u32 DT_RELA = 7;
static constexpr u32 DT_RELASZ = 8;
static constexpr u32 DT_RELAENT = 9;
static constexpr u32 DT_STRSZ = 10;
static constexpr u32 DT_SYMENT = 11;
static constexpr u32 DT_INIT = 12;
static constexpr u32 DT_FINI = 13;
static constexpr u32 DT_SONAME = 14;
static constexpr u32 DT_RPATH = 15;
static constexpr u32 DT_SYMBOLIC = 16;
static constexpr u32 DT_REL = 17;
static constexpr u32 DT_RELSZ = 18;
static constexpr u32 DT_RELENT = 19;
static constexpr u32 DT_PLTREL = 20;
static constexpr u32 DT_DEBUG = 21;
static constexpr u32 DT_TEXTREL = 22;
static constexpr u32 DT_JMPREL = 23;
static constexpr u32 DT_BIND_NOW = 24;
static constexpr u32 DT_INIT_ARRAY = 25;
static constexpr u32 DT_FINI_ARRAY = 26;
static constexpr u32 DT_INIT_ARRAYSZ = 27;
static constexpr u32 DT_FINI_ARRAYSZ = 28;
static constexpr u32 DT_RUNPATH = 29;
static constexpr u32 DT_FLAGS = 30;
static constexpr u32 DT_GNU_HASH = 0x6ffffef5;
static constexpr u32 DT_VERSYM = 0x6ffffff0;
static constexpr u32 DT_RELACOUNT = 0x6ffffff9;
static constexpr u32 DT_RELCOUNT = 0x6ffffffa;
static constexpr u32 DT_FLAGS_1 = 0x6ffffffb;
static constexpr u32 DT_VERDEF = 0x6ffffffc;
static constexpr u32 DT_VERDEFNUM = 0x6ffffffd;
static constexpr u32 DT_VERNEED = 0x6ffffffe;
static constexpr u32 DT_VERNEEDNUM = 0x6fffffff;
static constexpr u32 DT_AUXILIARY = 0x7ffffffd;
static constexpr u32 DT_FILTER = 0x7fffffff;
static constexpr u32 DF_ORIGIN = 0x01;
static constexpr u32 DF_SYMBOLIC = 0x02;
static constexpr u32 DF_TEXTREL = 0x04;
static constexpr u32 DF_BIND_NOW = 0x08;
static constexpr u32 DF_STATIC_TLS = 0x10;
static constexpr u32 DF_1_NOW = 0x00000001;
static constexpr u32 DF_1_NODELETE = 0x00000008;
static constexpr u32 DF_1_INITFIRST = 0x00000020;
static constexpr u32 DF_1_NOOPEN = 0x00000040;
static constexpr u32 DF_1_ORIGIN = 0x00000080;
static constexpr u32 DF_1_INTERPOSE = 0x00000400;
static constexpr u32 DF_1_NODUMP = 0x00001000;
static constexpr u32 DF_1_PIE = 0x08000000;
static constexpr u32 NT_GNU_ABI_TAG = 1;
static constexpr u32 NT_GNU_HWCAP = 2;
static constexpr u32 NT_GNU_BUILD_ID = 3;
static constexpr u32 NT_GNU_GOLD_VERSION = 4;
static constexpr u32 NT_GNU_PROPERTY_TYPE_0 = 5;
static constexpr u32 GNU_PROPERTY_AARCH64_FEATURE_1_AND = 0xc0000000;
static constexpr u32 GNU_PROPERTY_X86_FEATURE_1_AND = 0xc0000002;
static constexpr u32 ELFCOMPRESS_ZLIB = 1;
static constexpr u32 R_X86_64_NONE = 0;
static constexpr u32 R_X86_64_64 = 1;
static constexpr u32 R_X86_64_PC32 = 2;
static constexpr u32 R_X86_64_GOT32 = 3;
static constexpr u32 R_X86_64_PLT32 = 4;
static constexpr u32 R_X86_64_COPY = 5;
static constexpr u32 R_X86_64_GLOB_DAT = 6;
static constexpr u32 R_X86_64_JUMP_SLOT = 7;
static constexpr u32 R_X86_64_RELATIVE = 8;
static constexpr u32 R_X86_64_GOTPCREL = 9;
static constexpr u32 R_X86_64_32 = 10;
static constexpr u32 R_X86_64_32S = 11;
static constexpr u32 R_X86_64_16 = 12;
static constexpr u32 R_X86_64_PC16 = 13;
static constexpr u32 R_X86_64_8 = 14;
static constexpr u32 R_X86_64_PC8 = 15;
static constexpr u32 R_X86_64_DTPMOD64 = 16;
static constexpr u32 R_X86_64_DTPOFF64 = 17;
static constexpr u32 R_X86_64_TPOFF64 = 18;
static constexpr u32 R_X86_64_TLSGD = 19;
static constexpr u32 R_X86_64_TLSLD = 20;
static constexpr u32 R_X86_64_DTPOFF32 = 21;
static constexpr u32 R_X86_64_GOTTPOFF = 22;
static constexpr u32 R_X86_64_TPOFF32 = 23;
static constexpr u32 R_X86_64_PC64 = 24;
static constexpr u32 R_X86_64_GOTOFF64 = 25;
static constexpr u32 R_X86_64_GOTPC32 = 26;
static constexpr u32 R_X86_64_GOT64 = 27;
static constexpr u32 R_X86_64_GOTPCREL64 = 28;
static constexpr u32 R_X86_64_GOTPC64 = 29;
static constexpr u32 R_X86_64_GOTPLT64 = 30;
static constexpr u32 R_X86_64_PLTOFF64 = 31;
static constexpr u32 R_X86_64_SIZE32 = 32;
static constexpr u32 R_X86_64_SIZE64 = 33;
static constexpr u32 R_X86_64_GOTPC32_TLSDESC = 34;
static constexpr u32 R_X86_64_TLSDESC_CALL = 35;
static constexpr u32 R_X86_64_TLSDESC = 36;
static constexpr u32 R_X86_64_IRELATIVE = 37;
static constexpr u32 R_X86_64_GOTPCRELX = 41;
static constexpr u32 R_X86_64_REX_GOTPCRELX = 42;
template <>
inline std::string rel_to_string<X86_64>(u32 r_type) {
switch (r_type) {
case R_X86_64_NONE: return "R_X86_64_NONE";
case R_X86_64_64: return "R_X86_64_64";
case R_X86_64_PC32: return "R_X86_64_PC32";
case R_X86_64_GOT32: return "R_X86_64_GOT32";
case R_X86_64_PLT32: return "R_X86_64_PLT32";
case R_X86_64_COPY: return "R_X86_64_COPY";
case R_X86_64_GLOB_DAT: return "R_X86_64_GLOB_DAT";
case R_X86_64_JUMP_SLOT: return "R_X86_64_JUMP_SLOT";
case R_X86_64_RELATIVE: return "R_X86_64_RELATIVE";
case R_X86_64_GOTPCREL: return "R_X86_64_GOTPCREL";
case R_X86_64_32: return "R_X86_64_32";
case R_X86_64_32S: return "R_X86_64_32S";
case R_X86_64_16: return "R_X86_64_16";
case R_X86_64_PC16: return "R_X86_64_PC16";
case R_X86_64_8: return "R_X86_64_8";
case R_X86_64_PC8: return "R_X86_64_PC8";
case R_X86_64_DTPMOD64: return "R_X86_64_DTPMOD64";
case R_X86_64_DTPOFF64: return "R_X86_64_DTPOFF64";
case R_X86_64_TPOFF64: return "R_X86_64_TPOFF64";
case R_X86_64_TLSGD: return "R_X86_64_TLSGD";
case R_X86_64_TLSLD: return "R_X86_64_TLSLD";
case R_X86_64_DTPOFF32: return "R_X86_64_DTPOFF32";
case R_X86_64_GOTTPOFF: return "R_X86_64_GOTTPOFF";
case R_X86_64_TPOFF32: return "R_X86_64_TPOFF32";
case R_X86_64_PC64: return "R_X86_64_PC64";
case R_X86_64_GOTOFF64: return "R_X86_64_GOTOFF64";
case R_X86_64_GOTPC32: return "R_X86_64_GOTPC32";
case R_X86_64_GOT64: return "R_X86_64_GOT64";
case R_X86_64_GOTPCREL64: return "R_X86_64_GOTPCREL64";
case R_X86_64_GOTPC64: return "R_X86_64_GOTPC64";
case R_X86_64_GOTPLT64: return "R_X86_64_GOTPLT64";
case R_X86_64_PLTOFF64: return "R_X86_64_PLTOFF64";
case R_X86_64_SIZE32: return "R_X86_64_SIZE32";
case R_X86_64_SIZE64: return "R_X86_64_SIZE64";
case R_X86_64_GOTPC32_TLSDESC: return "R_X86_64_GOTPC32_TLSDESC";
case R_X86_64_TLSDESC_CALL: return "R_X86_64_TLSDESC_CALL";
case R_X86_64_TLSDESC: return "R_X86_64_TLSDESC";
case R_X86_64_IRELATIVE: return "R_X86_64_IRELATIVE";
case R_X86_64_GOTPCRELX: return "R_X86_64_GOTPCRELX";
case R_X86_64_REX_GOTPCRELX: return "R_X86_64_REX_GOTPCRELX";
}
return "unknown (" + std::to_string(r_type) + ")";
}
static constexpr u32 R_386_NONE = 0;
static constexpr u32 R_386_32 = 1;
static constexpr u32 R_386_PC32 = 2;
static constexpr u32 R_386_GOT32 = 3;
static constexpr u32 R_386_PLT32 = 4;
static constexpr u32 R_386_COPY = 5;
static constexpr u32 R_386_GLOB_DAT = 6;
static constexpr u32 R_386_JUMP_SLOT = 7;
static constexpr u32 R_386_RELATIVE = 8;
static constexpr u32 R_386_GOTOFF = 9;
static constexpr u32 R_386_GOTPC = 10;
static constexpr u32 R_386_32PLT = 11;
static constexpr u32 R_386_TLS_TPOFF = 14;
static constexpr u32 R_386_TLS_IE = 15;
static constexpr u32 R_386_TLS_GOTIE = 16;
static constexpr u32 R_386_TLS_LE = 17;
static constexpr u32 R_386_TLS_GD = 18;
static constexpr u32 R_386_TLS_LDM = 19;
static constexpr u32 R_386_16 = 20;
static constexpr u32 R_386_PC16 = 21;
static constexpr u32 R_386_8 = 22;
static constexpr u32 R_386_PC8 = 23;
static constexpr u32 R_386_TLS_GD_32 = 24;
static constexpr u32 R_386_TLS_GD_PUSH = 25;
static constexpr u32 R_386_TLS_GD_CALL = 26;
static constexpr u32 R_386_TLS_GD_POP = 27;
static constexpr u32 R_386_TLS_LDM_32 = 28;
static constexpr u32 R_386_TLS_LDM_PUSH = 29;
static constexpr u32 R_386_TLS_LDM_CALL = 30;
static constexpr u32 R_386_TLS_LDM_POP = 31;
static constexpr u32 R_386_TLS_LDO_32 = 32;
static constexpr u32 R_386_TLS_IE_32 = 33;
static constexpr u32 R_386_TLS_LE_32 = 34;
static constexpr u32 R_386_TLS_DTPMOD32 = 35;
static constexpr u32 R_386_TLS_DTPOFF32 = 36;
static constexpr u32 R_386_TLS_TPOFF32 = 37;
static constexpr u32 R_386_SIZE32 = 38;
static constexpr u32 R_386_TLS_GOTDESC = 39;
static constexpr u32 R_386_TLS_DESC_CALL = 40;
static constexpr u32 R_386_TLS_DESC = 41;
static constexpr u32 R_386_IRELATIVE = 42;
static constexpr u32 R_386_GOT32X = 43;
template <>
std::string rel_to_string<I386>(u32 r_type) {
switch (r_type) {
case R_386_NONE: return "R_386_NONE";
case R_386_32: return "R_386_32";
case R_386_PC32: return "R_386_PC32";
case R_386_GOT32: return "R_386_GOT32";
case R_386_PLT32: return "R_386_PLT32";
case R_386_COPY: return "R_386_COPY";
case R_386_GLOB_DAT: return "R_386_GLOB_DAT";
case R_386_JUMP_SLOT: return "R_386_JUMP_SLOT";
case R_386_RELATIVE: return "R_386_RELATIVE";
case R_386_GOTOFF: return "R_386_GOTOFF";
case R_386_GOTPC: return "R_386_GOTPC";
case R_386_32PLT: return "R_386_32PLT";
case R_386_TLS_TPOFF: return "R_386_TLS_TPOFF";
case R_386_TLS_IE: return "R_386_TLS_IE";
case R_386_TLS_GOTIE: return "R_386_TLS_GOTIE";
case R_386_TLS_LE: return "R_386_TLS_LE";
case R_386_TLS_GD: return "R_386_TLS_GD";
case R_386_TLS_LDM: return "R_386_TLS_LDM";
case R_386_16: return "R_386_16";
case R_386_PC16: return "R_386_PC16";
case R_386_8: return "R_386_8";
case R_386_PC8: return "R_386_PC8";
case R_386_TLS_GD_32: return "R_386_TLS_GD_32";
case R_386_TLS_GD_PUSH: return "R_386_TLS_GD_PUSH";
case R_386_TLS_GD_CALL: return "R_386_TLS_GD_CALL";
case R_386_TLS_GD_POP: return "R_386_TLS_GD_POP";
case R_386_TLS_LDM_32: return "R_386_TLS_LDM_32";
case R_386_TLS_LDM_PUSH: return "R_386_TLS_LDM_PUSH";
case R_386_TLS_LDM_CALL: return "R_386_TLS_LDM_CALL";
case R_386_TLS_LDM_POP: return "R_386_TLS_LDM_POP";
case R_386_TLS_LDO_32: return "R_386_TLS_LDO_32";
case R_386_TLS_IE_32: return "R_386_TLS_IE_32";
case R_386_TLS_LE_32: return "R_386_TLS_LE_32";
case R_386_TLS_DTPMOD32: return "R_386_TLS_DTPMOD32";
case R_386_TLS_DTPOFF32: return "R_386_TLS_DTPOFF32";
case R_386_TLS_TPOFF32: return "R_386_TLS_TPOFF32";
case R_386_SIZE32: return "R_386_SIZE32";
case R_386_TLS_GOTDESC: return "R_386_TLS_GOTDESC";
case R_386_TLS_DESC_CALL: return "R_386_TLS_DESC_CALL";
case R_386_TLS_DESC: return "R_386_TLS_DESC";
case R_386_IRELATIVE: return "R_386_IRELATIVE";
case R_386_GOT32X: return "R_386_GOT32X";
}
return "unknown (" + std::to_string(r_type) + ")";
}
static constexpr u32 DW_EH_PE_absptr = 0;
static constexpr u32 DW_EH_PE_omit = 0xff;
static constexpr u32 DW_EH_PE_uleb128 = 0x01;
static constexpr u32 DW_EH_PE_udata2 = 0x02;
static constexpr u32 DW_EH_PE_udata4 = 0x03;
static constexpr u32 DW_EH_PE_udata8 = 0x04;
static constexpr u32 DW_EH_PE_signed = 0x08;
static constexpr u32 DW_EH_PE_sleb128 = 0x09;
static constexpr u32 DW_EH_PE_sdata2 = 0x0a;
static constexpr u32 DW_EH_PE_sdata4 = 0x0b;
static constexpr u32 DW_EH_PE_sdata8 = 0x0c;
static constexpr u32 DW_EH_PE_pcrel = 0x10;
static constexpr u32 DW_EH_PE_textrel = 0x20;
static constexpr u32 DW_EH_PE_datarel = 0x30;
static constexpr u32 DW_EH_PE_funcrel = 0x40;
static constexpr u32 DW_EH_PE_aligned = 0x50;
struct Elf64Sym {
bool is_defined() const { return !is_undef(); }
bool is_undef() const { return st_shndx == SHN_UNDEF; }
bool is_abs() const { return st_shndx == SHN_ABS; }
bool is_common() const { return st_shndx == SHN_COMMON; }
bool is_weak() const { return st_bind == STB_WEAK; }
bool is_undef_strong() const {
return st_shndx == SHN_UNDEF && st_bind != STB_WEAK;
}
bool is_undef_weak() const {
return st_shndx == SHN_UNDEF && st_bind == STB_WEAK;
}
u32 st_name;
u8 st_type : 4;
u8 st_bind : 4;
u8 st_visibility : 2;
u16 st_shndx;
u64 st_value;
u64 st_size;
};
struct Elf32Sym {
bool is_defined() const { return !is_undef(); }
bool is_undef() const { return st_shndx == SHN_UNDEF; }
bool is_abs() const { return st_shndx == SHN_ABS; }
bool is_common() const { return st_shndx == SHN_COMMON; }
bool is_weak() const { return st_bind == STB_WEAK; }
bool is_undef_strong() const {
return st_shndx == SHN_UNDEF && st_bind != STB_WEAK;
}
bool is_undef_weak() const {
return st_shndx == SHN_UNDEF && st_bind == STB_WEAK;
}
u32 st_name;
u32 st_value;
u32 st_size;
u8 st_type : 4;
u8 st_bind : 4;
u8 st_visibility : 2;
u16 st_shndx;
};
struct Elf64Shdr {
u32 sh_name;
u32 sh_type;
u64 sh_flags;
u64 sh_addr;
u64 sh_offset;
u64 sh_size;
u32 sh_link;
u32 sh_info;
u64 sh_addralign;
u64 sh_entsize;
};
struct Elf32Shdr {
u32 sh_name;
u32 sh_type;
u32 sh_flags;
u32 sh_addr;
u32 sh_offset;
u32 sh_size;
u32 sh_link;
u32 sh_info;
u32 sh_addralign;
u32 sh_entsize;
};
struct Elf64Ehdr {
u8 e_ident[16];
u16 e_type;
u16 e_machine;
u32 e_version;
u64 e_entry;
u64 e_phoff;
u64 e_shoff;
u32 e_flags;
u16 e_ehsize;
u16 e_phentsize;
u16 e_phnum;
u16 e_shentsize;
u16 e_shnum;
u16 e_shstrndx;
};
struct Elf32Ehdr {
u8 e_ident[16];
u16 e_type;
u16 e_machine;
u32 e_version;
u32 e_entry;
u32 e_phoff;
u32 e_shoff;
u32 e_flags;
u16 e_ehsize;
u16 e_phentsize;
u16 e_phnum;
u16 e_shentsize;
u16 e_shnum;
u16 e_shstrndx;
};
struct Elf64Phdr {
u32 p_type;
u32 p_flags;
u64 p_offset;
u64 p_vaddr;
u64 p_paddr;
u64 p_filesz;
u64 p_memsz;
u64 p_align;
};
struct Elf32Phdr {
u32 p_type;
u32 p_offset;
u32 p_vaddr;
u32 p_paddr;
u32 p_filesz;
u32 p_memsz;
u32 p_flags;
u32 p_align;
};
struct Elf64Rel {
u64 r_offset;
u32 r_type;
u32 r_sym;
};
struct Elf32Rel {
u32 r_offset;
u32 r_type : 8;
u32 r_sym : 24;
};
struct Elf64Rela {
u64 r_offset;
u32 r_type;
u32 r_sym;
i64 r_addend;
};
struct Elf32Rela {
u32 r_offset;
u32 r_type : 8;
u32 r_sym : 24;
i32 r_addend;
};
struct Elf64Dyn {
u64 d_tag;
u64 d_val;
};
struct Elf32Dyn {
u32 d_tag;
u32 d_val;
};
struct Elf64Verneed {
u16 vn_version;
u16 vn_cnt;
u32 vn_file;
u32 vn_aux;
u32 vn_next;
};
struct Elf64Vernaux {
u32 vna_hash;
u16 vna_flags;
u16 vna_other;
u32 vna_name;
u32 vna_next;
};
struct Elf64Verdef {
u16 vd_version;
u16 vd_flags;
u16 vd_ndx;
u16 vd_cnt;
u32 vd_hash;
u32 vd_aux;
u32 vd_next;
};
struct Elf64Verdaux {
u32 vda_name;
u32 vda_next;
};
struct Elf64Chdr {
u32 ch_type;
u32 ch_reserved;
u64 ch_size;
u64 ch_addralign;
};
struct Elf32Chdr {
u32 ch_type;
u32 ch_size;
u32 ch_addralign;
};
struct Elf64Nhdr {
u32 n_namesz;
u32 n_descsz;
u32 n_type;
};
template <typename E> struct ElfSym;
template <typename E> struct ElfShdr;
template <typename E> struct ElfEhdr;
template <typename E> struct ElfPhdr;
template <typename E> struct ElfRel;
template <typename E> struct ElfDyn;
template <typename E> struct ElfVerneed;
template <typename E> struct ElfVernaux;
template <typename E> struct ElfVerdef;
template <typename E> struct ElfVerdaux;
template <typename E> struct ElfChdr;
template <typename E> struct ElfNhdr;
struct X86_64 {
typedef u64 WordTy;
static constexpr u32 R_NONE = R_X86_64_NONE;
static constexpr u32 R_COPY = R_X86_64_COPY;
static constexpr u32 R_GLOB_DAT = R_X86_64_GLOB_DAT;
static constexpr u32 R_JUMP_SLOT = R_X86_64_JUMP_SLOT;
static constexpr u32 R_RELATIVE = R_X86_64_RELATIVE;
static constexpr u32 R_IRELATIVE = R_X86_64_IRELATIVE;
static constexpr u32 R_DTPOFF = R_X86_64_DTPOFF64;
static constexpr u32 R_TPOFF = R_X86_64_TPOFF64;
static constexpr u32 R_DTPMOD = R_X86_64_DTPMOD64;
static constexpr u32 R_TLSDESC = R_X86_64_TLSDESC;
static constexpr u32 wordsize = 8;
static constexpr u32 e_machine = EM_X86_64;
static constexpr u32 plt_size = 16;
static constexpr u32 pltgot_size = 8;
static constexpr bool is_rel = false;
static constexpr bool is_le = true;
};
template <> struct ElfSym<X86_64> : public Elf64Sym {};
template <> struct ElfShdr<X86_64> : public Elf64Shdr {};
template <> struct ElfEhdr<X86_64> : public Elf64Ehdr {};
template <> struct ElfPhdr<X86_64> : public Elf64Phdr {};
template <> struct ElfRel<X86_64> : public Elf64Rela {};
template <> struct ElfDyn<X86_64> : public Elf64Dyn {};
template <> struct ElfVerneed<X86_64> : public Elf64Verneed {};
template <> struct ElfVernaux<X86_64> : public Elf64Vernaux {};
template <> struct ElfVerdef<X86_64> : public Elf64Verdef {};
template <> struct ElfVerdaux<X86_64> : public Elf64Verdaux {};
template <> struct ElfChdr<X86_64> : public Elf64Chdr {};
template <> struct ElfNhdr<X86_64> : public Elf64Nhdr {};
struct I386 {
typedef u32 WordTy;
static constexpr u32 R_NONE = R_386_NONE;
static constexpr u32 R_COPY = R_386_COPY;
static constexpr u32 R_GLOB_DAT = R_386_GLOB_DAT;
static constexpr u32 R_JUMP_SLOT = R_386_JUMP_SLOT;
static constexpr u32 R_RELATIVE = R_386_RELATIVE;
static constexpr u32 R_IRELATIVE = R_386_IRELATIVE;
static constexpr u32 R_DTPOFF = R_386_TLS_DTPOFF32;
static constexpr u32 R_TPOFF = R_386_TLS_TPOFF;
static constexpr u32 R_DTPMOD = R_386_TLS_DTPMOD32;
static constexpr u32 R_TLSDESC = R_386_TLS_DESC;
static constexpr u32 wordsize = 4;
static constexpr u32 e_machine = EM_386;
static constexpr u32 plt_size = 16;
static constexpr u32 pltgot_size = 8;
static constexpr bool is_rel = true;
static constexpr bool is_le = true;
};
template <> struct ElfSym<I386> : public Elf32Sym {};
template <> struct ElfShdr<I386> : public Elf32Shdr {};
template <> struct ElfEhdr<I386> : public Elf32Ehdr {};
template <> struct ElfPhdr<I386> : public Elf32Phdr {};
template <> struct ElfRel<I386> : public Elf32Rel {};
template <> struct ElfDyn<I386> : public Elf32Dyn {};
template <> struct ElfVerneed<I386> : public Elf64Verneed {};
template <> struct ElfVernaux<I386> : public Elf64Vernaux {};
template <> struct ElfVerdef<I386> : public Elf64Verdef {};
template <> struct ElfVerdaux<I386> : public Elf64Verdaux {};
template <> struct ElfChdr<I386> : public Elf32Chdr {};
template <> struct ElfNhdr<I386> : public Elf64Nhdr {};
-105
View File
@@ -1,105 +0,0 @@
#include "mold.h"
std::string get_current_dir() {
std::string buf(8192, '\0');
getcwd(buf.data(), buf.size());
buf.resize(buf.find_first_of('\0'));
return buf;
}
// Returns the directory part of a given path.
// Returns '.' if path doesn't contain '/'.
std::string_view path_dirname(std::string_view path) {
i64 pos = path.find_last_of('/');
if (pos == path.npos)
return ".";
return path.substr(0, pos);
}
// Returns the filename part of a given path.
// Returns '/' if path reperesents the root directory.
// Returns '.' if path is empty.
std::string_view path_filename(std::string_view path) {
if (path.empty())
return ".";
while (path.ends_with('/'))
path = path.substr(0, path.size() - 2);
if (path.empty())
return "/";
i64 pos = path.find_last_of('/');
if (pos == path.npos)
return path;
return path.substr(pos + 1);
}
// Returns the filename part of a given path without the file
// extension.
std::string_view path_basename(std::string_view path) {
std::string_view name = path_filename(path);
i64 pos = name.find_last_of('.');
if (pos == name.npos)
return name;
return name.substr(0, pos);
}
std::string path_to_absolute(std::string_view path) {
if (path.starts_with('/'))
return std::string(path);
return get_current_dir() + "/" + std::string(path);
}
// Removes redundant '/..' or '/.' from a given path.
// The transformation is done purely by lexical processing.
// This function does not access file system.
std::string path_clean(std::string_view path) {
std::vector<std::string_view> components;
bool is_rooted = path.starts_with('/');
while (!path.empty()) {
size_t pos = path.find('/');
std::string_view elem;
if (pos == path.npos) {
elem = path;
path = "";
} else {
elem = path.substr(0, pos);
path = path.substr(pos + 1);
}
if (elem.empty() || elem == ".")
continue;
if (elem == "..") {
if (components.empty()) {
if (is_rooted)
continue;
components.push_back("..");
continue;
}
if (components.back() == "..")
components.push_back("..");
else
components.pop_back();
continue;
}
components.push_back(elem);
}
std::string ret;
if (is_rooted)
ret = "/";
for (i64 i = 0, end = components.size(); i < end; i++) {
ret += components[i];
if (i != end - 1)
ret += "/";
}
return ret;
}
-192
View File
@@ -1,192 +0,0 @@
// This file implements a mark-sweep garbage collector for -gc-sections.
// In this algorithm, vertices are sections and edges are relocations.
// Any section that is reachable from a root section is considered alive.
#include "mold.h"
#include <tbb/concurrent_vector.h>
#include <tbb/parallel_for_each.h>
template <typename E>
using Feeder = tbb::parallel_do_feeder<InputSection<E> *>;
template <typename E>
static bool is_init_fini(const InputSection<E> &isec) {
return isec.shdr.sh_type == SHT_INIT_ARRAY ||
isec.shdr.sh_type == SHT_FINI_ARRAY ||
isec.shdr.sh_type == SHT_PREINIT_ARRAY ||
isec.name().starts_with(".ctors") ||
isec.name().starts_with(".dtors") ||
isec.name().starts_with(".init") ||
isec.name().starts_with(".fini");
}
template <typename E>
static bool mark_section(InputSection<E> *isec) {
return isec && isec->is_alive && !isec->is_visited.exchange(true);
}
template <typename E>
static void visit(Context<E> &ctx, InputSection<E> *isec,
Feeder<E> &feeder, i64 depth) {
assert(isec->is_visited);
// A relocation can refer either a section fragment (i.e. a piece of
// string in a mergeable string section) or a symbol. Mark all
// section fragments as alive.
if (isec->rel_fragments)
for (i64 i = 0; isec->rel_fragments[i].idx >= 0; i++)
isec->rel_fragments[i].frag->is_alive = true;
// If this is a text section, .eh_frame may contain records
// describing how to handle exceptions for that function.
// We want to keep associated .eh_frame records.
for (FdeRecord<E> &fde : isec->get_fdes())
for (ElfRel<E> &rel : fde.get_rels().subspan(1))
if (Symbol<E> *sym = isec->file.symbols[rel.r_sym])
if (mark_section(sym->input_section))
feeder.add(sym->input_section);
for (ElfRel<E> &rel : isec->get_rels(ctx)) {
Symbol<E> &sym = *isec->file.symbols[rel.r_sym];
// Symbol can refer either a section fragment or an input section.
// Mark a fragment as alive.
if (SectionFragment<E> *frag = sym.get_frag()) {
frag->is_alive = true;
continue;
}
if (!mark_section(sym.input_section))
continue;
// Mark a section alive. For better performacne, we don't call
// `feeder.add` too often.
if (depth < 3)
visit(ctx, sym.input_section, feeder, depth + 1);
else
feeder.add(sym.input_section);
}
}
template <typename E>
static tbb::concurrent_vector<InputSection<E> *>
collect_root_set(Context<E> &ctx) {
Timer t(ctx, "collect_root_set");
tbb::concurrent_vector<InputSection<E> *> roots;
auto enqueue_section = [&](InputSection<E> *isec) {
if (mark_section(isec))
roots.push_back(isec);
};
auto enqueue_symbol = [&](Symbol<E> *sym) {
if (sym) {
if (SectionFragment<E> *frag = sym->get_frag())
frag->is_alive = true;
else
enqueue_section(sym->input_section);
}
};
// Add sections that are not subject to garbage collection.
tbb::parallel_for_each(ctx.objs, [&](ObjectFile<E> *file) {
for (std::unique_ptr<InputSection<E>> &isec : file->sections) {
if (!isec || !isec->is_alive)
continue;
// -gc-sections discards only SHF_ALLOC sections. If you want to
// reduce the amount of non-memory-mapped segments, you should
// use `strip` command, compile without debug info or use
// -strip-all linker option.
if (!(isec->shdr.sh_flags & SHF_ALLOC))
isec->is_visited = true;
if (is_init_fini(*isec) || is_c_identifier(isec->name()) ||
isec->shdr.sh_type == SHT_NOTE)
enqueue_section(isec.get());
}
});
// Add sections containing exported symbols
tbb::parallel_for_each(ctx.objs, [&](ObjectFile<E> *file) {
for (Symbol<E> *sym : file->symbols)
if (sym->file == file && sym->is_exported)
enqueue_symbol(sym);
});
// Add sections referenced by root symbols.
enqueue_symbol(Symbol<E>::intern(ctx, ctx.arg.entry));
for (std::string_view name : ctx.arg.undefined)
enqueue_symbol(Symbol<E>::intern(ctx, name));
// .eh_frame consists of variable-length records called CIE and FDE
// records, and they are a unit of inclusion or exclusion.
// We just keep all CIEs and everything that are referenced by them.
tbb::parallel_for_each(ctx.objs, [&](ObjectFile<E> *file) {
for (CieRecord<E> &cie : file->cies)
for (ElfRel<E> &rel : cie.get_rels())
enqueue_symbol(file->symbols[rel.r_sym]);
});
return roots;
}
// Mark all reachable sections
template <typename E>
static void mark(Context<E> &ctx,
tbb::concurrent_vector<InputSection<E> *> &roots) {
Timer t(ctx, "mark");
tbb::parallel_do(roots, [&](InputSection<E> *isec, Feeder<E> &feeder) {
visit(ctx, isec, feeder, 0);
});
}
// Remove unreachable sections
template <typename E>
static void sweep(Context<E> &ctx) {
Timer t(ctx, "sweep");
static Counter counter("garbage_sections");
tbb::parallel_for_each(ctx.objs, [&](ObjectFile<E> *file) {
for (i64 i = 0; i < file->sections.size(); i++) {
std::unique_ptr<InputSection<E>> &isec = file->sections[i];
if (isec && isec->is_alive && !isec->is_visited) {
if (ctx.arg.print_gc_sections)
SyncOut(ctx) << "removing unused section " << *isec;
isec->kill();
counter++;
}
}
});
}
// Non-alloc section fragments are not subject of garbage collection.
// This function marks such fragments.
template <typename E>
static void mark_nonalloc_fragments(Context<E> &ctx) {
Timer t(ctx, "mark_nonalloc_fragments");
tbb::parallel_for_each(ctx.objs, [](ObjectFile<E> *file) {
for (SectionFragment<E> *frag : file->fragments)
if (!(frag->output_section.shdr.sh_flags & SHF_ALLOC))
frag->is_alive = true;
});
}
template <typename E>
void gc_sections(Context<E> &ctx) {
Timer t(ctx, "gc");
mark_nonalloc_fragments(ctx);
tbb::concurrent_vector<InputSection<E> *> roots = collect_root_set(ctx);
mark(ctx, roots);
sweep(ctx);
}
template void gc_sections(Context<X86_64> &ctx);
template void gc_sections(Context<I386> &ctx);
-76
View File
@@ -1,76 +0,0 @@
#!/bin/bash
#
# This test script takes a Gentoo package name and tries to build it
# using mold in a Docker environment. We chose Gentoo Linux as a test
# target, because its source-based package allows us to build programs
# locally and run their test suites without any hassle.
#
# You can get a complete list of Gentoo packages availalbe for testing
# with the following command:
#
# docker run --rm mold-gentoo emerge --color n -s '' | \
# perl -ne 'next unless m!^\*\s+(\S+/\S+)!; print "$1\n"'
if [ "$1" = "" ]; then
echo "Usage: $0 gentoo-package-name"
exit 1
fi
set -x
# Create a Docker image
if ! docker image ls mold-gentoo | grep -q mold-gentoo; then
set -e
cat <<EOF | docker build -t mold-gentoo -
FROM gentoo/stage3
RUN emerge-webrsync
RUN echo 'USE="elogind -systemd corefonts truetype jpeg jpeg2k tiff zstd static-libs binary"' >> /etc/portage/make.conf && \
echo 'ACCEPT_LICENSE="* -@EULA"' >> /etc/portage/make.conf && \
echo 'FEATURES="${FEATURE} noclean nostrip -ipc-sandbox -network-sandbox -pid-sandbox -sandbox"' >> /etc/portage/make.conf
RUN emerge gdb lld vim strace && rm -rf /var/tmp/portage
EOF
set +e
fi
# Build mold as a statically-linked executable
if ! [ -f mold ] || ! ldd mold 2>&1 | grep -q 'not a dynamic executable'; then
make clean
./build-static.sh
fi
git_hash=$(./mold --version | perl -ne '/\((\w+)/; print $1;')
# Build a given package in Docker
build() {
package="$1"
cmd1="ln -sf /mold/mold /usr/x86_64-pc-linux-gnu/bin/ld"
cmd2="MAKEOPTS=-j8 emerge --onlydeps $package"
cmd3="MAKEOPTS=-j8 FEATURES=test emerge $package"
filename=`echo "$package" | sed 's!/!_!g'`
docker="docker run --rm --cap-add=SYS_PTRACE -v `pwd`:/mold mold-gentoo timeout -v -k 15s 1h"
dir=gentoo/$git_hash
mkdir -p $dir/success $dir/failure
$docker nice -n 19 bash -c "$cmd1 && $cmd2 && $cmd3" >& $dir/$filename.mold
if [ $? = 0 ]; then
mv $dir/$filename.mold $dir/success
else
mv $dir/$filename.mold $dir/failure
fi
$docker nice -n 19 bash -c "$cmd2 && $cmd3" >& $dir/$filename.ld
if [ $? = 0 ]; then
mv $dir/$filename.ld $dir/success
else
mv $dir/$filename.ld $dir/failure
fi
}
if [ "$1" = dev-libs/concurrencykit ]; then
echo "Skipping known broken package: $1"
exit 0
fi
# Build a package
build "$1"
-154
View File
@@ -1,154 +0,0 @@
#include "mold.h"
#include <limits>
template <typename E>
InputSection<E>::InputSection(Context<E> &ctx, ObjectFile<E> &file,
const ElfShdr<E> &shdr, std::string_view name,
std::string_view contents, i64 section_idx)
: file(file), shdr(shdr), nameptr(name.data()), namelen(name.size()),
contents(contents), section_idx(section_idx) {
// As a special case, we want to map .ctors and .dtors to
// .init_array and .fini_array, respectively. However, old CRT
// object files are not compatible with this translation, so we need
// to keep them as-is if a section came from crtbegin.o or crtend.o.
//
// Yeah, this is an ugly hack, but the fundamental problem is that
// we have two different mechanism, ctors/dtors and init_array/fini_array
// for the same purpose. The latter was introduced to replace the
// former, but as it is often the case, the former still lingers
// around, so we need to keep this code to conver the old mechanism
// to the new one.
std::string_view stem = path_filename(file.filename);
if (stem != "crtbegin.o" && stem != "crtend.o" &&
stem != "crtbeginS.o" && stem != "crtendS.o") {
if (name == ".ctors" || name.starts_with(".ctors."))
name = ".init_array";
else if (name == ".dtors" || name.starts_with(".dtors."))
name = ".fini_array";
}
output_section =
OutputSection<E>::get_instance(ctx, name, shdr.sh_type, shdr.sh_flags);
}
template <typename E>
void InputSection<E>::write_to(Context<E> &ctx, u8 *buf) {
if (shdr.sh_type == SHT_NOBITS || shdr.sh_size == 0)
return;
// Copy data
memcpy(buf, contents.data(), contents.size());
// Apply relocations
if (shdr.sh_flags & SHF_ALLOC)
apply_reloc_alloc(ctx, buf);
else
apply_reloc_nonalloc(ctx, buf);
// As a special case, .ctors and .dtors section contents are
// reversed. These sections are now obsolete and mapped to
// .init_array and .fini_array, but they have to be reversed to
// maintain the original semantics.
bool init_fini = output_section->name == ".init_array" ||
output_section->name == ".fini_array";
bool ctors_dtors = name().starts_with(".ctors") ||
name().starts_with(".dtors");
if (init_fini && ctors_dtors)
std::reverse((typename E::WordTy *)buf,
(typename E::WordTy *)(buf + shdr.sh_size));
}
template <typename E>
static i64 get_output_type(Context<E> &ctx) {
if (ctx.arg.shared)
return 0;
if (ctx.arg.pie)
return 1;
return 2;
}
template <typename E>
static i64 get_sym_type(Context<E> &ctx, Symbol<E> &sym) {
if (sym.is_absolute(ctx))
return 0;
if (!sym.is_imported)
return 1;
if (sym.get_type() != STT_FUNC)
return 2;
return 3;
}
template <typename E>
void InputSection<E>::dispatch(Context<E> &ctx, Action table[3][4],
u16 rel_type, i64 i) {
std::span<ElfRel<E>> rels = get_rels(ctx);
const ElfRel<E> &rel = rels[i];
Symbol<E> &sym = *file.symbols[rel.r_sym];
bool is_writable = (shdr.sh_flags & SHF_WRITE);
Action action = table[get_output_type(ctx)][get_sym_type(ctx, sym)];
switch (action) {
case NONE:
rel_types[i] = rel_type;
return;
case ERROR:
break;
case COPYREL:
if (!ctx.arg.z_copyreloc && !sym.esym().is_undef_weak())
break;
if (sym.esym().st_visibility == STV_PROTECTED)
Error(ctx) << *this << ": cannot make copy relocation for "
<< " protected symbol '" << sym << "', defined in "
<< *sym.file;
sym.flags |= NEEDS_COPYREL;
rel_types[i] = rel_type;
return;
case PLT:
sym.flags |= NEEDS_PLT;
rel_types[i] = rel_type;
return;
case DYNREL:
if (!is_writable) {
if (ctx.arg.z_text)
break;
ctx.has_textrel = true;
}
sym.flags |= NEEDS_DYNSYM;
rel_types[i] = R_DYN;
file.num_dynrel++;
return;
case BASEREL:
if (!is_writable) {
if (ctx.arg.z_text)
break;
ctx.has_textrel = true;
}
rel_types[i] = R_BASEREL;
file.num_dynrel++;
return;
default:
unreachable(ctx);
}
Error(ctx) << *this << ": " << rel_to_string<E>(rel.r_type)
<< " relocation against symbol `" << sym
<< "' can not be used; recompile with -fPIE";
}
template <typename E>
void InputSection<E>::report_undef(Context<E> &ctx, Symbol<E> &sym) {
switch (ctx.arg.unresolved_symbols) {
case UnresolvedKind::ERROR:
Error(ctx) << "undefined symbol: " << file << ": " << sym;
break;
case UnresolvedKind::WARN:
Warn(ctx) << "undefined symbol: " << file << ": " << sym;
break;
case UnresolvedKind::IGNORE:
break;
}
}
template class InputSection<X86_64>;
template class InputSection<I386>;
+52
View File
@@ -0,0 +1,52 @@
#!/bin/sh
# This script installs binary packages needed to build mold.
# Feel free to send me a PR if your OS is not on this list.
set -e
. /etc/os-release
set -x
case "$ID" in
ubuntu | pop | linuxmint | debian | raspbian | neon)
apt-get update
apt-get install -y cmake gcc g++ clang gdb
;;
fedora | amzn | rhel | centos)
dnf install -y gcc-g++ cmake glibc-static libstdc++-static diffutils util-linux tar
;;
rocky)
dnf install -y gcc-g++ cmake diffutils util-linux
;;
opensuse-*)
zypper install -y make cmake gcc-c++ glibc-devel-static tar diffutils util-linux
;;
gentoo)
emerge-webrsync
FEATURES='getbinpkg binpkg-request-signature' emerge dev-build/cmake
;;
arch | archarm | artix | endeavouros)
pacman -Sy --needed --noconfirm base-devel cmake util-linux
;;
void)
xbps-install -Sy xbps bash make cmake gcc tar diffutils util-linux
;;
alpine)
apk update
apk add bash make linux-headers cmake gcc g++
;;
clear-linux-os)
swupd update
swupd bundle-add c-basic diffutils
;;
almalinux)
dnf install -y gcc-toolset-13-gcc-c++ gcc-toolset-13-libstdc++-devel cmake diffutils
;;
freebsd)
pkg update
pkg install -y cmake bash binutils gcc
;;
*)
echo "Error: don't know anything about build dependencies on $ID-$VERSION_ID"
exit 1
esac
+19
View File
@@ -0,0 +1,19 @@
#!/bin/bash
set -e
. /etc/os-release
set -x
# This script install packages for -DMOLD_ENABLE_QEMU_TESTS=1
# to enable cross-target tests.
#
# Feel free to send me a PR if your OS is not on this list.
case "$ID" in
ubuntu | pop | linuxmint | debian | raspbian)
apt-get install -y qemu-user {gcc,g++}-{i686,aarch64,riscv64,powerpc,powerpc64,powerpc64le,s390x,sparc64,m68k,sh4,arc}-linux-gnu {gcc,g++}-arm-linux-gnueabihf
;;
*)
echo "Error: don't know anything about build dependencies on $ID-$VERSION_ID"
exit 1
esac
+173
View File
@@ -0,0 +1,173 @@
// This file contains functions to read an archive file (.a file).
// An archive file is just a bundle of object files. It's similar to
// tar or zip, but the contents are not compressed.
//
// An archive file is either "regular" or "thin". A regular archive
// contains object files directly, while a thin archive contains only
// pathnames. In the latter case, actual file contents have to be read
// from given pathnames. A regular archive is sometimes called "fat"
// archive as opposed to "thin".
//
// If an archive file is given to the linker, the linker pulls out
// object files that are needed to resolve undefined symbols. So,
// bunding object files as an archive and giving that archive to the
// linker has a different meaning than directly giving the same set of
// object files to the linker. The former links only needed object
// files, while the latter links all the given object files.
//
// Therefore, if you link libc.a for example, not all the libc
// functions are linked to your binary. Instead, only object files
// that provides functions and variables used in your program get
// linked. To make this efficient, static library functions are
// usually separated to each object file in an archive file. You can
// see the contents of libc.a by running `ar t
// /usr/lib/x86_64-linux-gnu/libc.a`.
#pragma once
#include "common.h"
namespace mold {
struct ArHdr {
char ar_name[16];
char ar_date[12];
char ar_uid[6];
char ar_gid[6];
char ar_mode[8];
char ar_size[10];
char ar_fmag[2];
bool starts_with(std::string_view s) const {
return std::string_view(ar_name, s.size()) == s;
}
bool is_strtab() const {
return starts_with("// ");
}
bool is_symtab() const {
return starts_with("/ ") || starts_with("/SYM64/ ");
}
std::string read_name(std::string_view strtab, u8 *&ptr) const {
// BSD-style long filename
if (starts_with("#1/")) {
int namelen = atoi(ar_name + 3);
std::string name{(char *)ptr, (size_t)namelen};
ptr += namelen;
if (size_t pos = name.find('\0'))
name = name.substr(0, pos);
return name;
}
// SysV-style long filename
if (starts_with("/")) {
const char *start = strtab.data() + atoi(ar_name + 1);
return {start, (const char *)strstr(start, "/\n")};
}
// Short fileanme
if (const char *end = (char *)memchr(ar_name, '/', sizeof(ar_name)))
return {ar_name, end};
return {ar_name, sizeof(ar_name)};
}
};
template <typename Context>
std::vector<MappedFile *>
read_thin_archive_members(Context &ctx, MappedFile *mf) {
u8 *begin = mf->data;
u8 *data = begin + 8;
std::vector<MappedFile *> vec;
std::string_view strtab;
while (data < begin + mf->size) {
// Each header is aligned to a 2 byte boundary.
if ((begin - data) % 2)
data++;
ArHdr &hdr = *(ArHdr *)data;
u8 *body = data + sizeof(hdr);
u64 size = atol(hdr.ar_size);
// Read a string table.
if (hdr.is_strtab()) {
strtab = {(char *)body, (size_t)size};
data = body + size;
continue;
}
// Skip a symbol table.
if (hdr.is_symtab()) {
data = body + size;
continue;
}
if (!hdr.starts_with("#1/") && !hdr.starts_with("/"))
Fatal(ctx) << mf->name << ": filename is not stored as a long filename";
std::string name = hdr.read_name(strtab, body);
// Skip if symbol table
if (name == "__.SYMDEF" || name == "__.SYMDEF SORTED")
continue;
std::string path = name.starts_with('/') ?
name : (path_dirname(mf->name) / name).string();
vec.push_back(must_open_file(ctx, path));
vec.back()->thin_parent = mf;
data = body;
}
return vec;
}
template <typename Context>
std::vector<MappedFile *> read_fat_archive_members(Context &ctx, MappedFile *mf) {
u8 *begin = mf->data;
u8 *data = begin + 8;
std::vector<MappedFile *> vec;
std::string_view strtab;
while (begin + mf->size - data >= 2) {
if ((begin - data) % 2)
data++;
ArHdr &hdr = *(ArHdr *)data;
u8 *body = data + sizeof(hdr);
u64 size = atol(hdr.ar_size);
data = body + size;
// Read if string table
if (hdr.is_strtab()) {
strtab = {(char *)body, (size_t)size};
continue;
}
// Skip if symbol table
if (hdr.is_symtab())
continue;
// Read the name field
std::string name = hdr.read_name(strtab, body);
// Skip if symbol table
if (name == "__.SYMDEF" || name == "__.SYMDEF SORTED")
continue;
vec.push_back(mf->slice(ctx, name, body - begin, data - body));
}
return vec;
}
template <typename Context>
std::vector<MappedFile *> read_archive_members(Context &ctx, MappedFile *mf) {
std::string_view str = mf->get_contents();
if (str.starts_with("!<arch>\n"))
return read_fat_archive_members(ctx, mf);
assert(str.starts_with("!<thin>\n"));
return read_thin_archive_members(ctx, mf);
}
} // namespace mold
+979
View File
@@ -0,0 +1,979 @@
#pragma once
#include "config.h"
#include "integers.h"
#include <array>
#include <atomic>
#include <bit>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fcntl.h>
#include <filesystem>
#include <iostream>
#include <mutex>
#include <optional>
#include <span>
#include <sstream>
#include <string>
#include <string_view>
#include <sys/stat.h>
#include <sys/types.h>
#include <tbb/concurrent_vector.h>
#include <tbb/enumerable_thread_specific.h>
#include <tbb/parallel_for.h>
#include <vector>
#ifdef _WIN32
# include <io.h>
#else
# include <sys/mman.h>
# include <unistd.h>
#endif
#define XXH_INLINE_ALL 1
#include "../third-party/xxhash/xxhash.h"
#ifdef NDEBUG
# define unreachable() __builtin_unreachable()
#else
# define unreachable() assert(0 && "unreachable")
#endif
inline uint64_t hash_string(std::string_view str) {
return XXH3_64bits(str.data(), str.size());
}
class HashCmp {
public:
static size_t hash(const std::string_view &k) {
return hash_string(k);
}
static bool equal(const std::string_view &k1, const std::string_view &k2) {
return k1 == k2;
}
};
namespace mold {
namespace ranges = std::ranges;
using namespace std::literals::string_literals;
using namespace std::literals::string_view_literals;
inline char *output_tmpfile;
inline u8 *output_buffer_start = nullptr;
inline u8 *output_buffer_end = nullptr;
extern std::string mold_git_hash;
std::string errno_string();
void cleanup();
void install_signal_handler();
inline u64 combine_hash(u64 a, u64 b) {
return a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2));
}
//
// Error output
//
// Some C++ stdlibs don't support std::osyncstream even though
// it's is in the C++20 standard. So we implement it ourselves.
class SyncStream {
public:
SyncStream(std::ostream &out) : out(out) {}
~SyncStream() {
emit();
}
template <typename T> SyncStream &operator<<(T &&val) {
ss << std::forward<T>(val);
return *this;
}
void emit() {
if (emitted)
return;
std::scoped_lock lock(mu);
out << ss.str() << '\n';
emitted = true;
}
private:
std::ostream &out;
std::stringstream ss;
bool emitted = false;
static inline std::mutex mu;
};
template <typename Context>
class Out {
public:
Out(Context &ctx) {}
template <typename T> Out &operator<<(T &&val) {
out << std::forward<T>(val);
return *this;
}
private:
SyncStream out{std::cout};
};
static std::string_view fatal_mono = "mold: fatal: ";
static std::string_view fatal_color = "mold: \033[0;1;31mfatal:\033[0m ";
static std::string_view error_mono = "mold: error: ";
static std::string_view error_color = "mold: \033[0;1;31merror:\033[0m ";
static std::string_view warning_mono = "mold: warning: ";
static std::string_view warning_color = "mold: \033[0;1;35mwarning:\033[0m ";
template <typename Context>
class Fatal {
public:
Fatal(Context &ctx) {
out << (ctx.arg.color_diagnostics ? fatal_color : fatal_mono);
}
[[noreturn]] ~Fatal() {
out.emit();
cleanup();
_exit(1);
}
template <typename T> Fatal &operator<<(T &&val) {
out << std::forward<T>(val);
return *this;
}
private:
SyncStream out{std::cerr};
};
template <typename Context>
class Error {
public:
Error(Context &ctx) {
if (ctx.arg.noinhibit_exec) {
out << (ctx.arg.color_diagnostics ? warning_color : warning_mono);
} else {
out << (ctx.arg.color_diagnostics ? error_color : error_mono);
ctx.has_error = true;
}
}
template <typename T> Error &operator<<(T &&val) {
out << std::forward<T>(val);
return *this;
}
private:
SyncStream out{std::cerr};
};
template <typename Context>
class Warn {
public:
Warn(Context &ctx) {
if (ctx.arg.suppress_warnings)
return;
out.emplace(std::cerr);
if (ctx.arg.fatal_warnings) {
*out << (ctx.arg.color_diagnostics ? error_color : error_mono);
ctx.has_error = true;
} else {
*out << (ctx.arg.color_diagnostics ? warning_color : warning_mono);
}
}
template <typename T> Warn &operator<<(T &&val) {
if (out)
*out << std::forward<T>(val);
return *this;
}
private:
std::optional<SyncStream> out;
};
//
// Atomics
//
// This is the same as std::atomic except that the default memory
// order is relaxed instead of sequential consistency.
template <typename T>
struct Atomic : std::atomic<T> {
static constexpr std::memory_order relaxed = std::memory_order_relaxed;
using std::atomic<T>::atomic;
Atomic(const Atomic<T> &other) : std::atomic<T>(other.load()) {}
Atomic<T> &operator=(const Atomic<T> &other) {
store(other.load());
return *this;
}
void operator=(T val) { store(val); }
operator T() const { return load(); }
void store(T val, std::memory_order order = relaxed) {
std::atomic<T>::store(val, order);
}
T load(std::memory_order order = relaxed) const {
return std::atomic<T>::load(order);
}
T exchange(T val) { return std::atomic<T>::exchange(val, relaxed); }
T operator|=(T val) { return std::atomic<T>::fetch_or(val, relaxed); }
T operator++() { return std::atomic<T>::fetch_add(1, relaxed) + 1; }
T operator--() { return std::atomic<T>::fetch_sub(1, relaxed) - 1; }
T operator++(int) { return std::atomic<T>::fetch_add(1, relaxed); }
T operator--(int) { return std::atomic<T>::fetch_sub(1, relaxed); }
bool test_and_set() {
// A relaxed load + branch (assuming miss) takes only around 20 cycles,
// while an atomic RMW can easily take hundreds on x86. We note that it's
// common that another thread beat us in marking, so doing an optimistic
// early test tends to improve performance in the ~20% ballpark.
return load() || exchange(true);
}
};
//
// mimalloc.cc
//
void set_mimalloc_options();
//
// perf.cc
//
// Counter is used to collect statistics numbers.
class Counter {
public:
Counter(std::string_view name, i64 value = 0) : name(name), values(value) {
static std::mutex mu;
std::scoped_lock lock(mu);
instances.push_back(this);
}
Counter &operator++(int) {
if (enabled) [[unlikely]]
values.local()++;
return *this;
}
Counter &operator+=(int delta) {
if (enabled) [[unlikely]]
values.local() += delta;
return *this;
}
static void print();
static inline bool enabled = false;
private:
i64 get_value();
std::string_view name;
tbb::enumerable_thread_specific<i64> values;
static inline std::vector<Counter *> instances;
};
// Timer and TimeRecord records elapsed time (wall clock time)
// used by each pass of the linker.
struct TimerRecord {
TimerRecord(std::string name, TimerRecord *parent = nullptr);
void stop();
std::string name;
TimerRecord *parent;
tbb::concurrent_vector<TimerRecord *> children;
i64 start;
i64 end;
i64 user;
i64 sys;
bool stopped = false;
};
void
print_timer_records(tbb::concurrent_vector<std::unique_ptr<TimerRecord>> &);
template <typename Context>
class Timer {
public:
Timer(Context &ctx, std::string name, Timer *parent = nullptr) {
record = new TimerRecord(name, parent ? parent->record : nullptr);
ctx.timer_records.emplace_back(record);
}
Timer(const Timer &) = delete;
~Timer() {
record->stop();
}
void stop() {
record->stop();
}
private:
TimerRecord *record;
};
//
// Utility functions
//
// Some C++ libraries haven't implemented std::has_single_bit yet.
inline bool has_single_bit(u64 val) {
return std::popcount(val) == 1;
}
// Some C++ libraries haven't implemented std::bit_ceil yet.
inline u64 bit_ceil(u64 val) {
if (has_single_bit(val))
return val;
return 1LL << (64 - std::countl_zero(val));
}
inline u64 align_to(u64 val, u64 align) {
if (align == 0)
return val;
assert(has_single_bit(align));
return (val + align - 1) & ~(align - 1);
}
inline u64 align_down(u64 val, u64 align) {
assert(has_single_bit(align));
return val & ~(align - 1);
}
inline u64 bit(u64 val, i64 pos) {
return (val >> pos) & 1;
};
// Returns [hi:lo] bits of val.
inline u64 bits(u64 val, u64 hi, u64 lo) {
return (val >> lo) & ((1LL << (hi - lo + 1)) - 1);
}
// Cast val to a signed N bit integer.
// For example, sign_extend(x, 32) == (i32)x for any integer x.
inline i64 sign_extend(u64 val, i64 n) {
return (i64)(val << (64 - n)) >> (64 - n);
}
inline bool is_int(u64 val, i64 n) {
return sign_extend(val, n) == val;
}
template <typename T, typename Compare = std::less<T>>
void update_minimum(std::atomic<T> &atomic, u64 new_val, Compare cmp = {}) {
T old_val = atomic.load(std::memory_order_relaxed);
while (cmp(new_val, old_val) &&
!atomic.compare_exchange_weak(old_val, new_val,
std::memory_order_relaxed));
}
template <typename T, typename Compare = std::less<T>>
void update_maximum(std::atomic<T> &atomic, u64 new_val, Compare cmp = {}) {
T old_val = atomic.load(std::memory_order_relaxed);
while (cmp(old_val, new_val) &&
!atomic.compare_exchange_weak(old_val, new_val,
std::memory_order_relaxed));
}
template <typename T>
inline void append(std::vector<T> &x, const auto &y) {
x.insert(x.end(), y.begin(), y.end());
}
template <typename T>
inline std::vector<T> flatten(std::vector<std::vector<T>> &vec) {
i64 size = 0;
for (std::vector<T> &v : vec)
size += v.size();
std::vector<T> ret;
ret.reserve(size);
for (std::vector<T> &v : vec)
append(ret, v);
return ret;
}
template <typename T>
inline void remove_duplicates(std::vector<T> &vec) {
vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
}
inline i64 write_string(void *buf, std::string_view str) {
memcpy(buf, str.data(), str.size());
*((u8 *)buf + str.size()) = '\0';
return str.size() + 1;
}
template <typename T>
inline void write_vector(void *buf, const std::vector<T> &vec) {
if (!vec.empty())
memcpy(buf, vec.data(), vec.size() * sizeof(T));
}
inline void encode_uleb(std::vector<u8> &vec, u64 val) {
do {
u8 byte = val & 0x7f;
val >>= 7;
vec.push_back(val ? (byte | 0x80) : byte);
} while (val);
}
inline void encode_sleb(std::vector<u8> &vec, i64 val) {
for (;;) {
u8 byte = val & 0x7f;
val >>= 7;
bool neg = (byte & 0x40);
if ((val == 0 && !neg) || (val == -1 && neg)) {
vec.push_back(byte);
break;
}
vec.push_back(byte | 0x80);
}
}
inline i64 write_uleb(u8 *buf, u64 val) {
i64 i = 0;
do {
u8 byte = val & 0x7f;
val >>= 7;
buf[i++] = val ? (byte | 0x80) : byte;
} while (val);
return i;
}
inline u64 read_uleb(u8 **buf) {
u64 val = 0;
u8 shift = 0;
u8 byte;
do {
byte = *(*buf)++;
val |= (byte & 0x7f) << shift;
shift += 7;
} while (byte & 0x80);
return val;
}
inline u64 read_uleb(u8 *buf) {
u8 *tmp = buf;
return read_uleb(&tmp);
}
inline i64 read_sleb(u8 **buf) {
u64 val = 0;
u8 shift = 0;
u8 byte;
do {
byte = *(*buf)++;
val |= (byte & 0x7f) << shift;
shift += 7;
} while (byte & 0x80);
return sign_extend(val, shift);
}
inline i64 read_sleb(u8 *buf) {
u8 *tmp = buf;
return read_sleb(&tmp);
}
inline u64 read_uleb(std::string_view *str) {
u8 *start = (u8 *)str->data();
u8 *ptr = start;
u64 val = read_uleb(&ptr);
*str = str->substr(ptr - start);
return val;
}
inline u64 read_uleb(std::string_view str) {
std::string_view tmp = str;
return read_uleb(&tmp);
}
inline i64 uleb_size(u64 val) {
for (int i = 1; i < 9; i++)
if (val < (1LL << (7 * i)))
return i;
return 9;
}
inline void overwrite_uleb(u8 *loc, u64 val) {
while (*loc & 0b1000'0000) {
*loc++ = 0b1000'0000 | (val & 0b0111'1111);
val >>= 7;
}
*loc = val & 0b0111'1111;
}
static inline void pause() {
#if defined(__x86_64__)
asm volatile("pause");
#elif defined(__aarch64__)
asm volatile("yield");
#elif defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_8A__)
asm volatile("yield");
#endif
}
//
// Concurrent Map
//
// This is an implementation of a fast concurrent hash map. Unlike
// ordinary hash tables, this impl just aborts if it becomes full.
// So you need to give a correct estimation of the final size before
// using it. We use this hash map to uniquify pieces of data in
// mergeable sections.
//
// We've implemented this ourselves because the performance of
// conrurent hash map is critical for our linker.
template <typename T>
class ConcurrentMap {
public:
ConcurrentMap() = default;
ConcurrentMap(i64 nbuckets) {
resize(nbuckets);
}
~ConcurrentMap() {
if (entries) {
#ifdef _WIN32
_aligned_free(entries);
#else
munmap(entries, sizeof(Entry) * nbuckets);
#endif
}
}
// In order to avoid unnecessary cache-line false sharing, we want
// to make this object to be aligned to a reasonably large
// power-of-two address.
struct alignas(32) Entry {
Atomic<const char *> key;
u32 keylen;
T value;
};
void resize(i64 nbuckets) {
assert(!entries);
this->nbuckets = std::max<i64>(MIN_NBUCKETS, bit_ceil(nbuckets));
i64 bufsize = sizeof(Entry) * this->nbuckets;
// Allocate a zero-initialized buffer. We use mmap() if available
// because it's faster than malloc() and memset().
#ifdef _WIN32
entries = (Entry *)_aligned_malloc(bufsize, alignof(Entry));
memset((void *)entries, 0, bufsize);
#else
entries = (Entry *)mmap(nullptr, bufsize, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
#endif
}
std::pair<T *, bool> insert(std::string_view key, u64 hash, const T &val) {
assert(has_single_bit(nbuckets));
u64 begin = hash & (nbuckets - 1);
u64 mask = nbuckets / NUM_SHARDS - 1;
for (i64 i = 0; i < MAX_RETRY; i++) {
u64 idx = (begin & ~mask) | ((begin + i) & mask);
Entry &ent = entries[idx];
// It seems avoiding compare-and-swap is faster overall at least
// on my Zen4 machine, so do it.
if (const char *ptr = ent.key.load(std::memory_order_acquire);
ptr != nullptr && ptr != (char *)-1) {
if (key == std::string_view(ptr, ent.keylen))
return {&ent.value, false};
continue;
}
// Otherwise, use CAS to atomically claim the ownership of the slot.
const char *ptr = nullptr;
bool claimed = ent.key.compare_exchange_strong(ptr, (char *)-1,
std::memory_order_acquire);
// If we successfully claimed the ownership of the slot,
// copy values to it.
if (claimed) {
new (&ent.value) T(val);
ent.keylen = key.size();
ent.key.store(key.data(), std::memory_order_release);
return {&ent.value, true};
}
// If someone is copying values to the slot, do busy wait.
while (ptr == (char *)-1) {
pause();
ptr = ent.key.load(std::memory_order_acquire);
}
// If the same key is already present, this is the slot we are
// looking for.
if (key == std::string_view(ptr, ent.keylen))
return {&ent.value, false};
}
std::cerr << "ConcurrentMap is full\n";
abort();
}
i64 get_idx(T *value) const {
uintptr_t addr = (uintptr_t)value - (uintptr_t)value % sizeof(Entry);
return (Entry *)addr - entries;
}
// Return a list of map entries sorted in a deterministic order.
std::vector<Entry *> get_sorted_entries(i64 shard_idx) {
if (nbuckets == 0)
return {};
i64 shard_size = nbuckets / NUM_SHARDS;
i64 begin = shard_idx * shard_size;
i64 end = begin + shard_size;
i64 sz = 0;
for (i64 i = begin; i < end; i++)
if (entries[i].key)
sz++;
std::vector<Entry *> vec;
vec.reserve(sz);
// Since the shard is circular, we need to handle the last entries
// as if they were next to the first entries.
while (entries[end - 1].key)
vec.push_back(entries + --end);
// Find entries contiguous in the buckets and sort them.
i64 last = 0;
for (i64 i = begin; i < end;) {
while (i < end && entries[i].key)
vec.push_back(entries + i++);
std::sort(vec.begin() + last, vec.end(), [](Entry *a, Entry *b) {
if (a->keylen != b->keylen)
return a->keylen < b->keylen;
return memcmp(a->key, b->key, a->keylen) < 0;
});
last = vec.size();
while (i < end && !entries[i].key)
i++;
}
return vec;
}
std::vector<Entry *> get_sorted_entries_all() {
std::vector<std::vector<Entry *>> vec(NUM_SHARDS);
tbb::parallel_for((i64)0, NUM_SHARDS, [&](i64 i) {
vec[i] = get_sorted_entries(i);
});
return flatten(vec);
}
static constexpr i64 MIN_NBUCKETS = 4096;
static constexpr i64 NUM_SHARDS = 16;
static constexpr i64 MAX_RETRY = 256;
Entry *entries = nullptr;
u64 nbuckets = 0;
};
//
// random.cc
//
void get_random_bytes(u8 *buf, i64 size);
//
// hyperloglog.cc
//
class HyperLogLog {
public:
void insert(u64 hash) {
update_maximum(buckets[hash & (NBUCKETS - 1)], std::countl_zero(hash) + 1);
}
i64 get_cardinality() const;
void merge(const HyperLogLog &other) {
for (i64 i = 0; i < NBUCKETS; i++)
update_maximum(buckets[i], other.buckets[i]);
}
private:
static constexpr i64 NBUCKETS = 2048;
static constexpr double ALPHA = 0.79402;
Atomic<u8> buckets[NBUCKETS];
};
//
// glob.cc
//
class Glob {
typedef enum { STRING, STAR, QUESTION, BRACKET } Kind;
struct Element {
Element(Kind k) : kind(k) {}
Kind kind;
std::string str;
std::bitset<256> bitset;
};
public:
static std::optional<Glob> compile(std::string_view pat);
bool match(std::string_view str);
private:
Glob(std::vector<Element> &&vec) : elements(vec) {}
static bool do_match(std::string_view str, std::span<Element> elements);
std::vector<Element> elements;
};
//
// multi-glob.cc
//
class MultiGlob {
public:
bool add(std::string_view pat, i64 val);
bool empty() const { return strings.empty(); }
std::optional<i64> find(std::string_view str);
private:
struct TrieNode {
i64 value = -1;
TrieNode *suffix_link = nullptr;
std::unique_ptr<TrieNode> children[256];
};
void compile();
void fix_suffix_links(TrieNode &node);
void fix_values();
i64 find_aho_corasick(std::string_view str);
std::vector<std::string> strings;
std::unique_ptr<TrieNode> root;
std::vector<std::pair<Glob, i64>> globs;
std::once_flag once;
bool is_compiled = false;
bool prefix_match = false;
};
//
// filepath.cc
//
inline std::filesystem::path path_dirname(std::string_view path) {
return std::filesystem::path(path).parent_path();
}
inline std::string path_filename(std::string_view path) {
return std::filesystem::path(path).filename().string();
}
inline std::string path_clean(std::string_view path) {
return std::filesystem::path(path).lexically_normal().string();
}
std::string get_self_path();
//
// demangle.cc
//
std::optional<std::string_view> demangle_cpp(std::string_view name);
std::optional<std::string_view> demangle_rust(std::string_view name);
//
// jbos.cc
//
void acquire_global_lock();
void release_global_lock();
//
// crc32.cc
//
u32 compute_crc32(u32 crc, u8 *buf, i64 len);
std::vector<u8> crc32_solve(u32 current, u32 desired);
//
// compress.cc
//
class Compressor {
public:
virtual void write_to(u8 *buf) = 0;
virtual ~Compressor() {}
i64 compressed_size = 0;
};
class ZlibCompressor : public Compressor {
public:
ZlibCompressor(u8 *buf, i64 size);
void write_to(u8 *buf) override;
private:
std::vector<std::vector<u8>> shards;
u64 checksum = 0;
};
class ZstdCompressor : public Compressor {
public:
ZstdCompressor(u8 *buf, i64 size);
void write_to(u8 *buf) override;
private:
std::vector<std::vector<u8>> shards;
};
//
// tar.cc
//
// TarFile is a class to create a tar file.
//
// If you pass `--repro` to mold, mold collects all input files and
// put them into `<output-file-path>.repro.tar`, so that it is easy to
// run the same command with the same command line arguments.
class TarWriter {
public:
static std::unique_ptr<TarWriter>
open(std::string output_path, std::string basedir);
~TarWriter();
void append(std::string path, std::string_view data);
private:
TarWriter(FILE *out, std::string basedir) : out(out), basedir(basedir) {}
FILE *out = nullptr;
std::string basedir;
};
//
// Memory-mapped file
//
// MappedFile represents an mmap'ed input file.
// mold uses mmap-IO only.
class MappedFile {
public:
~MappedFile() { unmap(); }
void unmap();
void close_fd();
void reopen_fd(const std::string &path);
template <typename Context>
MappedFile *slice(Context &ctx, std::string name, u64 start, u64 size) {
MappedFile *mf = new MappedFile;
mf->name = name;
mf->data = data + start;
mf->size = size;
mf->parent = this;
ctx.mf_pool.emplace_back(mf);
return mf;
}
std::string_view get_contents() {
return std::string_view((char *)data, size);
}
i64 get_offset() const {
return parent ? (data - parent->data + parent->get_offset()) : 0;
}
// Returns a string that uniquely identify a file that is possibly
// in an archive.
std::string get_identifier() const {
if (parent) {
// We use the file offset within an archive as an identifier
// because archive members may have the same name.
return parent->name + ":" + std::to_string(get_offset());
}
if (thin_parent) {
// If this is a thin archive member, the filename part is
// guaranteed to be unique.
return thin_parent->name + ":" + name;
}
return name;
}
std::string name;
u8 *data = nullptr;
i64 size = 0;
bool given_fullpath = true;
MappedFile *parent = nullptr;
MappedFile *thin_parent = nullptr;
// For --dependency-file
bool is_dependency = true;
#ifdef _WIN32
HANDLE fd = INVALID_HANDLE_VALUE;
#else
int fd = -1;
#endif
};
MappedFile *open_file_impl(const std::string &path, std::string &error);
template <typename Context>
MappedFile *open_file(Context &ctx, std::string path) {
if (path.starts_with('/') && !ctx.arg.chroot.empty())
path = ctx.arg.chroot + "/" + path_clean(path);
std::string error;
MappedFile *mf = open_file_impl(path, error);
if (!error.empty())
Fatal(ctx) << error;
if (mf)
ctx.mf_pool.emplace_back(mf);
return mf;
}
template <typename Context>
MappedFile *must_open_file(Context &ctx, std::string path) {
MappedFile *mf = open_file(ctx, path);
if (!mf)
Fatal(ctx) << "cannot open " << path << ": " << errno_string();
return mf;
}
} // namespace mold
+185
View File
@@ -0,0 +1,185 @@
// This file implements a multi-threaded zlib and zstd compression
// routine.
//
// zlib-compressed data can be merged just by concatenation as long as
// each piece of data is flushed with Z_SYNC_FLUSH. In this file, we
// split input data into multiple shards, compress them individually
// and concatenate them. We then append a header, a trailer and a
// checksum so that the concatenated data is valid zlib-format data.
//
// zstd-compressed data can be merged in the same way.
//
// Using threads to compress data has a downside. Since the dictionary
// is reset on boundaries of shards, compression ratio is sacrificed
// a little bit. However, if a shard size is large enough, that loss
// is negligible in practice.
#include "common.h"
#include <tbb/parallel_for_each.h>
#include <zlib.h>
#include <zstd.h>
#define CHECK(fn) \
do { \
[[maybe_unused]] int r = (fn); \
assert(r == Z_OK); \
} while (0)
namespace mold {
static constexpr i64 SHARD_SIZE = 1024 * 1024;
static std::vector<std::string_view> split(std::string_view input) {
std::vector<std::string_view> shards;
while (input.size() >= SHARD_SIZE) {
shards.push_back(input.substr(0, SHARD_SIZE));
input = input.substr(SHARD_SIZE);
}
if (!input.empty())
shards.push_back(input);
return shards;
}
static std::vector<u8> zlib_compress(std::string_view input) {
// Initialize zlib stream. Since debug info is generally compressed
// pretty well with lower compression levels, we chose compression
// level 1.
z_stream strm;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
CHECK(deflateInit2(&strm, 1, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY));
// Set an input buffer
strm.avail_in = input.size();
strm.next_in = (u8 *)input.data();
// Set an output buffer. deflateBound() returns an upper bound
// on the compression size. +16 for Z_SYNC_FLUSH.
std::vector<u8> buf(deflateBound(&strm, strm.avail_in) + 16);
// Compress data. It writes all compressed bytes except the last
// partial byte, so up to 7 bits can be held to be written to the
// buffer.
strm.avail_out = buf.size();
strm.next_out = buf.data();
CHECK(deflate(&strm, Z_BLOCK));
// This is a workaround for libbacktrace before 2022-04-06.
//
// Zlib is a bit stream, and what Z_SYNC_FLUSH does is to write a
// three bit value indicating the start of an uncompressed data
// block followed by four byte data 00 00 ff ff which indicates that
// the length of the block is zero. libbacktrace uses its own zlib
// inflate routine, and it had a bug that if that particular three
// bit value happens to end at a byte boundary, it accidentally
// skipped the next byte.
//
// In order to avoid triggering that bug, we should avoid calling
// deflate() with Z_SYNC_FLUSH if the current bit position is 5.
// If it's 5, we insert an empty block consisting of 10 bits so
// that the bit position is 7 in the next byte.
//
// https://github.com/ianlancetaylor/libbacktrace/pull/87
int nbits;
deflatePending(&strm, Z_NULL, &nbits);
if (nbits == 5)
CHECK(deflatePrime(&strm, 10, 2));
CHECK(deflate(&strm, Z_SYNC_FLUSH));
assert(strm.avail_out > 0);
buf.resize(buf.size() - strm.avail_out);
buf.shrink_to_fit();
deflateEnd(&strm);
return buf;
}
ZlibCompressor::ZlibCompressor(u8 *buf, i64 size) {
std::string_view input{(char *)buf, (size_t)size};
std::vector<std::string_view> inputs = split(input);
std::vector<u64> adlers(inputs.size());
shards.resize(inputs.size());
// Compress each shard
tbb::parallel_for((i64)0, (i64)inputs.size(), [&](i64 i) {
adlers[i] = adler32(1, (u8 *)inputs[i].data(), inputs[i].size());
shards[i] = zlib_compress(inputs[i]);
});
// Combine checksums
checksum = adlers[0];
for (i64 i = 1; i < inputs.size(); i++)
checksum = adler32_combine(checksum, adlers[i], inputs[i].size());
// Comput the total size
compressed_size = 8; // the header and the trailer
for (std::vector<u8> &shard : shards)
compressed_size += shard.size();
}
void ZlibCompressor::write_to(u8 *buf) {
// Write a zlib-format header
buf[0] = 0x78;
buf[1] = 0x9c;
// Copy compressed data
std::vector<i64> offsets(shards.size());
offsets[0] = 2; // +2 for header
for (i64 i = 1; i < shards.size(); i++)
offsets[i] = offsets[i - 1] + shards[i - 1].size();
tbb::parallel_for((i64)0, (i64)shards.size(), [&](i64 i) {
memcpy(buf + offsets[i], shards[i].data(), shards[i].size());
});
// Write a trailer
u8 *end = buf + compressed_size;
end[-6] = 3;
end[-5] = 0;
// Write a checksum
*(ub32 *)(end - 4) = checksum;
}
static std::vector<u8> zstd_compress(std::string_view input) {
std::vector<u8> buf(ZSTD_COMPRESSBOUND(input.size()));
constexpr int LEVEL = 3; // compression level; must be between 1 to 22
size_t sz = ZSTD_compress(buf.data(), buf.size(), input.data(), input.size(),
LEVEL);
assert(!ZSTD_isError(sz));
buf.resize(sz);
buf.shrink_to_fit();
return buf;
}
ZstdCompressor::ZstdCompressor(u8 *buf, i64 size) {
std::string_view input{(char *)buf, (size_t)size};
std::vector<std::string_view> inputs = split(input);
shards.resize(inputs.size());
// Compress each shard
tbb::parallel_for((i64)0, (i64)inputs.size(), [&](i64 i) {
shards[i] = zstd_compress(inputs[i]);
});
compressed_size = 0;
for (std::vector<u8> &shard : shards)
compressed_size += shard.size();
}
void ZstdCompressor::write_to(u8 *buf) {
// Copy compressed data
std::vector<i64> offsets(shards.size());
for (i64 i = 1; i < shards.size(); i++)
offsets[i] = offsets[i - 1] + shards[i - 1].size();
tbb::parallel_for((i64)0, (i64)shards.size(), [&](i64 i) {
memcpy(buf + offsets[i], shards[i].data(), shards[i].size());
});
}
} // namespace mold
+7
View File
@@ -0,0 +1,7 @@
#define MOLD_VERSION "@mold_VERSION@"
#define MOLD_LIBDIR "@CMAKE_INSTALL_FULL_LIBDIR@"
#cmakedefine HAVE_MADVISE 1
#cmakedefine HAVE_UNAME 1
#cmakedefine MOLD_USE_MIMALLOC 1
#cmakedefine MOLD_USE_SYSTEM_MIMALLOC 1
+60
View File
@@ -0,0 +1,60 @@
#include "common.h"
#include <tbb/parallel_for_each.h>
#include <zlib.h>
namespace mold {
// This function "forges" a CRC. That is, given the current and a desired
// CRC32 value, crc32_solve() returns a binary blob to add to the end of
// the original data to yield the desired CRC. Trailing garbage is ignored
// by many bianry file formats, so you can create a file with a desired
// CRC using crc32_solve(). We need it for --separate-debug-file.
std::vector<u8> crc32_solve(u32 current, u32 desired) {
constexpr u32 poly = 0xedb88320;
u32 x = ~desired;
// Each iteration computes x = (x * x^-1) mod poly.
for (i64 i = 0; i < 32; i++) {
x = std::rotl(x, 1);
x ^= (x & 1) * (poly << 1);
}
x ^= ~current;
std::vector<u8> out(4);
out[0] = x;
out[1] = x >> 8;
out[2] = x >> 16;
out[3] = x >> 24;
return out;
}
// Compute a CRC for given data in parallel
u32 compute_crc32(u32 crc, u8 *buf, i64 len) {
struct Shard {
u8 *buf;
i64 len;
u32 crc;
};
constexpr i64 shard_size = 1024 * 1024; // 1 MiB
std::vector<Shard> shards;
while (len > 0) {
i64 sz = std::min(len, shard_size);
shards.push_back({buf, sz, 0});
buf += sz;
len -= sz;
}
tbb::parallel_for_each(shards, [](Shard &shard) {
shard.crc = crc32(0, shard.buf, shard.len);
});
for (Shard &shard : shards)
crc = crc32_combine(crc, shard.crc, shard.len);
return crc;
}
} // namespace mold
+42
View File
@@ -0,0 +1,42 @@
#include "common.h"
#include <cstdlib>
#ifndef _WIN32
#include <cxxabi.h>
#endif
#include "../third-party/rust-demangle/rust-demangle.h"
namespace mold {
std::optional<std::string_view> demangle_cpp(std::string_view name) {
static thread_local char *buf;
static thread_local size_t buflen;
// TODO(cwasser): Actually demangle Symbols on Windows using e.g.
// `UnDecorateSymbolName` from Dbghelp, maybe even Itanium symbols?
#ifndef _WIN32
if (name.starts_with("_Z")) {
int status;
char *p = abi::__cxa_demangle(std::string(name).c_str(), buf, &buflen, &status);
if (status == 0) {
buf = p;
return p;
}
}
#endif
return {};
}
std::optional<std::string_view> demangle_rust(std::string_view name) {
static thread_local char *buf;
free(buf);
buf = rust_demangle(std::string(name).c_str(), 0);
if (buf)
return buf;
return {};
}
} // namespace mold
+42
View File
@@ -0,0 +1,42 @@
#include "common.h"
#include <filesystem>
#include <sys/stat.h>
#ifdef __APPLE__
# include <mach-o/dyld.h>
#endif
#ifdef __FreeBSD__
# include <sys/sysctl.h>
#endif
namespace mold {
// Returns the path of the mold executable itself
std::string get_self_path() {
#if __APPLE__ || _WIN32
fprintf(stderr, "mold: get_self_path is not supported");
exit(1);
#elif __FreeBSD__
// /proc may not be mounted on FreeBSD. The proper way to get the
// current executable's path is to use sysctl(2).
int mib[4];
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PATHNAME;
mib[3] = -1;
size_t size;
sysctl(mib, 4, NULL, &size, NULL, 0);
std::string path;
path.resize(size);
sysctl(mib, 4, path.data(), &size, NULL, 0);
return path;
#else
return std::filesystem::read_symlink("/proc/self/exe").string();
#endif
}
} // namespace mold
+69
View File
@@ -0,0 +1,69 @@
#!/bin/bash
#
# This test script takes a Gentoo package name and tries to build it
# using mold in a Podman environment. We chose Gentoo Linux as a test
# target, because its source-based package allows us to build programs
# locally and run their test suites without any hassle.
#
# You can get a complete list of Gentoo packages availalbe for testing
# with the following command:
#
# podman run --rm mold-gentoo emerge --color n -s '' | \
# perl -ne 'next unless m!^\*\s+(\S+/\S+)!; print "$1\n"'
package="$1"
if [ "$package" = "" ]; then
echo "Usage: $0 gentoo-package-name"
exit 1
fi
set -x
# Create a Podman image
if ! podman image ls mold-gentoo | grep -q mold-gentoo; then
set -e
cat <<EOF | podman build -t mold-gentoo -
FROM docker.io/gentoo/stage3
RUN emerge-webrsync
RUN echo 'USE="X ssl elogind -systemd corefonts truetype jpeg jpeg2k tiff zstd static-libs binary -perl"' >> /etc/portage/make.conf && \
echo 'ACCEPT_KEYWORDS="~amd64"' >> /etc/portage/make.conf && \
echo 'ACCEPT_LICENSE="* -@EULA"' >> /etc/portage/make.conf && \
echo 'FEATURES="\${FEATURE} noclean nostrip ccache -ipc-sandbox -network-sandbox -pid-sandbox -sandbox"' >> /etc/portage/make.conf && \
echo 'CCACHE_DIR="/ccache"' >> /etc/portage/make.conf && \
FEATURES='getbinpkg binpkg-request-signature' emerge gdb lld llvm-core/clang vim emacs strace ccache xeyes dev-build/cmake dev-vcs/git && \
rm -rf /var/tmp/portage
EOF
set +e
fi
git_hash=$(./dist/mold --version | perl -ne '/\((\w+)/; print $1;')
if [ "$package" = dev-libs/concurrencykit ]; then
echo "Skipping known broken package: $package"
exit 0
fi
# Build a given package in Podman
cmd1='(cd /usr/bin; ln -sf /mold/dist/mold $(realpath ld))'
cmd2="MAKEOPTS=-'j$(nproc) --load-average=100' emerge --onlydeps $package"
cmd3="MAKEOPTS='-j$(nproc) --load-average=100' FEATURES=test emerge $package"
filename=`echo "$package" | sed 's!/!_!g'`
podman="podman run --rm --pids-limit=-1 --cap-add=SYS_PTRACE -v `pwd`:/mold:ro -v /var/cache/ccache-gentoo:/ccache mold-gentoo timeout -v -k 15s 3h"
dir=gentoo/$git_hash
mkdir -p "$dir"/success "$dir"/failure
$podman nice -n 19 bash -c "$cmd1 && $cmd2 && $cmd3" >& "$dir"/"$filename".mold
if [ $? = 0 ]; then
mv "$dir"/"$filename".mold "$dir"/success
else
mv "$dir"/"$filename".mold "$dir"/failure
fi
$podman nice -n 19 bash -c "$cmd2 && $cmd3" >& "$dir"/"$filename".ld
if [ $? = 0 ]; then
mv "$dir"/"$filename".ld "$dir"/success
else
mv "$dir"/"$filename".ld "$dir"/failure
fi
+156
View File
@@ -0,0 +1,156 @@
#include "common.h"
#include <cstring>
namespace mold {
std::optional<Glob> Glob::compile(std::string_view pat) {
std::vector<Element> vec;
while (!pat.empty()) {
u8 c = pat[0];
pat = pat.substr(1);
switch (c) {
case '[': {
// Here are a few bracket pattern examples:
//
// [abc]: a, b or c
// [$\]!]: $, ] or !
// [a-czg-i]: a, b, c, z, g, h, or i
// [^a-z]: Any character except lowercase letters
vec.emplace_back(BRACKET);
std::bitset<256> &bitset = vec.back().bitset;
bool negate = false;
if (!pat.empty() && pat[0] == '^') {
negate = true;
pat = pat.substr(1);
}
bool closed = false;
while (!pat.empty()) {
if (pat[0] == ']') {
pat = pat.substr(1);
closed = true;
break;
}
if (pat[0] == '\\') {
pat = pat.substr(1);
if (pat.empty())
return {};
}
if (pat.size() >= 3 && pat[1] == '-') {
u8 start = pat[0];
u8 end = pat[2];
pat = pat.substr(3);
if (end == '\\') {
if (pat.empty())
return {};
end = pat[0];
pat = pat.substr(1);
}
if (end < start)
return {};
for (i64 i = start; i <= end; i++)
bitset[i] = true;
} else {
bitset[(u8)pat[0]] = true;
pat = pat.substr(1);
}
}
if (!closed)
return {};
if (negate)
bitset.flip();
break;
}
case '?':
vec.emplace_back(QUESTION);
break;
case '*':
vec.emplace_back(STAR);
break;
case '\\':
if (pat.empty())
return {};
if (vec.empty() || vec.back().kind != STRING)
vec.emplace_back(STRING);
vec.back().str += pat[0];
pat = pat.substr(1);
break;
default:
if (vec.empty() || vec.back().kind != STRING)
vec.emplace_back(STRING);
vec.back().str += c;
break;
}
}
return {Glob{std::move(vec)}};
}
bool Glob::match(std::string_view str) {
return do_match(str, elements);
}
bool Glob::do_match(std::string_view str, std::span<Element> elements) {
while (!elements.empty()) {
Element &e = elements[0];
elements = elements.subspan(1);
switch (e.kind) {
case STRING:
if (!str.starts_with(e.str))
return false;
str = str.substr(e.str.size());
break;
case STAR:
if (elements.empty())
return true;
// Patterns like "*foo*bar*" should be much more common than more
// complex ones like "*foo*[abc]*" or "*foo**?bar*", so we optimize
// the former case here.
if (elements[0].kind == STRING) {
for (;;) {
size_t pos = str.find(elements[0].str);
if (pos == str.npos)
return false;
if (do_match(str.substr(pos + elements[0].str.size()),
elements.subspan(1)))
return true;
str = str.substr(pos + 1);
}
}
// Other cases are handled here.
for (i64 j = 0; j < str.size(); j++)
if (do_match(str.substr(j), elements))
return true;
return false;
case QUESTION:
if (str.empty())
return false;
str = str.substr(1);
break;
case BRACKET:
if (str.empty() || !e.bitset[str[0]])
return false;
str = str.substr(1);
break;
}
}
return str.empty();
}
} // namespace mold
+20
View File
@@ -0,0 +1,20 @@
// This file implements HyperLogLog algorithm, which estimates
// the number of unique items in a given multiset.
//
// For more info, read
// https://engineering.fb.com/2018/12/13/data-infrastructure/hyperloglog
#include "common.h"
#include <cmath>
namespace mold {
i64 HyperLogLog::get_cardinality() const {
double z = 0;
for (i64 val : buckets)
z += std::ldexp(1.0, -val);
return ALPHA * NBUCKETS * NBUCKETS / z;
}
} // namespace mold
+144
View File
@@ -0,0 +1,144 @@
// This file defines integral types for file input/output. We need to use
// these types instead of the plain integers (such as uint32_t or int32_t)
// when reading from/writing to an mmap'ed file area for the following
// reasons:
//
// 1. mold is always a cross linker and should not depend on what host it
// is running on. For example, users should be able to run mold on a
// big-endian SPARC machine to create a little-endian RV64 binary.
//
// 2. Even though data members in all ELF data strucutres are naturally
// aligned, they are not guaranteed to be aligned on memory because of
// archive files. Archive files (.a files) align each member only to a
// 2 byte boundary, so anything larger than 2 bytes may be misaligned
// in an mmap'ed memory. Misaligned access is an undefined behavior in
// C/C++, so we shouldn't cast an arbitrary pointer to a uint32_t, for
// example, to read a 32 bit value.
//
// The data types defined in this file don't depend on host byte order and
// don't do unaligned access. Note that modern compilers are smart enough
// to recognize shift and bitwise OR patterns and compile them into a
// single load instruction.
#pragma once
#include <cstdint>
#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# define __LITTLE_ENDIAN__ 1
# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define __BIG_ENDIAN__ 1
# else
# error "unknown host byte order"
# endif
#endif
namespace mold {
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t i8;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
template <typename T, bool is_le, int size = sizeof(T)>
class Integer {
public:
constexpr Integer() = default;
constexpr Integer(T x) requires (is_le && size == 2)
: buf{(u8)x, (u8)(x >> 8)} {}
constexpr Integer(T x) requires (is_le && size == 3)
: buf{(u8)x, (u8)(x >> 8), (u8)(x >> 16)} {}
constexpr Integer(T x) requires (is_le && size == 4)
: buf{(u8)x, (u8)(x >> 8), (u8)(x >> 16), (u8)(x >> 24)} {}
constexpr Integer(T x) requires (is_le && size == 8)
: buf{(u8)x, (u8)(x >> 8), (u8)(x >> 16), (u8)(x >> 24),
(u8)(x >> 32), (u8)(x >> 40), (u8)(x >> 48), (u8)(x >> 56)} {}
constexpr Integer(T x) requires (!is_le && size == 2)
: buf{(u8)(x >> 8), (u8)x} {}
constexpr Integer(T x) requires (!is_le && size == 3)
: buf{(u8)(x >> 16), (u8)(x >> 8), (u8)x} {}
constexpr Integer(T x) requires (!is_le && size == 4)
: buf{(u8)(x >> 24), (u8)(x >> 16), (u8)(x >> 8), (u8)x} {}
constexpr Integer(T x) requires (!is_le && size == 8)
: buf{(u8)(x >> 56), (u8)(x >> 48), (u8)(x >> 40), (u8)(x >> 32),
(u8)(x >> 24), (u8)(x >> 16), (u8)(x >> 8), (u8)x} {}
operator T() const {
if constexpr (is_le) {
if constexpr (size == 2)
return buf[1] << 8 | buf[0];
else if constexpr (size == 3)
return buf[2] << 16 | buf[1] << 8 | buf[0];
else if constexpr (size == 4)
return buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0];
else
return (u64)buf[7] << 56 | (u64)buf[6] << 48 |
(u64)buf[5] << 40 | (u64)buf[4] << 32 |
(u64)buf[3] << 24 | (u64)buf[2] << 16 |
(u64)buf[1] << 8 | (u64)buf[0];
} else {
if constexpr (size == 2)
return buf[0] << 8 | buf[1];
else if constexpr (size == 3)
return buf[0] << 16 | buf[1] << 8 | buf[2];
else if constexpr (size == 4)
return buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
else
return (u64)buf[0] << 56 | (u64)buf[1] << 48 |
(u64)buf[2] << 40 | (u64)buf[3] << 32 |
(u64)buf[4] << 24 | (u64)buf[5] << 16 |
(u64)buf[6] << 8 | (u64)buf[7];
}
}
Integer &operator=(T x) {
new (this) Integer(x);
return *this;
}
Integer &operator++() { return *this = *this + 1; }
Integer operator++(int) { return ++*this - 1; }
Integer &operator--() { return *this = *this - 1; }
Integer operator--(int) { return --*this + 1; }
Integer &operator+=(T x) { return *this = *this + x; }
Integer &operator-=(T x) { return *this = *this - x; }
Integer &operator&=(T x) { return *this = *this & x; }
Integer &operator|=(T x) { return *this = *this | x; }
private:
u8 buf[size];
};
using il16 = Integer<i16, true>;
using il32 = Integer<i32, true>;
using il64 = Integer<i64, true>;
using ul16 = Integer<u16, true>;
using ul24 = Integer<u32, true, 3>;
using ul32 = Integer<u32, true>;
using ul64 = Integer<u64, true>;
using ib16 = Integer<i16, false>;
using ib32 = Integer<i32, false>;
using ib64 = Integer<i64, false>;
using ub16 = Integer<u16, false>;
using ub24 = Integer<u32, false, 3>;
using ub32 = Integer<u32, false>;
using ub64 = Integer<u64, false>;
} // namespace mold
+50
View File
@@ -0,0 +1,50 @@
// Many build systems attempt to invoke as many linker processes as there
// are cores, based on the assumption that the linker is single-threaded.
// However, since mold is multi-threaded, such build systems' behavior is
// not beneficial and just increases the overall peak memory usage.
// On machines with limited memory, this could lead to an out-of-memory
// error.
//
// This file implements a feature that limits the number of concurrent
// mold processes to just 1 for each user. It is intended to be used as
// `MOLD_JOBS=1 ninja` or `MOLD_JOBS=1 make -j$(nproc)`.
#include "common.h"
#include <cstdlib>
#include <fcntl.h>
#include <pwd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
namespace mold {
static int lock_fd = -1;
void acquire_global_lock() {
char *jobs = getenv("MOLD_JOBS");
if (!jobs || jobs != "1"s)
return;
std::string path;
if (char *dir = getenv("XDG_RUNTIME_DIR"))
path = dir + "/mold-lock"s;
else
path = "/tmp/mold-lock-"s + getpwuid(getuid())->pw_name;
int fd = open(path.c_str(), O_WRONLY | O_CREAT | O_CLOEXEC, 0600);
if (fd == -1)
return;
if (lockf(fd, F_LOCK, 0) == -1)
return;
lock_fd = fd;
}
void release_global_lock() {
if (lock_fd != -1)
close(lock_fd);
}
} // namespace mold
+6
View File
@@ -0,0 +1,6 @@
namespace mold {
void acquire_global_lock() {}
void release_global_lock() {}
} // namespace mold
+51
View File
@@ -0,0 +1,51 @@
#include "common.h"
namespace mold {
MappedFile *open_file_impl(const std::string &path, std::string &error) {
i64 fd = ::open(path.c_str(), O_RDONLY);
if (fd == -1) {
if (errno != ENOENT)
error = "opening " + path + " failed: " + errno_string();
return nullptr;
}
struct stat st;
if (fstat(fd, &st) == -1)
error = path + ": fstat failed: " + errno_string();
MappedFile *mf = new MappedFile;
mf->name = path;
mf->size = st.st_size;
if (st.st_size > 0) {
mf->data = (u8 *)mmap(nullptr, st.st_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE, fd, 0);
if (mf->data == MAP_FAILED)
error = path + ": mmap failed: " + errno_string();
}
close(fd);
return mf;
}
void MappedFile::unmap() {
if (size == 0 || parent || !data)
return;
munmap(data, size);
data = nullptr;
}
void MappedFile::close_fd() {
if (fd == -1)
return;
close(fd);
fd = -1;
}
void MappedFile::reopen_fd(const std::string &path) {
if (fd == -1)
fd = open(path.c_str(), O_RDONLY);
}
} // namespace mold
+81
View File
@@ -0,0 +1,81 @@
#include "common.h"
namespace mold {
MappedFile *open_file_impl(const std::string &path, std::string &error) {
HANDLE fd = CreateFileA(path.c_str(), GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
if (fd == INVALID_HANDLE_VALUE) {
auto err = GetLastError();
if (err != ERROR_FILE_NOT_FOUND)
error = "opening " + path + " failed: " + errno_string();
return nullptr;
}
if (GetFileType(fd) != FILE_TYPE_DISK) {
CloseHandle(fd);
return nullptr;
}
DWORD size_hi;
DWORD size_lo = GetFileSize(fd, &size_hi);
if (size_lo == INVALID_FILE_SIZE) {
error = path + ": GetFileSize failed: " + errno_string();
return nullptr;
}
u64 size = ((u64)size_hi << 32) + size_lo;
MappedFile *mf = new MappedFile;
mf->name = path;
mf->size = size;
mf->fd = fd;
if (size > 0) {
HANDLE h = CreateFileMapping(fd, nullptr, PAGE_READONLY, 0, size, nullptr);
if (!h) {
error = path + ": CreateFileMapping failed: " + errno_string();
return nullptr;
}
mf->data = (u8 *)MapViewOfFile(h, FILE_MAP_COPY, 0, 0, size);
CloseHandle(h);
if (!mf->data) {
error = path + ": MapViewOfFile failed: " + errno_string();
return nullptr;
}
}
return mf;
}
void MappedFile::unmap() {
if (size == 0 || parent || !data)
return;
UnmapViewOfFile(data);
if (fd != INVALID_HANDLE_VALUE)
CloseHandle(fd);
data = nullptr;
}
void MappedFile::close_fd() {
if (fd == INVALID_HANDLE_VALUE)
return;
CloseHandle(fd);
fd = INVALID_HANDLE_VALUE;
}
void MappedFile::reopen_fd(const std::string &path) {
if (fd == INVALID_HANDLE_VALUE)
fd = CreateFileA(path.c_str(), GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
}
} // namespace mold
+24
View File
@@ -0,0 +1,24 @@
#include "common.h"
// Including mimalloc-new-delete.h overrides new/delete operators.
// We need it only when we are using mimalloc as a dynamic library.
#if MOLD_USE_SYSTEM_MIMALLOC
# include <mimalloc-new-delete.h>
#endif
// Silence mimalloc warning messages that users can just ignore.
#if MOLD_USE_MIMALLOC
# include <mimalloc.h>
namespace mold {
void set_mimalloc_options() {
mi_option_disable(mi_option_verbose);
mi_option_disable(mi_option_show_errors);
}
}
#else
namespace mold {
void set_mimalloc_options() {}
}
#endif
+186
View File
@@ -0,0 +1,186 @@
// This file implements the Aho-Corasick algorithm to match multiple
// glob patterns to symbol strings as quickly as possible.
//
// Here are some examples of glob patterns:
//
// qt_private_api_tag*
// *16QAccessibleCache*
// *32QAbstractFileIconProviderPrivate*
// *17QPixmapIconEngine*
//
// `*` is a wildcard that matches any substring. We sometimes have
// hundreds of glob patterns and have to match them against millions
// of symbol strings.
//
// Aho-Corasick cannot handle complex patterns such as `*foo*bar*`.
// We handle such patterns with the Glob class. Glob is relatively
// slow, but complex patterns are rare in practice, so it should be
// OK.
#include "common.h"
#include <queue>
#include <regex>
namespace mold {
std::optional<i64> MultiGlob::find(std::string_view str) {
std::call_once(once, [&] { compile(); });
i64 val = -1;
// Match against simple glob patterns
if (root)
val = find_aho_corasick(str);
// Match against complex glob patterns
for (std::pair<Glob, i64> &glob : globs)
if (glob.first.match(str))
val = std::max(val, glob.second);
if (val == -1)
return {};
return val;
}
i64 MultiGlob::find_aho_corasick(std::string_view str) {
TrieNode *node = root.get();
i64 val = -1;
auto walk = [&](u8 c) {
for (;;) {
if (node->children[c]) {
node = node->children[c].get();
val = std::max(val, node->value);
return;
}
if (!node->suffix_link)
return;
node = node->suffix_link;
}
};
walk('\0');
for (u8 c : str) {
if (prefix_match && node == root.get())
return val;
walk(c);
}
walk('\0');
return val;
}
static bool is_simple_pattern(std::string_view pat) {
static std::regex re(R"(\*?[^*[?]+\*?)", std::regex_constants::optimize);
return std::regex_match(pat.begin(), pat.end(), re);
}
static std::string handle_stars(std::string_view pat) {
std::string str(pat);
// Convert "foo" -> "\0foo\0", "*foo" -> "foo\0", "foo*" -> "\0foo"
// and "*foo*" -> "foo". Aho-Corasick can do only substring matching,
// so we use \0 as beginning/end-of-string markers.
if (str.starts_with('*') && str.ends_with('*'))
return str.substr(1, str.size() - 2);
if (str.starts_with('*'))
return str.substr(1) + "\0"s;
if (str.ends_with('*'))
return "\0"s + str.substr(0, str.size() - 1);
return "\0"s + str + "\0"s;
}
bool MultiGlob::add(std::string_view pat, i64 val) {
assert(!is_compiled);
assert(!pat.empty());
strings.emplace_back(pat);
// Complex glob pattern
if (!is_simple_pattern(pat)) {
if (std::optional<Glob> glob = Glob::compile(pat)) {
globs.emplace_back(std::move(*glob), val);
return true;
}
return false;
}
// Simple glob pattern
if (!root)
root.reset(new TrieNode);
TrieNode *node = root.get();
for (u8 c : handle_stars(pat)) {
if (!node->children[c])
node->children[c].reset(new TrieNode);
node = node->children[c].get();
}
node->value = std::max(node->value, val);
return true;
}
void MultiGlob::compile() {
is_compiled = true;
if (root) {
fix_suffix_links(*root);
fix_values();
// If no pattern starts with '*', set prefix_match to true.
// We'll use this flag for optimization.
prefix_match = true;
for (i64 i = 1; i < 256; i++) {
if (root->children[i]) {
prefix_match = false;
break;
}
}
}
}
void MultiGlob::fix_suffix_links(TrieNode &node) {
for (i64 i = 0; i < 256; i++) {
if (!node.children[i])
continue;
TrieNode &child = *node.children[i];
TrieNode *cur = node.suffix_link;
for (;;) {
if (!cur) {
child.suffix_link = root.get();
break;
}
if (cur->children[i]) {
child.suffix_link = cur->children[i].get();
break;
}
cur = cur->suffix_link;
}
fix_suffix_links(child);
}
}
void MultiGlob::fix_values() {
std::queue<TrieNode *> queue;
queue.push(root.get());
do {
TrieNode *node = queue.front();
queue.pop();
for (std::unique_ptr<TrieNode> &child : node->children) {
if (!child)
continue;
child->value = std::max(child->value, child->suffix_link->value);
queue.push(child.get());
}
} while (!queue.empty());
}
} // namespace mold
+40 -48
View File
@@ -1,19 +1,23 @@
#include "mold.h"
#include "common.h"
#include <functional>
#include <iomanip>
#include <ios>
#include <tbb/concurrent_vector.h>
#ifndef _WIN32
#include <sys/resource.h>
#include <sys/time.h>
#endif
namespace mold {
i64 Counter::get_value() {
return values.combine(std::plus());
}
void Counter::print() {
sort(instances, [](Counter *a, Counter *b) {
return a->get_value() > b->get_value();
});
ranges::stable_sort(instances, {}, [](Counter *x) { return x->get_value(); });
for (Counter *c : instances)
std::cout << std::setw(20) << std::right << c->name
@@ -21,24 +25,33 @@ void Counter::print() {
}
static i64 now_nsec() {
struct timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
return (i64)t.tv_sec * 1000000000 + t.tv_nsec;
return (i64)std::chrono::steady_clock::now().time_since_epoch().count();
}
static i64 to_nsec(struct timeval t) {
return (i64)t.tv_sec * 1000000000 + t.tv_usec * 1000;
static std::pair<i64, i64> get_usage() {
#ifdef _WIN32
auto to_nsec = [](FILETIME t) -> i64 {
return (((u64)t.dwHighDateTime << 32) + (u64)t.dwLowDateTime) * 100;
};
FILETIME creation, exit, kernel, user;
GetProcessTimes(GetCurrentProcess(), &creation, &exit, &kernel, &user);
return {to_nsec(user), to_nsec(kernel)};
#else
auto to_nsec = [](struct timeval t) -> i64 {
return (i64)t.tv_sec * 1'000'000'000 + t.tv_usec * 1'000;
};
struct rusage ru;
getrusage(RUSAGE_SELF, &ru);
return {to_nsec(ru.ru_utime), to_nsec(ru.ru_stime)};
#endif
}
TimerRecord::TimerRecord(std::string name, TimerRecord *parent)
: name(name), parent(parent) {
struct rusage usage;
getrusage(RUSAGE_SELF, &usage);
start = now_nsec();
user = to_nsec(usage.ru_utime);
sys = to_nsec(usage.ru_stime);
std::tie(user, sys) = get_usage();
if (parent)
parent->children.push_back(this);
}
@@ -48,51 +61,31 @@ void TimerRecord::stop() {
return;
stopped = true;
struct rusage usage;
getrusage(RUSAGE_SELF, &usage);
i64 user2;
i64 sys2;
std::tie(user2, sys2) = get_usage();
end = now_nsec();
user = to_nsec(usage.ru_utime) - user;
sys = to_nsec(usage.ru_stime) - sys;
}
template <typename E>
Timer<E>::Timer(Context<E> &ctx, std::string name, Timer *parent) {
record = new TimerRecord(name, parent ? parent->record : nullptr);
ctx.timer_records.push_back(std::unique_ptr<TimerRecord>(record));
}
template <typename E>
Timer<E>::~Timer() {
record->stop();
}
template <typename E>
void Timer<E>::stop() {
record->stop();
user = user2 - user;
sys = sys2 - sys;
}
static void print_rec(TimerRecord &rec, i64 indent) {
printf(" % 8.3f % 8.3f % 8.3f %s%s\n",
((double)rec.user / 1000000000),
((double)rec.sys / 1000000000),
(((double)rec.end - rec.start) / 1000000000),
((double)rec.user / 1'000'000'000),
((double)rec.sys / 1'000'000'000),
(((double)rec.end - rec.start) / 1'000'000'000),
std::string(indent * 2, ' ').c_str(),
rec.name.c_str());
sort(rec.children, [](TimerRecord *a, TimerRecord *b) {
return a->start < b->start;
});
ranges::stable_sort(rec.children, {}, &TimerRecord::start);
for (TimerRecord *child : rec.children)
print_rec(*child, indent + 1);
}
template <typename E>
void Timer<E>::print(Context<E> &ctx) {
tbb::concurrent_vector<std::unique_ptr<TimerRecord>> &records =
ctx.timer_records;
void print_timer_records(
tbb::concurrent_vector<std::unique_ptr<TimerRecord>> &records) {
for (i64 i = records.size() - 1; i >= 0; i--)
records[i]->stop();
@@ -120,5 +113,4 @@ void Timer<E>::print(Context<E> &ctx) {
std::cout << std::flush;
}
template class Timer<X86_64>;
template class Timer<I386>;
} // namespace mold
+20
View File
@@ -0,0 +1,20 @@
#include "common.h"
#include <random>
namespace mold {
void get_random_bytes(u8 *buf, i64 size) {
std::random_device rand;
i64 i = 0;
for (; i < size - 4; i += 4) {
u32 val = rand();
memcpy(buf + i, &val, 4);
}
u32 val = rand();
memcpy(buf + i, &val, size - i);
}
} // namespace mold
+88
View File
@@ -0,0 +1,88 @@
#include "common.h"
#include <csignal>
#include <tbb/version.h>
#ifdef __FreeBSD__
# include <sys/sysctl.h>
# include <unistd.h>
#endif
namespace mold {
std::string errno_string() {
// strerror is not thread-safe, so guard it with a lock.
static std::mutex mu;
std::scoped_lock lock(mu);
return strerror(errno);
}
void cleanup() {
if (output_tmpfile)
unlink(output_tmpfile);
}
// mold mmap's an output file, and the mmap succeeds even if there's
// no enough space left on the filesystem. The actual disk blocks are
// not allocated on the mmap call but when the program writes to it
// for the first time.
//
// If a disk becomes full as a result of a write to an mmap'ed memory
// region, the failure of the write is reported as a SIGBUS or structured
// exeption with code EXCEPTION_IN_PAGE_ERROR on Windows. This
// signal handler catches that signal and prints out a user-friendly
// error message. Without this, it is very hard to realize that the
// disk might be full.
static std::string sigabrt_msg;
static void sighandler(int signo, siginfo_t *info, void *ucontext) {
static std::mutex mu;
std::scoped_lock lock{mu};
// Handle disk full error
switch (signo) {
case SIGSEGV:
case SIGBUS:
if (output_buffer_start <= info->si_addr &&
info->si_addr < output_buffer_end) {
const char msg[] = "mold: failed to write to an output file. Disk full?\n";
(void)!write(STDERR_FILENO, msg, sizeof(msg) - 1);
}
break;
case SIGABRT: {
(void)!write(STDERR_FILENO, &sigabrt_msg[0], sigabrt_msg.size());
break;
}
}
// Re-throw the signal
signal(SIGSEGV, SIG_DFL);
signal(SIGBUS, SIG_DFL);
signal(SIGABRT, SIG_DFL);
cleanup();
raise(signo);
}
void install_signal_handler() {
struct sigaction action;
action.sa_sigaction = sighandler;
sigemptyset(&action.sa_mask);
action.sa_flags = SA_SIGINFO;
sigaction(SIGSEGV, &action, NULL);
sigaction(SIGBUS, &action, NULL);
// OneTBB 2021.9.0 has the interface version 12090.
if (TBB_runtime_interface_version() < 12090) {
sigabrt_msg = "mold: aborted\n"
"mold: mold with libtbb version 2021.9.0 or older is known to be unstable "
"under heavy load. Your libtbb version is " +
std::string(TBB_runtime_version()) +
". Please upgrade your libtbb library and try again.\n";
sigaction(SIGABRT, &action, NULL);
}
}
} // namespace mold
+55
View File
@@ -0,0 +1,55 @@
#include "common.h"
#include <windows.h>
namespace mold {
void cleanup() {
if (output_tmpfile)
_unlink(output_tmpfile);
}
std::string errno_string() {
LPVOID buf;
DWORD dw = GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&buf, 0, nullptr);
std::string ret = (char *)buf;
LocalFree(buf);
return ret;
}
static LONG WINAPI vectored_handler(_EXCEPTION_POINTERS *exception_info) {
static std::mutex mu;
std::scoped_lock lock{mu};
PEXCEPTION_RECORD rec = exception_info->ExceptionRecord;
ULONG_PTR *p = rec->ExceptionInformation;
if (rec->ExceptionCode == EXCEPTION_IN_PAGE_ERROR &&
(ULONG_PTR)output_buffer_start <= p[1] &&
p[1] < (ULONG_PTR)output_buffer_end) {
static const char msg[] =
"mold: failed to write to an output file. Disk full?\n";
(void)!_write(_fileno(stderr), msg, sizeof(msg) - 1);
} else if (rec->ExceptionCode == EXCEPTION_STACK_OVERFLOW) {
static const char msg[] =
"mold: stack overflow\n";
(void)!_write(_fileno(stderr), msg, sizeof(msg) - 1);
}
cleanup();
_exit(1);
}
void install_signal_handler() {
AddVectoredExceptionHandler(0, vectored_handler);
}
} // namespace mold
+144
View File
@@ -0,0 +1,144 @@
// This is a header-only C++20 implementation of SipHash based on the
// reference implementation. To use, just copy this header file into
// your project and #include it.
//
// https://github.com/rui314/siphash/blob/main/siphash.h
#include <bit>
#include <cstdint>
#include <cstring>
template <int C_ROUNDS, int D_ROUNDS, int OUTLEN>
class SipHashTmpl {
public:
static_assert(OUTLEN == 64 || OUTLEN == 128);
SipHashTmpl(void *key) {
uint64_t k0 = read64(key);
uint64_t k1 = read64((char *)key + 8);
v0 = 0x736f6d6570736575 ^ k0;
v1 = 0x646f72616e646f6d ^ k1;
v2 = 0x6c7967656e657261 ^ k0;
v3 = 0x7465646279746573 ^ k1;
if (OUTLEN == 128)
v1 ^= 0xee;
}
void update(void *msgp, int64_t msglen) {
char *msg = (char *)msgp;
sum += msglen;
if (buflen) {
if (buflen + msglen < 8) {
memcpy(buf + buflen, msg, msglen);
buflen += msglen;
return;
}
int j = 8 - buflen;
memcpy(buf + buflen, msg, j);
compress(read64(buf));
msg += j;
msglen -= j;
buflen = 0;
}
while (msglen >= 8) {
compress(read64(msg));
msg += 8;
msglen -= 8;
}
memcpy(buf, msg, msglen);
buflen = msglen;
}
void finish(void *out) {
memset(buf + buflen, 0, 8 - buflen);
compress(((uint64_t)sum << 56) | read64(buf));
v2 ^= (OUTLEN == 128) ? 0xee : 0xff;
finalize();
write64(out, v0 ^ v1 ^ v2 ^ v3);
if (OUTLEN == 128) {
v1 ^= 0xdd;
finalize();
write64((char *)out + 8, v0 ^ v1 ^ v2 ^ v3);
}
}
static void hash(void *out, void *key, void *in, int inlen) {
SipHashTmpl<C_ROUNDS, D_ROUNDS, OUTLEN> h(key);
h.update(in, inlen);
h.finish(out);
}
private:
uint64_t v0, v1, v2, v3;
uint8_t buf[8];
uint8_t buflen = 0;
uint8_t sum = 0;
uint64_t read64(void *loc) {
uint64_t val;
memcpy(&val, loc, 8);
if (std::endian::native == std::endian::big)
val = bswap(val);
return val;
}
void write64(void *loc, uint64_t val) {
if (std::endian::native == std::endian::big)
val = bswap(val);
memcpy(loc, &val, 8);
}
uint64_t bswap(uint64_t val) {
return ((val << 56) & 0xff00000000000000) |
((val << 40) & 0x00ff000000000000) |
((val << 24) & 0x0000ff0000000000) |
((val << 8) & 0x000000ff00000000) |
((val >> 8) & 0x00000000ff000000) |
((val >> 24) & 0x0000000000ff0000) |
((val >> 40) & 0x000000000000ff00) |
((val >> 56) & 0x00000000000000ff);
}
void round() {
v0 += v1;
v1 = std::rotl(v1, 13);
v1 ^= v0;
v0 = std::rotl(v0, 32);
v2 += v3;
v3 = std::rotl(v3, 16);
v3 ^= v2;
v0 += v3;
v3 = std::rotl(v3, 21);
v3 ^= v0;
v2 += v1;
v1 = std::rotl(v1, 17);
v1 ^= v2;
v2 = std::rotl(v2, 32);
}
void compress(uint64_t m) {
v3 ^= m;
for (int i = 0; i < C_ROUNDS; i++)
round();
v0 ^= m;
}
void finalize() {
for (int i = 0; i < D_ROUNDS; i++)
round();
}
};
using SipHash = SipHashTmpl<2, 4, 64>;
using SipHash128 = SipHashTmpl<2, 4, 128>;
using SipHash13 = SipHashTmpl<1, 3, 64>;
using SipHash13_128 = SipHashTmpl<1, 3, 128>;
+114
View File
@@ -0,0 +1,114 @@
// This file contains functions to create a tar file.
#include "common.h"
#ifdef _WIN32
# define ftruncate _chsize_s
#endif
namespace mold {
static constexpr i64 BLOCK_SIZE = 512;
// A tar file consists of one or more Ustar header followed by data.
// Each Ustar header represents a single file in an archive.
//
// tar is an old file format, and its `name` field is only 100 bytes long.
// If `name` is longer than 100 bytes, we can emit a PAX header before a
// Ustar header to store a long filename.
//
// For simplicity, we always emit a PAX header even for a short filename.
struct UstarHeader {
char name[100];
char mode[8];
char uid[8];
char gid[8];
char size[12];
char mtime[12];
char checksum[8];
char typeflag[1];
char linkname[100];
char magic[6];
char version[2];
char uname[32];
char gname[32];
char devmajor[8];
char devminor[8];
char prefix[155];
char pad[12];
};
static_assert(sizeof(UstarHeader) == BLOCK_SIZE);
static void finalize(UstarHeader &hdr) {
memset(hdr.checksum, ' ', sizeof(hdr.checksum));
memcpy(hdr.magic, "ustar", 5);
memcpy(hdr.version, "00", 2);
// Compute checksum
int sum = 0;
for (i64 i = 0; i < sizeof(hdr); i++)
sum += ((u8 *)&hdr)[i];
// We need to convince the compiler that sum isn't too big to silence
// -Werror=format-truncation.
if (sum >= 01'000'000)
unreachable();
snprintf(hdr.checksum, sizeof(hdr.checksum), "%06o", sum);
}
static std::string encode_path(std::string basedir, std::string path) {
path = path_clean(basedir + "/" + path);
// Construct a string which contains something like
// "16 path=foo/bar\n" where 16 is the size of the string
// including the size string itself.
i64 len = std::string(" path=\n").size() + path.size();
i64 total = std::to_string(len).size() + len;
total = std::to_string(total).size() + len;
return std::to_string(total) + " path=" + path + "\n";
}
std::unique_ptr<TarWriter>
TarWriter::open(std::string output_path, std::string basedir) {
FILE *out = fopen(output_path.c_str(), "w");
if (!out)
return nullptr;
return std::unique_ptr<TarWriter>(new TarWriter(out, basedir));
}
TarWriter::~TarWriter() {
fclose(out);
}
void TarWriter::append(std::string path, std::string_view data) {
// Write PAX header
UstarHeader pax = {};
std::string attr = encode_path(basedir, path);
snprintf(pax.size, sizeof(pax.size), "%011zo", attr.size());
pax.name[0] = '/';
pax.typeflag[0] = 'x';
finalize(pax);
fwrite(&pax, sizeof(pax), 1, out);
// Write pathname
fwrite(attr.data(), attr.size(), 1, out);
fseek(out, align_to(ftell(out), BLOCK_SIZE), SEEK_SET);
// Write Ustar header
UstarHeader ustar = {};
memcpy(ustar.mode, "0000664", 8);
snprintf(ustar.size, sizeof(ustar.size), "%011zo", data.size());
finalize(ustar);
fwrite(&ustar, sizeof(ustar), 1, out);
// Write file contents
fwrite(data.data(), data.size(), 1, out);
fseek(out, align_to(ftell(out), BLOCK_SIZE), SEEK_SET);
// A tar file must ends with two empty blocks
(void)!ftruncate(fileno(out), ftell(out) + BLOCK_SIZE * 2);
}
} // namespace mold
+33
View File
@@ -0,0 +1,33 @@
# Get a git hash value. We do not want to use git command here
# because we don't want to make git a build-time dependency.
if(EXISTS "${SOURCE_DIR}/.git/HEAD")
file(READ "${SOURCE_DIR}/.git/HEAD" HASH)
string(STRIP "${HASH}" HASH)
if(HASH MATCHES "^ref: (.*)")
set(HEAD "${CMAKE_MATCH_1}")
if(EXISTS "${SOURCE_DIR}/.git/${HEAD}")
file(READ "${SOURCE_DIR}/.git/${HEAD}" HASH)
string(STRIP "${HASH}" HASH)
else()
file(READ "${SOURCE_DIR}/.git/packed-refs" PACKED_REFS)
string(REGEX REPLACE ".*\n([0-9a-f]+) ${HEAD}\n.*" "\\1" HASH "\n${PACKED_REFS}")
endif()
endif()
endif()
# Create new file contents and update a given file if necessary.
set(NEW_CONTENTS "#include <string>
namespace mold {
std::string mold_git_hash = \"${HASH}\";
}
")
if(EXISTS "${OUTPUT_FILE}")
file(READ "${OUTPUT_FILE}" OLD_CONTENTS)
if(NOT "${NEW_CONTENTS}" STREQUAL "${OLD_CONTENTS}")
file(WRITE "${OUTPUT_FILE}" "${NEW_CONTENTS}")
endif()
else()
file(WRITE "${OUTPUT_FILE}" "${NEW_CONTENTS}")
endif()
-364
View File
@@ -1,364 +0,0 @@
// On Linux, /usr/lib/x86_64-linux-gnu/libc.so is not actually
// a shared object file but an ASCII text file containing a linker
// script to include a "real" libc.so file. Therefore, we need to
// support a (very limited) subset of the linker script language.
#include "mold.h"
#include <cctype>
#include <iomanip>
template <typename E>
static thread_local MemoryMappedFile<E> *current_file;
static std::string_view get_line(std::string_view input, const char *pos) {
assert(input.data() <= pos);
assert(pos < input.data() + input.size());
i64 start = input.rfind('\n', pos - input.data());
if (start == input.npos)
start = 0;
else
start++;
i64 end = input.find('\n', pos - input.data());
if (end == input.npos)
end = input.size();
return input.substr(start, end - start);
}
template <typename E>
class SyntaxError {
public:
SyntaxError(Context<E> &ctx, std::string_view errpos) : out(ctx) {
std::string_view contents = current_file<E>->get_contents(ctx);
std::string_view line = get_line(contents, errpos.data());
i64 lineno = 1;
for (i64 i = 0; contents.data() + i < line.data(); i++)
if (contents[i] == '\n')
lineno++;
i64 column = errpos.data() - line.data();
std::stringstream ss;
ss << current_file<E>->name << ":" << lineno << ": ";
i64 indent = (i64)ss.tellp() + strlen("mold: ");
ss << line << "\n" << std::setw(indent + column) << " " << "^ ";
out << ss.str();
}
template <class T> SyntaxError &operator<<(T &&val) {
out << std::forward<T>(val);
return *this;
}
[[noreturn]] ~SyntaxError() = default;
Fatal<E> out;
};
template <typename E>
static std::vector<std::string_view>
tokenize(Context<E> &ctx, std::string_view input) {
std::vector<std::string_view> vec;
while (!input.empty()) {
if (isspace(input[0])) {
input = input.substr(1);
continue;
}
if (input.starts_with("/*")) {
i64 pos = input.find("*/", 2);
if (pos == std::string_view::npos)
SyntaxError(ctx, input) << "unclosed comment";
input = input.substr(pos + 2);
continue;
}
if (input[0] == '#') {
i64 pos = input.find("\n", 1);
if (pos == std::string_view::npos)
break;
input = input.substr(pos + 1);
continue;
}
if (input[0] == '"') {
i64 pos = input.find('"', 1);
if (pos == std::string_view::npos)
SyntaxError(ctx, input) << "unclosed string literal";
vec.push_back(input.substr(0, pos + 1));
input = input.substr(pos + 1);
continue;
}
i64 pos = input.find_first_not_of(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
"0123456789_.$/\\~=+[]*?-!^:");
if (pos == 0)
pos = 1;
else if (pos == input.npos)
pos = input.size();
vec.push_back(input.substr(0, pos));
input = input.substr(pos);
}
return vec;
}
template <typename E>
static std::span<std::string_view>
skip(Context<E> &ctx, std::span<std::string_view> tok, std::string_view str) {
if (tok.empty())
Fatal(ctx) << current_file<E>->name << ": expected '" << str
<< "', but got EOF";
if (tok[0] != str)
SyntaxError(ctx, tok[0]) << "expected '" << str << "'";
return tok.subspan(1);
}
static std::string_view unquote(std::string_view s) {
if (s.size() > 0 && s[0] == '"') {
assert(s[s.size() - 1] == '"');
return s.substr(1, s.size() - 2);
}
return s;
}
template <typename E>
static std::span<std::string_view>
read_output_format(Context<E> &ctx, std::span<std::string_view> tok) {
tok = skip(ctx, tok, "(");
while (!tok.empty() && tok[0] != ")")
tok = tok.subspan(1);
if (tok.empty())
Fatal(ctx) << current_file<E>->name << ": expected ')', but got EOF";
return tok.subspan(1);
}
template <typename E>
static MemoryMappedFile<E> *resolve_path(Context<E> &ctx, std::string_view tok) {
std::string str(unquote(tok));
if (str.starts_with("/"))
return MemoryMappedFile<E>::must_open(ctx, ctx.arg.sysroot + str);
if (str.starts_with("-l"))
return find_library(ctx, str.substr(2));
if (std::string dir(path_dirname(current_file<E>->name));
MemoryMappedFile<E> *mb = MemoryMappedFile<E>::open(ctx, dir + "/" + str))
return mb;
if (MemoryMappedFile<E> *mb = MemoryMappedFile<E>::open(ctx, str))
return mb;
for (std::string_view dir : ctx.arg.library_paths) {
std::string root = dir.starts_with("/") ? ctx.arg.sysroot : "";
std::string path = root + std::string(dir) + "/" + str;
if (MemoryMappedFile<E> *mb = MemoryMappedFile<E>::open(ctx, path))
return mb;
}
SyntaxError(ctx, tok) << "library not found: " << str;
}
template <typename E>
static std::span<std::string_view>
read_group(Context<E> &ctx, std::span<std::string_view> tok) {
tok = skip(ctx, tok, "(");
while (!tok.empty() && tok[0] != ")") {
if (tok[0] == "AS_NEEDED") {
bool orig = ctx.as_needed;
ctx.as_needed = true;
tok = read_group(ctx, tok.subspan(1));
ctx.as_needed = orig;
continue;
}
MemoryMappedFile<E> *mb = resolve_path(ctx, tok[0]);
read_file(ctx, mb);
tok = tok.subspan(1);
}
if (tok.empty())
Fatal(ctx) << current_file<E>->name << ": expected ')', but got EOF";
return tok.subspan(1);
}
template <typename E>
void parse_linker_script(Context<E> &ctx, MemoryMappedFile<E> *mb) {
current_file<E> = mb;
std::vector<std::string_view> vec = tokenize(ctx, mb->get_contents(ctx));
std::span<std::string_view> tok = vec;
while (!tok.empty()) {
if (tok[0] == "OUTPUT_FORMAT")
tok = read_output_format(ctx, tok.subspan(1));
else if (tok[0] == "INPUT" || tok[0] == "GROUP")
tok = read_group(ctx, tok.subspan(1));
else
SyntaxError(ctx, tok[0]) << "unknown token";
}
}
template <typename E>
i64 get_script_output_type(Context<E> &ctx, MemoryMappedFile<E> *mb) {
current_file<E> = mb;
std::vector<std::string_view> vec = tokenize(ctx, mb->get_contents(ctx));
std::span<std::string_view> tok = vec;
if (tok.size() >= 3 && tok[0] == "OUTPUT_FORMAT" && tok[1] == "(") {
if (tok[2] == "elf64-x86-64")
return EM_X86_64;
if (tok[2] == "elf32-i386")
return EM_386;
}
return -1;
}
static bool read_label(std::span<std::string_view> &tok,
std::string label) {
if (tok.size() >= 1 && tok[0] == label + ":") {
tok = tok.subspan(1);
return true;
}
if (tok.size() >= 2 && tok[0] == label && tok[1] == ":") {
tok = tok.subspan(2);
return true;
}
return false;
}
template <typename E>
static void parse_version_script_commands(Context<E> &ctx,
std::span<std::string_view> &tok,
i16 &ver, bool is_extern_cpp) {
bool is_global = true;
while (!tok.empty() && tok[0] != "}") {
if (read_label(tok, "global")) {
is_global = true;
continue;
}
if (read_label(tok, "local")) {
is_global = false;
continue;
}
if (tok[0] == "extern") {
tok = tok.subspan(1);
bool is_cpp;
if (!tok.empty() && tok[0] == "\"C\"") {
tok = tok.subspan(1);
is_cpp = false;
} else {
tok = skip(ctx, tok, "\"C++\"");
is_cpp = true;
}
tok = skip(ctx, tok, "{");
parse_version_script_commands(ctx, tok, ver, is_cpp);
tok = skip(ctx, tok, "}");
tok = skip(ctx, tok, ";");
continue;
}
if (tok[0] == "*")
ctx.arg.default_version = (is_global ? ver : VER_NDX_LOCAL);
else
ctx.arg.version_patterns.push_back({tok[0], ver, is_extern_cpp});
tok = tok.subspan(1);
if (!tok.empty() && tok[0] == "}")
return;
tok = skip(ctx, tok, ";");
}
}
template <typename E>
void parse_version_script(Context<E> &ctx, std::string path) {
current_file<E> = MemoryMappedFile<E>::must_open(ctx, path);
std::vector<std::string_view> vec =
tokenize(ctx, current_file<E>->get_contents(ctx));
std::span<std::string_view> tok = vec;
i16 next_ver = VER_NDX_LAST_RESERVED + 1;
while (!tok.empty()) {
i16 ver = VER_NDX_GLOBAL;
if (tok[0] != "{") {
ver = next_ver++;
ctx.arg.version_definitions.push_back(tok[0]);
tok = tok.subspan(1);
}
tok = skip(ctx, tok, "{");
parse_version_script_commands(ctx, tok, ver, false);
tok = skip(ctx, tok, "}");
if (!tok.empty() && tok[0] != ";")
tok = tok.subspan(1);
tok = skip(ctx, tok, ";");
}
if (!tok.empty())
SyntaxError(ctx, tok[0]) << "trailing garbage token";
}
template <typename E>
void parse_dynamic_list(Context<E> &ctx, std::string path) {
current_file<E> = MemoryMappedFile<E>::must_open(ctx, path);
std::vector<std::string_view> vec =
tokenize(ctx, current_file<E>->get_contents(ctx));
std::span<std::string_view> tok = vec;
tok = skip(ctx, tok, "{");
i16 ver = VER_NDX_GLOBAL;
while (!tok.empty() && tok[0] != "}") {
if (read_label(tok, "global")) {
ver = VER_NDX_GLOBAL;
continue;
}
if (read_label(tok, "local")) {
ver = VER_NDX_LOCAL;
continue;
}
if (tok[0] == "*")
ctx.arg.default_version = ver;
else
ctx.arg.version_patterns.push_back({tok[0], ver, false});
tok = skip(ctx, tok.subspan(1), ";");
}
tok = skip(ctx, tok, "}");
tok = skip(ctx, tok, ";");
if (!tok.empty())
SyntaxError(ctx, tok[0]) << "trailing garbage token";
}
#define INSTANTIATE(E) \
template \
void parse_linker_script(Context<E> &ctx, MemoryMappedFile<E> *mb); \
template \
i64 get_script_output_type(Context<E> &ctx, MemoryMappedFile<E> *mb); \
template \
void parse_version_script(Context<E> &ctx, std::string path); \
template \
void parse_dynamic_list(Context<E> &ctx, std::string path)
INSTANTIATE(X86_64);
INSTANTIATE(I386);
-682
View File
@@ -1,682 +0,0 @@
#include "mold.h"
#include <functional>
#include <iomanip>
#include <map>
#include <signal.h>
#include <tbb/global_control.h>
#include <tbb/parallel_for_each.h>
#include <unistd.h>
#include <unordered_set>
template <typename E>
std::string_view save_string(Context<E> &ctx, const std::string &str) {
u8 *buf = new u8[str.size() + 1];
memcpy(buf, str.data(), str.size());
buf[str.size()] = '\0';
ctx.owning_bufs.push_back(std::unique_ptr<u8[]>(buf));
return {(char *)buf, str.size()};
}
std::string get_version_string() {
if (strlen(GIT_HASH) == 0)
return "mold " MOLD_VERSION " (compatible with GNU ld and GNU gold)";
return "mold " MOLD_VERSION " (" GIT_HASH
"; compatible with GNU ld and GNU gold)";
}
std::regex glob_to_regex(std::string_view pattern) {
std::stringstream ss;
for (u8 c : pattern) {
if (c == '*')
ss << ".*";
else
ss << "\\x" << std::hex << std::setw(2) << std::setfill('0') << (int)c;
}
return std::regex(ss.str(), std::regex::optimize);
}
template <typename E>
static ObjectFile<E> *new_object_file(Context<E> &ctx, MemoryMappedFile<E> *mb,
std::string archive_name) {
static Counter count("parsed_objs");
count++;
bool in_lib = (!archive_name.empty() && !ctx.whole_archive);
ObjectFile<E> *file = ObjectFile<E>::create(ctx, mb, archive_name, in_lib);
file->priority = ctx.file_priority++;
ctx.tg.run([file, &ctx]() { file->parse(ctx); });
if (ctx.arg.trace)
SyncOut(ctx) << "trace: " << *file;
return file;
}
template <typename E>
static SharedFile<E> *new_shared_file(Context<E> &ctx, MemoryMappedFile<E> *mb) {
SharedFile<E> *file = SharedFile<E>::create(ctx, mb);
file->priority = ctx.file_priority++;
ctx.tg.run([file, &ctx]() { file->parse(ctx); });
if (ctx.arg.trace)
SyncOut(ctx) << "trace: " << *file;
return file;
}
template <typename E>
void read_file(Context<E> &ctx, MemoryMappedFile<E> *mb) {
if (ctx.visited.contains(mb->name))
return;
if (ctx.is_preloading) {
switch (get_file_type(ctx, mb)) {
case FileType::OBJ:
ctx.obj_cache.store(mb, new_object_file(ctx, mb, ""));
return;
case FileType::DSO:
ctx.dso_cache.store(mb, new_shared_file(ctx, mb));
return;
case FileType::AR:
for (MemoryMappedFile<E> *child : read_fat_archive_members(ctx, mb))
if (get_file_type(ctx, child) == FileType::OBJ)
ctx.obj_cache.store(mb, new_object_file(ctx, child, mb->name));
return;
case FileType::THIN_AR:
for (MemoryMappedFile<E> *child : read_thin_archive_members(ctx, mb))
if (get_file_type(ctx, child) == FileType::OBJ)
ctx.obj_cache.store(child, new_object_file(ctx, child, mb->name));
return;
case FileType::TEXT:
parse_linker_script(ctx, mb);
return;
case FileType::LLVM_BITCODE:
Fatal(ctx) << mb->name << ": looks like this is an LLVM bitcode, but"
<< " mold does not support LTO";
default:
Fatal(ctx) << mb->name << ": unknown file type";
}
}
switch (get_file_type(ctx, mb)) {
case FileType::OBJ:
if (ObjectFile<E> *obj = ctx.obj_cache.get_one(mb))
ctx.objs.push_back(obj);
else
ctx.objs.push_back(new_object_file(ctx, mb, ""));
return;
case FileType::DSO:
if (SharedFile<E> *obj = ctx.dso_cache.get_one(mb))
ctx.dsos.push_back(obj);
else
ctx.dsos.push_back(new_shared_file(ctx, mb));
ctx.visited.insert(mb->name);
return;
case FileType::AR: {
std::vector<ObjectFile<E> *> objs = ctx.obj_cache.get(mb);
if (!objs.empty()) {
append(ctx.objs, objs);
} else {
for (MemoryMappedFile<E> *child : read_fat_archive_members(ctx, mb))
if (get_file_type(ctx, child) == FileType::OBJ)
ctx.objs.push_back(new_object_file(ctx, child, mb->name));
}
ctx.visited.insert(mb->name);
return;
}
case FileType::THIN_AR:
for (MemoryMappedFile<E> *child : read_thin_archive_members(ctx, mb)) {
if (ObjectFile<E> *obj = ctx.obj_cache.get_one(child))
ctx.objs.push_back(obj);
else if (get_file_type(ctx, child) == FileType::OBJ)
ctx.objs.push_back(new_object_file(ctx, child, mb->name));
}
ctx.visited.insert(mb->name);
return;
case FileType::TEXT:
parse_linker_script(ctx, mb);
return;
case FileType::LLVM_BITCODE:
Fatal(ctx) << mb->name << ": looks like this is an LLVM bitcode, "
<< "but mold does not support LTO";
default:
Fatal(ctx) << mb->name << ": unknown file type";
}
}
template <typename E>
void cleanup() {
if (OutputFile<E>::tmpfile)
unlink(OutputFile<E>::tmpfile);
if (socket_tmpfile)
unlink(socket_tmpfile);
}
template <typename E>
static void signal_handler(int) {
cleanup<E>();
_exit(1);
}
// Read the beginning of a given file and returns its machine type
// (e.g. EM_X86_64 or EM_386). Return -1 if unknown.
template <typename E>
static i64 get_machine_type(Context<E> &ctx, MemoryMappedFile<E> *mb) {
switch (get_file_type(ctx, mb)) {
case FileType::DSO:
return ((ElfEhdr<E> *)mb->data(ctx))->e_machine;
case FileType::AR:
for (MemoryMappedFile<E> *child : read_fat_archive_members(ctx, mb))
if (get_file_type(ctx, child) == FileType::OBJ)
return ((ElfEhdr<E> *)child->data(ctx))->e_machine;
return -1;
case FileType::THIN_AR:
for (MemoryMappedFile<E> *child : read_thin_archive_members(ctx, mb))
if (get_file_type(ctx, child) == FileType::OBJ)
return ((ElfEhdr<E> *)child->data(ctx))->e_machine;
return -1;
case FileType::TEXT:
return get_script_output_type(ctx, mb);
default:
return -1;
}
}
template <typename E>
static MemoryMappedFile<E> *open_library(Context<E> &ctx, std::string path) {
MemoryMappedFile<E> *mb = MemoryMappedFile<E>::open(ctx, path);
if (!mb)
return nullptr;
i64 type = get_machine_type(ctx, mb);
if (type == -1 || type == E::e_machine)
return mb;
Warn(ctx) << path << ": skipping incompatible file";
return nullptr;
}
template <typename E>
MemoryMappedFile<E> *find_library(Context<E> &ctx, std::string name) {
if (name.starts_with(':')) {
for (std::string_view dir : ctx.arg.library_paths) {
std::string root = dir.starts_with("/") ? ctx.arg.sysroot : "";
std::string path = root + std::string(dir) + "/" + name.substr(1);
if (MemoryMappedFile<E> *mb = open_library(ctx, path))
return mb;
}
Fatal(ctx) << "library not found: " << name;
}
for (std::string_view dir : ctx.arg.library_paths) {
std::string root = dir.starts_with("/") ? ctx.arg.sysroot : "";
std::string stem = root + std::string(dir) + "/lib" + name;
if (!ctx.is_static)
if (MemoryMappedFile<E> *mb = open_library(ctx, stem + ".so"))
return mb;
if (MemoryMappedFile<E> *mb = open_library(ctx, stem + ".a"))
return mb;
}
Fatal(ctx) << "library not found: " << name;
}
template <typename E>
static void read_input_files(Context<E> &ctx, std::span<std::string_view> args) {
std::vector<std::tuple<bool, bool, bool>> state;
while (!args.empty()) {
std::string_view arg;
if (read_flag(args, "as-needed")) {
ctx.as_needed = true;
} else if (read_flag(args, "no-as-needed")) {
ctx.as_needed = false;
} else if (read_flag(args, "whole-archive")) {
ctx.whole_archive = true;
} else if (read_flag(args, "no-whole-archive")) {
ctx.whole_archive = false;
} else if (read_flag(args, "Bstatic")) {
ctx.is_static = true;
} else if (read_flag(args, "Bdynamic")) {
ctx.is_static = false;
} else if (read_arg(ctx, args, arg, "version-script")) {
parse_version_script(ctx, std::string(arg));
} else if (read_arg(ctx, args, arg, "dynamic-list")) {
parse_dynamic_list(ctx, std::string(arg));
} else if (read_flag(args, "push-state")) {
state.push_back({ctx.as_needed, ctx.whole_archive, ctx.is_static});
} else if (read_flag(args, "pop-state")) {
if (state.empty())
Fatal(ctx) << "no state pushed before popping";
std::tie(ctx.as_needed, ctx.whole_archive, ctx.is_static) = state.back();
state.pop_back();
} else if (read_arg(ctx, args, arg, "l")) {
MemoryMappedFile<E> *mb = find_library(ctx, std::string(arg));
mb->given_fullpath = false;
read_file(ctx, mb);
} else {
read_file(ctx, MemoryMappedFile<E>::must_open(ctx, std::string(args[0])));
args = args.subspan(1);
}
}
}
template <typename E>
static void show_stats(Context<E> &ctx) {
for (ObjectFile<E> *obj : ctx.objs) {
static Counter defined("defined_syms");
defined += obj->first_global - 1;
static Counter undefined("undefined_syms");
undefined += obj->symbols.size() - obj->first_global;
for (std::unique_ptr<InputSection<E>> &sec : obj->sections) {
if (!sec || !sec->is_alive)
continue;
static Counter alloc("reloc_alloc");
static Counter nonalloc("reloc_nonalloc");
if (sec->shdr.sh_flags & SHF_ALLOC)
alloc += sec->get_rels(ctx).size();
else
nonalloc += sec->get_rels(ctx).size();
}
static Counter comdats("comdats");
comdats += obj->comdat_groups.size();
static Counter removed_comdats("removed_comdat_mem");
for (auto &pair : obj->comdat_groups)
if (ComdatGroup *group = pair.first; group->owner != obj->priority)
removed_comdats += pair.second.size();
static Counter num_cies("num_cies");
num_cies += obj->cies.size();
static Counter num_unique_cies("num_unique_cies");
for (CieRecord<E> &cie : obj->cies)
if (cie.is_leader)
num_unique_cies++;
static Counter num_fdes("num_fdes");
num_fdes += obj->fdes.size();
}
static Counter num_bytes("total_input_bytes");
for (std::unique_ptr<MemoryMappedFile<E>> &mb : ctx.owning_mbs)
num_bytes += mb->size();
static Counter num_input_sections("input_sections");
for (ObjectFile<E> *file : ctx.objs)
num_input_sections += file->sections.size();
static Counter num_output_chunks("output_chunks", ctx.chunks.size());
static Counter num_objs("num_objs", ctx.objs.size());
static Counter num_dsos("num_dsos", ctx.dsos.size());
Counter::print();
}
template <typename E>
int do_main(int argc, char **argv) {
Context<E> ctx;
// Process -run option first. process_run_subcommand() does not return.
if (argc >= 2)
if (std::string_view arg = argv[1]; arg == "-run" || arg == "--run")
process_run_subcommand(ctx, argc, argv);
Timer t_all(ctx, "all");
// Parse non-positional command line options
ctx.cmdline_args = expand_response_files(ctx, argv);
std::vector<std::string_view> file_args;
parse_nonpositional_args(ctx, file_args);
if (ctx.arg.relocatable) {
combine_objects(ctx, file_args);
return 0;
}
if (!ctx.arg.preload)
try_resume_daemon(ctx);
tbb::global_control tbb_cont(tbb::global_control::max_allowed_parallelism,
ctx.arg.thread_count);
signal(SIGINT, signal_handler<E>);
signal(SIGTERM, signal_handler<E>);
if (!ctx.arg.directory.empty() && chdir(ctx.arg.directory.c_str()) == -1)
Fatal(ctx) << "chdir failed: " << ctx.arg.directory
<< ": " << strerror(errno);
// Handle --wrap options if any.
for (std::string_view name : ctx.arg.wrap)
Symbol<E>::intern(ctx, name)->wrap = true;
// Handle --retain-symbols-file options if any.
if (ctx.arg.retain_symbols_file)
for (std::string_view name : *ctx.arg.retain_symbols_file)
Symbol<E>::intern(ctx, name)->write_to_symtab = true;
// Preload input files
std::function<void()> on_complete;
if (ctx.arg.preload) {
Timer t(ctx, "preload");
std::function<void()> wait_for_client;
daemonize(ctx, &wait_for_client, &on_complete);
ctx.reset_reader_context(true);
read_input_files(ctx, file_args);
ctx.tg.wait();
t.stop();
Timer t2(ctx, "wait_for_client");
wait_for_client();
} else if (ctx.arg.fork) {
on_complete = fork_child();
}
for (std::string_view arg : ctx.arg.trace_symbol)
Symbol<E>::intern(ctx, arg)->traced = true;
// Parse input files
{
Timer t(ctx, "parse");
ctx.reset_reader_context(false);
read_input_files(ctx, file_args);
ctx.tg.wait();
}
if (ctx.objs.empty())
Fatal(ctx) << "no input files";
// Uniquify shared object files by soname
{
std::unordered_set<std::string_view> seen;
erase(ctx.dsos, [&](SharedFile<E> *file) {
return !seen.insert(file->soname).second;
});
}
Timer t_total(ctx, "total");
Timer t_before_copy(ctx, "before_copy");
// Apply -exclude-libs
apply_exclude_libs(ctx);
// Create instances of linker-synthesized sections such as
// .got or .plt.
create_synthetic_sections(ctx);
// Resolve symbols and fix the set of object files that are
// included to the final output.
resolve_symbols(ctx);
// Remove redundant comdat sections (e.g. duplicate inline functions).
eliminate_comdats(ctx);
// Create .bss sections for common symbols.
convert_common_symbols(ctx);
// Apply version scripts.
apply_version_script(ctx);
// Parse symbol version suffixes (e.g. "foo@ver1").
parse_symbol_version(ctx);
// Set is_import and is_export bits for each symbol.
compute_import_export(ctx);
// Garbage-collect unreachable sections.
if (ctx.arg.gc_sections)
gc_sections(ctx);
// Merge identical read-only sections.
if (ctx.arg.icf)
icf_sections(ctx);
// Compute sizes of sections containing mergeable strings.
compute_merged_section_sizes(ctx);
// ctx input sections into output sections
bin_sections(ctx);
// Get a list of output sections.
append(ctx.chunks, collect_output_sections(ctx));
// Create a dummy file containing linker-synthesized symbols
// (e.g. `__bss_start`).
ctx.internal_obj = ObjectFile<E>::create_internal_file(ctx);
ctx.internal_obj->resolve_regular_symbols(ctx);
ctx.objs.push_back(ctx.internal_obj);
// Beyond this point, no new files will be added to ctx.objs
// or ctx.dsos.
// If we are linking a .so file, remaining undefined symbols does
// not cause a linker error. Instead, they are treated as if they
// were imported symbols.
//
// If we are linking an executable, weak undefs are converted to
// weakly imported symbol so that they'll have another chance to be
claim_unresolved_symbols(ctx);
// Beyond this point, no new symbols will be added to the result.
// Make sure that all symbols have been resolved.
if (!ctx.arg.allow_multiple_definition)
check_duplicate_symbols(ctx);
// .init_array and .fini_array contents have to be sorted by
// a special rule. Sort them.
sort_init_fini(ctx);
// Compute sizes of output sections while assigning offsets
// within an output section to input sections.
compute_section_sizes(ctx);
// Sort sections by section attributes so that we'll have to
// create as few segments as possible.
sort(ctx.chunks, [&](OutputChunk<E> *a, OutputChunk<E> *b) {
return get_section_rank(ctx, a) < get_section_rank(ctx, b);
});
// Copy string referred by .dynamic to .dynstr.
for (SharedFile<E> *file : ctx.dsos)
ctx.dynstr->add_string(file->soname);
for (std::string_view str : ctx.arg.auxiliary)
ctx.dynstr->add_string(str);
for (std::string_view str : ctx.arg.filter)
ctx.dynstr->add_string(str);
if (!ctx.arg.rpaths.empty())
ctx.dynstr->add_string(ctx.arg.rpaths);
if (!ctx.arg.soname.empty())
ctx.dynstr->add_string(ctx.arg.soname);
// Scan relocations to find symbols that need entries in .got, .plt,
// .got.plt, .dynsym, .dynstr, etc.
scan_rels(ctx);
// Reserve a space for dynamic symbol strings in .dynstr and sort
// .dynsym contents if necessary. Beyond this point, no symbol will
// be added to .dynsym.
ctx.dynsym->finalize(ctx);
// Fill .gnu.version_d section contents.
ctx.verdef->construct(ctx);
// Fill .gnu.version_r section contents.
ctx.verneed->construct(ctx);
// Compute .symtab and .strtab sizes for each file.
{
Timer t(ctx, "compute_symtab");
tbb::parallel_for_each(ctx.objs, [&](ObjectFile<E> *file) {
file->compute_symtab(ctx);
});
}
// .eh_frame is a special section from the linker's point of view,
// as its contents are parsed and reconstructed by the linker,
// unlike other sections that are regarded as opaque bytes.
// Here, we transplant .eh_frame sections from a regular output
// section to the special EHFrameSection.
{
Timer t(ctx, "eh_frame");
erase(ctx.chunks, [](OutputChunk<E> *chunk) {
return chunk->kind == OutputChunk<E>::REGULAR &&
chunk->name == ".eh_frame";
});
ctx.eh_frame->construct(ctx);
}
// Now that we have computed sizes for all sections and assigned
// section indices to them, so we can fix section header contents
// for all output sections.
for (OutputChunk<E> *chunk : ctx.chunks)
chunk->update_shdr(ctx);
erase(ctx.chunks, [](OutputChunk<E> *chunk) {
return chunk->kind == OutputChunk<E>::SYNTHETIC &&
chunk->shdr.sh_size == 0;
});
// Set section indices.
for (i64 i = 0, shndx = 1; i < ctx.chunks.size(); i++)
if (ctx.chunks[i]->kind != OutputChunk<E>::HEADER)
ctx.chunks[i]->shndx = shndx++;
for (OutputChunk<E> *chunk : ctx.chunks)
chunk->update_shdr(ctx);
// Assign offsets to output sections
i64 filesize = set_osec_offsets(ctx);
// Fix linker-synthesized symbol addresses.
fix_synthetic_symbols(ctx);
// If --compress-debug-sections is given, compress .debug_* sections
// using zlib.
if (ctx.arg.compress_debug_sections != COMPRESS_NONE) {
compress_debug_sections(ctx);
filesize = set_osec_offsets(ctx);
}
// At this point, file layout is fixed.
// Beyond this, you can assume that symbol addresses including their
// GOT or PLT addresses have a correct final value.
// Some types of relocations for TLS symbols need the TLS segment
// address. Find it out now.
for (ElfPhdr<E> phdr : create_phdr(ctx)) {
if (phdr.p_type == PT_TLS) {
ctx.tls_begin = phdr.p_vaddr;
ctx.tls_end = align_to(phdr.p_vaddr + phdr.p_memsz, phdr.p_align);
break;
}
}
t_before_copy.stop();
// Create an output file
ctx.output_file = OutputFile<E>::open(ctx, ctx.arg.output, filesize, 0777);
ctx.buf = ctx.output_file->buf;
Timer t_copy(ctx, "copy");
// Copy input sections to the output file
{
Timer t(ctx, "copy_buf");
tbb::parallel_for_each(ctx.chunks, [&](OutputChunk<E> *chunk) {
std::string name(chunk->name);
if (name.empty())
name = "(header)";
Timer t2(ctx, name, &t);
chunk->copy_buf(ctx);
});
Error<E>::checkpoint(ctx);
}
// Dynamic linker works better with sorted .rela.dyn section,
// so we sort them.
ctx.reldyn->sort(ctx);
// Zero-clear paddings between sections
clear_padding(ctx);
if (ctx.buildid) {
Timer t(ctx, "build_id");
ctx.buildid->write_buildid(ctx);
}
t_copy.stop();
// Commit
ctx.output_file->close(ctx);
t_total.stop();
t_all.stop();
if (ctx.arg.print_map)
print_map(ctx);
// Show stats numbers
if (ctx.arg.stats)
show_stats(ctx);
if (ctx.arg.perf)
Timer<E>::print(ctx);
std::cout << std::flush;
std::cerr << std::flush;
if (on_complete)
on_complete();
if (ctx.arg.quick_exit)
std::quick_exit(0);
for (std::function<void()> &fn : ctx.on_exit)
fn();
return 0;
}
enum class MachineType { X86_64, I386 };
static MachineType get_machine_type(int argc, char **argv) {
for (i64 i = 1; i < argc; i++) {
if (std::string_view(argv[i]) == "-m") {
if (i + 1 == argc)
break;
i++;
std::string_view val(argv[i]);
if (val == "elf_x86_64")
return MachineType::X86_64;
if (val == "elf_i386")
return MachineType::I386;
std::cerr << "unknown -m argument: " << val << "\n";
exit(1);
}
}
return MachineType::X86_64;
}
int main(int argc, char **argv) {
switch (get_machine_type(argc, argv)) {
case MachineType::X86_64:
return do_main<X86_64>(argc, argv);
case MachineType::I386:
return do_main<I386>(argc, argv);
}
}
#define INSTANTIATE(E) \
template void read_file(Context<E> &, MemoryMappedFile<E> *); \
template std::string_view save_string(Context<E> &, const std::string &)
INSTANTIATE(X86_64);
INSTANTIATE(I386);
-104
View File
@@ -1,104 +0,0 @@
#include "mold.h"
#include <fstream>
#include <iomanip>
#include <ios>
#include <sstream>
#include <tbb/parallel_for_each.h>
#include <unordered_map>
template <typename E>
using Map =
tbb::concurrent_hash_map<InputSection<E> *, std::vector<Symbol<E> *>>;
template <typename E>
static std::unique_ptr<std::ofstream> open_output_file(Context<E> &ctx) {
std::unique_ptr<std::ofstream> file(new std::ofstream);
file->open(ctx.arg.Map.c_str());
if (!file->is_open())
Fatal(ctx) << "cannot open " << ctx.arg.Map << ": " << strerror(errno);
return file;
}
template <typename E>
static Map<E> get_map(Context<E> &ctx) {
Map<E> map;
tbb::parallel_for_each(ctx.objs, [&](ObjectFile<E> *file) {
for (Symbol<E> *sym : file->symbols) {
if (sym->file == file && sym->input_section &&
sym->get_type() != STT_SECTION) {
assert(file == &sym->input_section->file);
typename Map<E>::accessor acc;
map.insert(acc, {sym->input_section, {}});
acc->second.push_back(sym);
}
}
});
tbb::parallel_for(map.range(), [](const typename Map<E>::range_type &range) {
for (auto it = range.begin(); it != range.end(); it++) {
std::vector<Symbol<E> *> &vec = it->second;
sort(vec, [](Symbol<E> *a, Symbol<E> *b) { return a->value < b->value; });
}
});
return map;
}
template <typename E>
void print_map(Context<E> &ctx) {
std::ostream *out = &std::cout;
std::unique_ptr<std::ofstream> file;
if (!ctx.arg.Map.empty()) {
file = open_output_file(ctx);
out = file.get();
}
// Construct a section-to-symbol map.
Map<E> map = get_map(ctx);
// Print a mapfile.
*out << " VMA Size Align Out In Symbol\n";
for (OutputChunk<E> *osec : ctx.chunks) {
*out << std::setw(16) << (u64)osec->shdr.sh_addr
<< std::setw(11) << (u64)osec->shdr.sh_size
<< std::setw(6) << (u64)osec->shdr.sh_addralign
<< " " << osec->name << "\n";
if (osec->kind != OutputChunk<E>::REGULAR)
continue;
std::span<InputSection<E> *> members = ((OutputSection<E> *)osec)->members;
std::vector<std::string> bufs(members.size());
tbb::parallel_for((i64)0, (i64)members.size(), [&](i64 i) {
InputSection<E> *mem = members[i];
std::ostringstream ss;
opt_demangle = ctx.arg.demangle;
ss << std::setw(16) << (osec->shdr.sh_addr + mem->offset)
<< std::setw(11) << (u64)mem->shdr.sh_size
<< std::setw(6) << (u64)mem->shdr.sh_addralign
<< " " << *mem << "\n";
typename Map<E>::const_accessor acc;
if (map.find(acc, mem))
for (Symbol<E> *sym : acc->second)
ss << std::setw(16) << sym->get_addr(ctx)
<< " 0 0 "
<< *sym << "\n";
bufs[i] = std::move(ss.str());
});
for (std::string &str : bufs)
*out << str;
}
}
template void print_map(Context<X86_64> &ctx);
template void print_map(Context<I386> &ctx);
-118
View File
@@ -1,118 +0,0 @@
#include "mold.h"
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
template <typename E>
MemoryMappedFile<E> *
MemoryMappedFile<E>::open(Context<E> &ctx, std::string path) {
if (path.starts_with('/') && !ctx.arg.chroot.empty())
path = ctx.arg.chroot + "/" + path_clean(path);
struct stat st;
if (stat(path.c_str(), &st) == -1)
return nullptr;
u64 mtime = (u64)st.st_mtim.tv_sec * 1000000000 + st.st_mtim.tv_nsec;
u8 *data = nullptr;
if (st.st_size == 0) {
// mmap(2) doesn't allow 0 as an argument for length parameter,
// so this case has to be handled as a special case.
static u8 dummy[1];
data = dummy;
}
MemoryMappedFile *mb = new MemoryMappedFile(path, data, st.st_size, mtime);
ctx.owning_mbs.push_back(std::unique_ptr<MemoryMappedFile>(mb));
return mb;
}
template <typename E>
MemoryMappedFile<E> *
MemoryMappedFile<E>::must_open(Context<E> &ctx, std::string path) {
if (MemoryMappedFile *mb = MemoryMappedFile::open(ctx, path))
return mb;
Fatal(ctx) << "cannot open " << path;
}
template <typename E>
u8 *MemoryMappedFile<E>::data(Context<E> &ctx) {
if (data_)
return data_;
std::lock_guard lock(mu);
if (data_)
return data_;
i64 fd = ::open(name.c_str(), O_RDONLY);
if (fd == -1)
Fatal(ctx) << name << ": cannot open: " << strerror(errno);
data_ = (u8 *)mmap(nullptr, size_, PROT_READ, MAP_PRIVATE, fd, 0);
if (data_ == MAP_FAILED)
Fatal(ctx) << name << ": mmap failed: " << strerror(errno);
close(fd);
return data_;
}
template <typename E>
MemoryMappedFile<E> *
MemoryMappedFile<E>::slice(Context<E> &ctx, std::string name, u64 start,
u64 size) {
MemoryMappedFile *mb = new MemoryMappedFile<E>(name, data_ + start, size);
ctx.owning_mbs.push_back(std::unique_ptr<MemoryMappedFile>(mb));
mb->parent = this;
return mb;
}
template <typename E>
MemoryMappedFile<E>::~MemoryMappedFile() {
if (data_ && !parent)
munmap(data_, size_);
}
template <typename E>
static bool is_text_file(Context<E> &ctx, MemoryMappedFile<E> *mb) {
u8 *data = mb->data(ctx);
return mb->size() >= 4 &&
isprint(data[0]) &&
isprint(data[1]) &&
isprint(data[2]) &&
isprint(data[3]);
}
template <typename E>
FileType get_file_type(Context<E> &ctx, MemoryMappedFile<E> *mb) {
u8 *data = mb->data(ctx);
if (mb->size() >= 20 && memcmp(data, "\177ELF", 4) == 0) {
ElfEhdr<E> &ehdr = *(ElfEhdr<E> *)data;
if (ehdr.e_type == ET_REL)
return FileType::OBJ;
if (ehdr.e_type == ET_DYN)
return FileType::DSO;
return FileType::UNKNOWN;
}
if (mb->size() >= 8 && memcmp(data, "!<arch>\n", 8) == 0)
return FileType::AR;
if (mb->size() >= 8 && memcmp(data, "!<thin>\n", 8) == 0)
return FileType::THIN_AR;
if (is_text_file(ctx, mb))
return FileType::TEXT;
if (mb->size() >= 4 && memcmp(data, "\xDE\xC0\x17\x0B", 4) == 0)
return FileType::LLVM_BITCODE;
if (mb->size() >= 4 && memcmp(data, "BC\xC0\xDE", 4) == 0)
return FileType::LLVM_BITCODE;
return FileType::UNKNOWN;
}
#define INSTANTIATE(E) \
template class MemoryMappedFile<E>; \
template FileType get_file_type(Context<E> &, MemoryMappedFile<E> *)
INSTANTIATE(X86_64);
INSTANTIATE(I386);
-382
View File
@@ -1,382 +0,0 @@
cmake_minimum_required(VERSION 3.0)
project(libmimalloc C CXX)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
option(MI_SECURE "Use full security mitigations (like guard pages, allocation randomization, double-free mitigation, and free-list corruption detection)" OFF)
option(MI_DEBUG_FULL "Use full internal heap invariant checking in DEBUG mode (expensive)" OFF)
option(MI_PADDING "Enable padding to detect heap block overflow (used only in DEBUG mode)" ON)
option(MI_OVERRIDE "Override the standard malloc interface (e.g. define entry points for malloc() etc)" ON)
option(MI_XMALLOC "Enable abort() call on memory allocation failure by default" OFF)
option(MI_SHOW_ERRORS "Show error and warning messages by default (only enabled by default in DEBUG mode)" OFF)
option(MI_USE_CXX "Use the C++ compiler to compile the library (instead of the C compiler)" OFF)
option(MI_SEE_ASM "Generate assembly files" OFF)
option(MI_INTERPOSE "Use interpose to override standard malloc on macOS" ON)
option(MI_OSX_ZONE "Use malloc zone to override standard malloc on macOS" OFF) # enables interpose as well
option(MI_LOCAL_DYNAMIC_TLS "Use slightly slower, dlopen-compatible TLS mechanism (Unix)" OFF)
option(MI_BUILD_SHARED "Build shared library" ON)
option(MI_BUILD_STATIC "Build static library" ON)
option(MI_BUILD_OBJECT "Build object library" ON)
option(MI_BUILD_TESTS "Build test executables" ON)
option(MI_DEBUG_TSAN "Build with thread sanitizer (needs clang)" OFF)
option(MI_DEBUG_UBSAN "Build with undefined-behavior sanitizer (needs clang++)" OFF)
option(MI_CHECK_FULL "Use full internal invariant checking in DEBUG mode (deprecated, use MI_DEBUG_FULL instead)" OFF)
option(MI_INSTALL_TOPLEVEL "Install directly into $CMAKE_INSTALL_PREFIX instead of PREFIX/lib/mimalloc-version" OFF)
include("cmake/mimalloc-config-version.cmake")
set(mi_sources
src/stats.c
src/random.c
src/os.c
src/bitmap.c
src/arena.c
src/region.c
src/segment.c
src/page.c
src/alloc.c
src/alloc-aligned.c
src/alloc-posix.c
src/heap.c
src/options.c
src/init.c)
# -----------------------------------------------------------------------------
# Converience: set default build type depending on the build directory
# -----------------------------------------------------------------------------
if (NOT CMAKE_BUILD_TYPE)
if ("${CMAKE_BINARY_DIR}" MATCHES ".*(D|d)ebug$" OR MI_DEBUG_FULL)
message(STATUS "No build type selected, default to: Debug")
set(CMAKE_BUILD_TYPE "Debug")
else()
message(STATUS "No build type selected, default to: Release")
set(CMAKE_BUILD_TYPE "Release")
endif()
endif()
if("${CMAKE_BINARY_DIR}" MATCHES ".*(S|s)ecure$")
message(STATUS "Default to secure build")
set(MI_SECURE "ON")
endif()
# -----------------------------------------------------------------------------
# Process options
# -----------------------------------------------------------------------------
if(CMAKE_C_COMPILER_ID MATCHES "MSVC|Intel")
set(MI_USE_CXX "ON")
endif()
if(MI_OVERRIDE)
message(STATUS "Override standard malloc (MI_OVERRIDE=ON)")
if(APPLE)
if(MI_OSX_ZONE)
# use zone's on macOS
message(STATUS " Use malloc zone to override malloc (MI_OSX_ZONE=ON)")
list(APPEND mi_sources src/alloc-override-osx.c)
list(APPEND mi_defines MI_OSX_ZONE=1)
if(NOT MI_INTERPOSE)
message(STATUS " (enabling INTERPOSE as well since zone's require this)")
set(MI_INTERPOSE "ON")
endif()
endif()
if(MI_INTERPOSE)
# use interpose on macOS
message(STATUS " Use interpose to override malloc (MI_INTERPOSE=ON)")
list(APPEND mi_defines MI_INTERPOSE)
endif()
endif()
endif()
if(MI_SECURE)
message(STATUS "Set full secure build (MI_SECURE=ON)")
list(APPEND mi_defines MI_SECURE=4)
endif()
if(MI_SEE_ASM)
message(STATUS "Generate assembly listings (MI_SEE_ASM=ON)")
list(APPEND mi_cflags -save-temps)
endif()
if(MI_CHECK_FULL)
message(STATUS "The MI_CHECK_FULL option is deprecated, use MI_DEBUG_FULL instead")
set(MI_DEBUG_FULL "ON")
endif()
if(MI_DEBUG_FULL)
message(STATUS "Set debug level to full internal invariant checking (MI_DEBUG_FULL=ON)")
list(APPEND mi_defines MI_DEBUG=3) # full invariant checking
endif()
if(NOT MI_PADDING)
message(STATUS "Disable padding of heap blocks in debug mode (MI_PADDING=OFF)")
list(APPEND mi_defines MI_PADDING=0)
endif()
if(MI_XMALLOC)
message(STATUS "Enable abort() calls on memory allocation failure (MI_XMALLOC=ON)")
list(APPEND mi_defines MI_XMALLOC=1)
endif()
if(MI_SHOW_ERRORS)
message(STATUS "Enable printing of error and warning messages by default (MI_SHOW_ERRORS=ON)")
list(APPEND mi_defines MI_SHOW_ERRORS=1)
endif()
if(MI_DEBUG_TSAN)
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
message(STATUS "Build with thread sanitizer (MI_DEBUG_TSAN=ON)")
list(APPEND mi_defines MI_TSAN=1)
list(APPEND mi_cflags -fsanitize=thread -g -O1)
list(APPEND CMAKE_EXE_LINKER_FLAGS -fsanitize=thread)
else()
message(WARNING "Can only use thread sanitizer with clang (MI_DEBUG_TSAN=ON but ignored)")
endif()
endif()
if(MI_DEBUG_UBSAN)
if(CMAKE_BUILD_TYPE MATCHES "Debug")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(STATUS "Build with undefined-behavior sanitizer (MI_DEBUG_UBSAN=ON)")
list(APPEND mi_cflags -fsanitize=undefined -g)
list(APPEND CMAKE_EXE_LINKER_FLAGS -fsanitize=undefined)
if (NOT MI_USE_CXX)
message(STATUS "(switch to use C++ due to MI_DEBUG_UBSAN)")
set(MI_USE_CXX "ON")
endif()
else()
message(WARNING "Can only use undefined-behavior sanitizer with clang++ (MI_DEBUG_UBSAN=ON but ignored)")
endif()
else()
message(WARNING "Can only use thread sanitizer with a debug build (CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})")
endif()
endif()
if(MI_USE_CXX)
message(STATUS "Use the C++ compiler to compile (MI_USE_CXX=ON)")
set_source_files_properties(${mi_sources} PROPERTIES LANGUAGE CXX )
set_source_files_properties(src/static.c test/test-api.c test/test-stress PROPERTIES LANGUAGE CXX )
if(CMAKE_CXX_COMPILER_ID MATCHES "AppleClang|Clang")
list(APPEND mi_cflags -Wno-deprecated)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
list(APPEND mi_cflags -Kc++)
endif()
endif()
# Compiler flags
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU")
list(APPEND mi_cflags -Wall -Wextra -Wno-unknown-pragmas -fvisibility=hidden)
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
list(APPEND mi_cflags -Wno-invalid-memory-model)
endif()
endif()
if(CMAKE_C_COMPILER_ID MATCHES "Intel")
list(APPEND mi_cflags -Wall -fvisibility=hidden)
endif()
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU|Intel" AND NOT CMAKE_SYSTEM_NAME MATCHES "Haiku")
if(MI_LOCAL_DYNAMIC_TLS)
list(APPEND mi_cflags -ftls-model=local-dynamic)
else()
list(APPEND mi_cflags -ftls-model=initial-exec)
endif()
endif()
if (MSVC AND MSVC_VERSION GREATER_EQUAL 1914)
list(APPEND mi_cflags /Zc:__cplusplus)
endif()
# extra needed libraries
if(WIN32)
list(APPEND mi_libraries psapi shell32 user32 advapi32 bcrypt)
else()
if(NOT ${CMAKE_C_COMPILER} MATCHES "android")
list(APPEND mi_libraries pthread)
find_library(LIBRT rt)
if(LIBRT)
list(APPEND mi_libraries ${LIBRT})
endif()
endif()
endif()
# -----------------------------------------------------------------------------
# Install and output names
# -----------------------------------------------------------------------------
if (MI_INSTALL_TOPLEVEL)
set(mi_install_dir "${CMAKE_INSTALL_PREFIX}")
else()
set(mi_install_dir "${CMAKE_INSTALL_PREFIX}/lib/mimalloc-${mi_version}")
endif()
if(MI_SECURE)
set(mi_basename "mimalloc-secure")
else()
set(mi_basename "mimalloc")
endif()
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LC)
if(NOT(CMAKE_BUILD_TYPE_LC MATCHES "^(release|relwithdebinfo|minsizerel)$"))
set(mi_basename "${mi_basename}-${CMAKE_BUILD_TYPE_LC}") #append build type (e.g. -debug) if not a release version
endif()
if(MI_BUILD_SHARED)
list(APPEND mi_build_targets "shared")
endif()
if(MI_BUILD_STATIC)
list(APPEND mi_build_targets "static")
endif()
if(MI_BUILD_OBJECT)
list(APPEND mi_build_targets "object")
endif()
if(MI_BUILD_TESTS)
list(APPEND mi_build_targets "tests")
endif()
message(STATUS "")
message(STATUS "Library base name: ${mi_basename}")
message(STATUS "Build type : ${CMAKE_BUILD_TYPE_LC}")
if(MI_USE_CXX)
message(STATUS "Compiler : ${CMAKE_CXX_COMPILER}")
else()
message(STATUS "Compiler : ${CMAKE_C_COMPILER}")
endif()
message(STATUS "Install directory: ${mi_install_dir}")
message(STATUS "Build targets : ${mi_build_targets}")
message(STATUS "")
# -----------------------------------------------------------------------------
# Main targets
# -----------------------------------------------------------------------------
# shared library
if(MI_BUILD_SHARED)
add_library(mimalloc SHARED ${mi_sources})
set_target_properties(mimalloc PROPERTIES VERSION ${mi_version} OUTPUT_NAME ${mi_basename} )
target_compile_definitions(mimalloc PRIVATE ${mi_defines} MI_SHARED_LIB MI_SHARED_LIB_EXPORT)
target_compile_options(mimalloc PRIVATE ${mi_cflags})
target_link_libraries(mimalloc PUBLIC ${mi_libraries})
target_include_directories(mimalloc PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${mi_install_dir}/include>
)
if(WIN32)
# On windows copy the mimalloc redirection dll too.
target_link_libraries(mimalloc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/bin/mimalloc-redirect.lib)
add_custom_command(TARGET mimalloc POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/bin/mimalloc-redirect.dll" $<TARGET_FILE_DIR:mimalloc>
COMMENT "Copy mimalloc-redirect.dll to output directory")
endif()
if (MI_INSTALL_TOPLEVEL MATCHES "ON")
install(TARGETS mimalloc EXPORT mimalloc LIBRARY
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
else()
install(TARGETS mimalloc EXPORT mimalloc DESTINATION ${mi_install_dir} LIBRARY)
endif()
install(EXPORT mimalloc DESTINATION ${mi_install_dir}/cmake)
endif()
# static library
if (MI_BUILD_STATIC)
add_library(mimalloc-static STATIC ${mi_sources})
set_property(TARGET mimalloc-static PROPERTY POSITION_INDEPENDENT_CODE ON)
target_compile_definitions(mimalloc-static PRIVATE ${mi_defines} MI_STATIC_LIB)
target_compile_options(mimalloc-static PRIVATE ${mi_cflags})
target_link_libraries(mimalloc-static PUBLIC ${mi_libraries})
target_include_directories(mimalloc-static PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${mi_install_dir}/include>
)
if(WIN32)
# When building both static and shared libraries on Windows, a static library should use a
# different output name to avoid the conflict with the import library of a shared one.
string(REPLACE "mimalloc" "mimalloc-static" mi_output_name ${mi_basename})
set_target_properties(mimalloc-static PROPERTIES OUTPUT_NAME ${mi_output_name})
else()
set_target_properties(mimalloc-static PROPERTIES OUTPUT_NAME ${mi_basename})
endif()
install(TARGETS mimalloc-static EXPORT mimalloc DESTINATION ${mi_install_dir})
endif()
# install include files
install(FILES include/mimalloc.h DESTINATION ${mi_install_dir}/include)
install(FILES include/mimalloc-override.h DESTINATION ${mi_install_dir}/include)
install(FILES include/mimalloc-new-delete.h DESTINATION ${mi_install_dir}/include)
install(FILES cmake/mimalloc-config.cmake DESTINATION ${mi_install_dir}/cmake)
install(FILES cmake/mimalloc-config-version.cmake DESTINATION ${mi_install_dir}/cmake)
if(NOT WIN32 AND MI_BUILD_SHARED AND NOT MI_INSTALL_TOPLEVEL)
# install a symlink in the /usr/local/lib to the versioned library
set(mi_symlink "${CMAKE_SHARED_MODULE_PREFIX}${mi_basename}${CMAKE_SHARED_LIBRARY_SUFFIX}")
set(mi_soname "mimalloc-${mi_version}/${mi_symlink}.${mi_version}")
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${mi_soname} ${mi_symlink} WORKING_DIRECTORY ${mi_install_dir}/..)")
install(CODE "MESSAGE(\"-- Symbolic link: ${CMAKE_INSTALL_PREFIX}/lib/${mi_symlink} -> ${mi_soname}\")")
endif()
# single object file for more predictable static overriding
if (MI_BUILD_OBJECT)
add_library(mimalloc-obj OBJECT src/static.c)
set_property(TARGET mimalloc-obj PROPERTY POSITION_INDEPENDENT_CODE ON)
target_compile_definitions(mimalloc-obj PRIVATE ${mi_defines})
target_compile_options(mimalloc-obj PRIVATE ${mi_cflags})
target_include_directories(mimalloc-obj PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${mi_install_dir}/include>
)
# the following seems to lead to cmake warnings/errors on some systems, disable for now :-(
# install(TARGETS mimalloc-obj EXPORT mimalloc DESTINATION ${mi_install_dir})
# the FILES expression can also be: $<TARGET_OBJECTS:mimalloc-obj>
# but that fails cmake versions less than 3.10 so we leave it as is for now
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/mimalloc-obj.dir/src/static.c${CMAKE_C_OUTPUT_EXTENSION}
DESTINATION ${mi_install_dir}
RENAME ${mi_basename}${CMAKE_C_OUTPUT_EXTENSION} )
endif()
# -----------------------------------------------------------------------------
# API surface testing
# -----------------------------------------------------------------------------
if (MI_BUILD_TESTS)
add_executable(mimalloc-test-api test/test-api.c)
target_compile_definitions(mimalloc-test-api PRIVATE ${mi_defines})
target_compile_options(mimalloc-test-api PRIVATE ${mi_cflags})
target_include_directories(mimalloc-test-api PRIVATE include)
target_link_libraries(mimalloc-test-api PRIVATE mimalloc-static ${mi_libraries})
add_executable(mimalloc-test-stress test/test-stress.c)
target_compile_definitions(mimalloc-test-stress PRIVATE ${mi_defines})
target_compile_options(mimalloc-test-stress PRIVATE ${mi_cflags})
target_include_directories(mimalloc-test-stress PRIVATE include)
target_link_libraries(mimalloc-test-stress PRIVATE mimalloc ${mi_libraries})
enable_testing()
add_test(test_api, mimalloc-test-api)
add_test(test_stress, mimalloc-test-stress)
endif()
# -----------------------------------------------------------------------------
# Set override properties
# -----------------------------------------------------------------------------
if (MI_OVERRIDE)
if (MI_BUILD_SHARED)
target_compile_definitions(mimalloc PRIVATE MI_MALLOC_OVERRIDE)
endif()
if(NOT WIN32)
# It is only possible to override malloc on Windows when building as a DLL.
if (MI_BUILD_STATIC)
target_compile_definitions(mimalloc-static PRIVATE MI_MALLOC_OVERRIDE)
endif()
if (MI_BUILD_OBJECT)
target_compile_definitions(mimalloc-obj PRIVATE MI_MALLOC_OVERRIDE)
endif()
endif()
endif()
-174
View File
@@ -1,174 +0,0 @@
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
branches:
include:
- master
- dev
- dev-slice
tags:
include:
- v*
jobs:
- job:
displayName: Windows
pool:
vmImage:
windows-2019
strategy:
matrix:
Debug:
BuildType: debug
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON
MSBuildConfiguration: Debug
Release:
BuildType: release
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release
MSBuildConfiguration: Release
Secure:
BuildType: secure
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -DMI_SECURE=ON
MSBuildConfiguration: Release
steps:
- task: CMake@1
inputs:
workingDirectory: $(BuildType)
cmakeArgs: .. $(cmakeExtraArgs)
- task: MSBuild@1
inputs:
solution: $(BuildType)/libmimalloc.sln
configuration: '$(MSBuildConfiguration)'
msbuildArguments: -m
- script: ctest --verbose --timeout 120
workingDirectory: $(BuildType)
displayName: CTest
#- script: $(BuildType)\$(BuildType)\mimalloc-test-stress
# displayName: TestStress
#- upload: $(Build.SourcesDirectory)/$(BuildType)
# artifact: mimalloc-windows-$(BuildType)
- job:
displayName: Linux
pool:
vmImage:
ubuntu-18.04
strategy:
matrix:
Debug:
CC: gcc
CXX: g++
BuildType: debug
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON
Release:
CC: gcc
CXX: g++
BuildType: release
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release
Secure:
CC: gcc
CXX: g++
BuildType: secure
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -DMI_SECURE=ON
Debug++:
CC: gcc
CXX: g++
BuildType: debug-cxx
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON -DMI_USE_CXX=ON
Debug Clang:
CC: clang
CXX: clang++
BuildType: debug-clang
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON
Release Clang:
CC: clang
CXX: clang++
BuildType: release-clang
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release
Secure Clang:
CC: clang
CXX: clang++
BuildType: secure-clang
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -DMI_SECURE=ON
Debug++ Clang:
CC: clang
CXX: clang++
BuildType: debug-clang-cxx
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON -DMI_USE_CXX=ON
steps:
- task: CMake@1
inputs:
workingDirectory: $(BuildType)
cmakeArgs: .. $(cmakeExtraArgs)
- script: make -j$(nproc) -C $(BuildType)
displayName: Make
- script: ctest --verbose --timeout 120
workingDirectory: $(BuildType)
displayName: CTest
# - upload: $(Build.SourcesDirectory)/$(BuildType)
# artifact: mimalloc-ubuntu-$(BuildType)
- job:
displayName: macOS
pool:
vmImage:
macOS-10.14
strategy:
matrix:
Debug:
BuildType: debug
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON
Release:
BuildType: release
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release
Secure:
BuildType: secure
cmakeExtraArgs: -DCMAKE_BUILD_TYPE=Release -DMI_SECURE=ON
steps:
- task: CMake@1
inputs:
workingDirectory: $(BuildType)
cmakeArgs: .. $(cmakeExtraArgs)
- script: make -j$(sysctl -n hw.ncpu) -C $(BuildType)
displayName: Make
- script: ctest --verbose --timeout 120
workingDirectory: $(BuildType)
displayName: CTest
# - upload: $(Build.SourcesDirectory)/$(BuildType)
# artifact: mimalloc-macos-$(BuildType)
# - job:
# displayName: Windows-2017
# pool:
# vmImage:
# vs2017-win2016
# strategy:
# matrix:
# Debug:
# BuildType: debug
# cmakeExtraArgs: -A x64 -DCMAKE_BUILD_TYPE=Debug -DMI_DEBUG_FULL=ON
# MSBuildConfiguration: Debug
# Release:
# BuildType: release
# cmakeExtraArgs: -A x64 -DCMAKE_BUILD_TYPE=Release
# MSBuildConfiguration: Release
# Secure:
# BuildType: secure
# cmakeExtraArgs: -A x64 -DCMAKE_BUILD_TYPE=Release -DMI_SECURE=ON
# MSBuildConfiguration: Release
# steps:
# - task: CMake@1
# inputs:
# workingDirectory: $(BuildType)
# cmakeArgs: .. $(cmakeExtraArgs)
# - task: MSBuild@1
# inputs:
# solution: $(BuildType)/libmimalloc.sln
# configuration: '$(MSBuildConfiguration)'
# - script: |
# cd $(BuildType)
# ctest --verbose --timeout 120
# displayName: CTest
Binary file not shown.
Binary file not shown.
-2
View File
@@ -1,2 +0,0 @@
include(${CMAKE_CURRENT_LIST_DIR}/mimalloc.cmake)
get_filename_component(MIMALLOC_TARGET_DIR "${CMAKE_CURRENT_LIST_DIR}" PATH)
Binary file not shown.

Before

Width:  |  Height:  |  Size: 164 KiB

-122
View File
@@ -1,122 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.15"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>mi-malloc: Data Structures</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="mimalloc-doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="mimalloc-logo.svg"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">mi-malloc
&#160;<span id="projectnumber">1.6</span>
</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.15 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('annotated.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="headertitle">
<div class="title">Data Structures</div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock">Here are the data structures with brief descriptions:</div><div class="directory">
<table class="directory">
<tr id="row_0_" class="even"><td class="entry"><span style="width:16px;display:inline-block;">&#160;</span><span class="icona"><span class="icon">C</span></span><a class="el" href="group__analysis.html#structmi__heap__area__t" target="_self">mi_heap_area_t</a></td><td class="desc">An area of heap space contains blocks of a single size </td></tr>
<tr id="row_1_"><td class="entry"><span style="width:16px;display:inline-block;">&#160;</span><span class="icona"><span class="icon">C</span></span><a class="el" href="group__cpp.html#structmi__stl__allocator" target="_self">mi_stl_allocator</a></td><td class="desc"><em>std::allocator</em> implementation for mimalloc for use in STL containers </td></tr>
</table>
</div><!-- directory -->
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.15 </li>
</ul>
</div>
</body>
</html>
-5
View File
@@ -1,5 +0,0 @@
var annotated_dup =
[
[ "mi_heap_area_t", "group__analysis.html#structmi__heap__area__t", "group__analysis_structmi__heap__area__t" ],
[ "mi_stl_allocator", "group__cpp.html#structmi__stl__allocator", null ]
];
Binary file not shown.

Before

Width:  |  Height:  |  Size: 657 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 142 B

-120
View File
@@ -1,120 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.15"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>mi-malloc: Performance</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="mimalloc-doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="mimalloc-logo.svg"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">mi-malloc
&#160;<span id="projectnumber">1.6</span>
</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.15 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('bench.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="PageDoc"><div class="header">
<div class="headertitle">
<div class="title">Performance </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>We tested <em>mimalloc</em> against many other top allocators over a wide range of benchmarks, ranging from various real world programs to synthetic benchmarks that see how the allocator behaves under more extreme circumstances.</p>
<p>In our benchmarks, <em>mimalloc</em> always outperforms all other leading allocators (<em>jemalloc</em>, <em>tcmalloc</em>, <em>Hoard</em>, etc) (Apr 2019), and usually uses less memory (up to 25% more in the worst case). A nice property is that it does <em>consistently</em> well over the wide range of benchmarks.</p>
<p>See the <a href="https://github.com/microsoft/mimalloc#Performance">Performance</a> section in the <em>mimalloc</em> repository for benchmark results, or the the technical report for detailed benchmark results. </p>
</div></div><!-- PageDoc -->
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.15 </li>
</ul>
</div>
</body>
</html>
-130
View File
@@ -1,130 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.15"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>mi-malloc: Building</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="mimalloc-doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="mimalloc-logo.svg"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">mi-malloc
&#160;<span id="projectnumber">1.6</span>
</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.15 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('build.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="PageDoc"><div class="header">
<div class="headertitle">
<div class="title">Building </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>Checkout the sources from Github: </p><div class="fragment"><div class="line">git clone https:<span class="comment">//github.com/microsoft/mimalloc</span></div></div><!-- fragment --><h2>Windows</h2>
<p>Open <code>ide/vs2019/mimalloc.sln</code> in Visual Studio 2019 and build (or <code>ide/vs2017/mimalloc.sln</code>). The <code>mimalloc</code> project builds a static library (in <code>out/msvc-x64</code>), while the <code>mimalloc-override</code> project builds a DLL for overriding malloc in the entire program.</p>
<h2>macOS, Linux, BSD, etc.</h2>
<p>We use <a href="https://cmake.org"><code>cmake</code></a><sup>1</sup> as the build system:</p>
<div class="fragment"><div class="line">&gt; mkdir -p out/release</div><div class="line">&gt; cd out/release</div><div class="line">&gt; cmake ../..</div><div class="line">&gt; make</div></div><!-- fragment --><p> This builds the library as a shared (dynamic) library (<code>.so</code> or <code>.dylib</code>), a static library (<code>.a</code>), and as a single object file (<code>.o</code>).</p>
<p><code>&gt; sudo make install</code> (install the library and header files in <code>/usr/local/lib</code> and <code>/usr/local/include</code>)</p>
<p>You can build the debug version which does many internal checks and maintains detailed statistics as:</p>
<div class="fragment"><div class="line">&gt; mkdir -p out/debug</div><div class="line">&gt; cd out/debug</div><div class="line">&gt; cmake -DCMAKE_BUILD_TYPE=Debug ../..</div><div class="line">&gt; make</div></div><!-- fragment --><p> This will name the shared library as <code>libmimalloc-debug.so</code>.</p>
<p>Finally, you can build a <em>secure</em> version that uses guard pages, encrypted free lists, etc, as: </p><div class="fragment"><div class="line">&gt; mkdir -p out/secure</div><div class="line">&gt; cd out/secure</div><div class="line">&gt; cmake -DMI_SECURE=ON ../..</div><div class="line">&gt; make</div></div><!-- fragment --><p> This will name the shared library as <code>libmimalloc-secure.so</code>. Use <code>ccmake</code><sup>2</sup> instead of <code>cmake</code> to see and customize all the available build options.</p>
<p>Notes:</p><ol type="1">
<li>Install CMake: <code>sudo apt-get install cmake</code></li>
<li>Install CCMake: <code>sudo apt-get install cmake-curses-gui</code> </li>
</ol>
</div></div><!-- PageDoc -->
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.15 </li>
</ul>
</div>
</body>
</html>
-125
View File
@@ -1,125 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.15"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>mi-malloc: Data Structure Index</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="mimalloc-doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="mimalloc-logo.svg"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">mi-malloc
&#160;<span id="projectnumber">1.6</span>
</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.15 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('classes.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="headertitle">
<div class="title">Data Structure Index</div> </div>
</div><!--header-->
<div class="contents">
<div class="qindex"><a class="qindex" href="#letter_m">m</a></div>
<table class="classindex">
<tr><td rowspan="2" valign="bottom"><a name="letter_m"></a><table border="0" cellspacing="0" cellpadding="0"><tr><td><div class="ah">&#160;&#160;m&#160;&#160;</div></td></tr></table>
</td><td valign="top"><a class="el" href="group__cpp.html#structmi__stl__allocator">mi_stl_allocator</a>&#160;&#160;&#160;</td><td></td></tr>
<tr><td></td><td></td><td></td></tr>
<tr><td valign="top"><a class="el" href="group__analysis.html#structmi__heap__area__t">mi_heap_area_t</a>&#160;&#160;&#160;</td><td></td><td></td></tr>
<tr><td></td><td></td><td></td></tr>
</table>
<div class="qindex"><a class="qindex" href="#letter_m">m</a></div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.15 </li>
</ul>
</div>
</body>
</html>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 133 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 858 B

File diff suppressed because it is too large. Load diff
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

-120
View File
@@ -1,120 +0,0 @@
/*
@licstart The following is the entire license notice for the
JavaScript code in this file.
Copyright (C) 1997-2017 by Dimitri van Heesch
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
@licend The above is the entire license notice
for the JavaScript code in this file
*/
function toggleVisibility(linkObj)
{
var base = $(linkObj).attr('id');
var summary = $('#'+base+'-summary');
var content = $('#'+base+'-content');
var trigger = $('#'+base+'-trigger');
var src=$(trigger).attr('src');
if (content.is(':visible')===true) {
content.hide();
summary.show();
$(linkObj).addClass('closed').removeClass('opened');
$(trigger).attr('src',src.substring(0,src.length-8)+'closed.png');
} else {
content.show();
summary.hide();
$(linkObj).removeClass('closed').addClass('opened');
$(trigger).attr('src',src.substring(0,src.length-10)+'open.png');
}
return false;
}
function updateStripes()
{
$('table.directory tr').
removeClass('even').filter(':visible:even').addClass('even');
}
function toggleLevel(level)
{
$('table.directory tr').each(function() {
var l = this.id.split('_').length-1;
var i = $('#img'+this.id.substring(3));
var a = $('#arr'+this.id.substring(3));
if (l<level+1) {
i.removeClass('iconfopen iconfclosed').addClass('iconfopen');
a.html('&#9660;');
$(this).show();
} else if (l==level+1) {
i.removeClass('iconfclosed iconfopen').addClass('iconfclosed');
a.html('&#9658;');
$(this).show();
} else {
$(this).hide();
}
});
updateStripes();
}
function toggleFolder(id)
{
// the clicked row
var currentRow = $('#row_'+id);
// all rows after the clicked row
var rows = currentRow.nextAll("tr");
var re = new RegExp('^row_'+id+'\\d+_$', "i"); //only one sub
// only match elements AFTER this one (can't hide elements before)
var childRows = rows.filter(function() { return this.id.match(re); });
// first row is visible we are HIDING
if (childRows.filter(':first').is(':visible')===true) {
// replace down arrow by right arrow for current row
var currentRowSpans = currentRow.find("span");
currentRowSpans.filter(".iconfopen").removeClass("iconfopen").addClass("iconfclosed");
currentRowSpans.filter(".arrow").html('&#9658;');
rows.filter("[id^=row_"+id+"]").hide(); // hide all children
} else { // we are SHOWING
// replace right arrow by down arrow for current row
var currentRowSpans = currentRow.find("span");
currentRowSpans.filter(".iconfclosed").removeClass("iconfclosed").addClass("iconfopen");
currentRowSpans.filter(".arrow").html('&#9660;');
// replace down arrows by right arrows for child rows
var childRowsSpans = childRows.find("span");
childRowsSpans.filter(".iconfopen").removeClass("iconfopen").addClass("iconfclosed");
childRowsSpans.filter(".arrow").html('&#9658;');
childRows.show(); //show all children
}
updateStripes();
}
function toggleInherit(id)
{
var rows = $('tr.inherit.'+id);
var img = $('tr.inherit_header.'+id+' img');
var src = $(img).attr('src');
if (rows.filter(':first').is(':visible')===true) {
rows.css('display','none');
$(img).attr('src',src.substring(0,src.length-8)+'closed.png');
} else {
rows.css('display','table-row'); // using show() causes jump in firefox
$(img).attr('src',src.substring(0,src.length-10)+'open.png');
}
}
/* @license-end */
-127
View File
@@ -1,127 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.15"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>mi-malloc: Environment Options</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="mimalloc-doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="mimalloc-logo.svg"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">mi-malloc
&#160;<span id="projectnumber">1.6</span>
</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.15 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('environment.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="PageDoc"><div class="header">
<div class="headertitle">
<div class="title">Environment Options </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>You can set further options either programmatically (using <a href="https://microsoft.github.io/mimalloc/group__options.html"><code>mi_option_set</code></a>), or via environment variables.</p>
<ul>
<li><code>MIMALLOC_SHOW_STATS=1</code>: show statistics when the program terminates.</li>
<li><code>MIMALLOC_VERBOSE=1</code>: show verbose messages.</li>
<li><code>MIMALLOC_SHOW_ERRORS=1</code>: show error and warning messages.</li>
<li><code>MIMALLOC_PAGE_RESET=0</code>: by default, mimalloc will reset (or purge) OS pages when not in use to signal to the OS that the underlying physical memory can be reused. This can reduce memory fragmentation in long running (server) programs. By setting it to <code>0</code> no such page resets will be done which can improve performance for programs that are not long running. As an alternative, the <code>MIMALLOC_RESET_DELAY=</code>&lt;msecs&gt; can be set higher (100ms by default) to make the page reset occur less frequently instead of turning it off completely.</li>
<li><code>MIMALLOC_LARGE_OS_PAGES=1</code>: use large OS pages (2MiB) when available; for some workloads this can significantly improve performance. Use <code>MIMALLOC_VERBOSE</code> to check if the large OS pages are enabled &ndash; usually one needs to explicitly allow large OS pages (as on <a href="https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/enable-the-lock-pages-in-memory-option-windows?view=sql-server-2017">Windows</a> and <a href="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/5/html/tuning_and_optimizing_red_hat_enterprise_linux_for_oracle_9i_and_10g_databases/sect-oracle_9i_and_10g_tuning_guide-large_memory_optimization_big_pages_and_huge_pages-configuring_huge_pages_in_red_hat_enterprise_linux_4_or_5">Linux</a>). However, sometimes the OS is very slow to reserve contiguous physical memory for large OS pages so use with care on systems that can have fragmented memory (for that reason, we generally recommend to use <code>MIMALLOC_RESERVE_HUGE_OS_PAGES</code> instead when possible).</li>
<li><code>MIMALLOC_RESERVE_HUGE_OS_PAGES=N</code>: where N is the number of 1GiB <em>huge</em> OS pages. This reserves the huge pages at startup and sometimes this can give a large (latency) performance improvement on big workloads. Usually it is better to not use <code>MIMALLOC_LARGE_OS_PAGES</code> in combination with this setting. Just like large OS pages, use with care as reserving contiguous physical memory can take a long time when memory is fragmented (but reserving the huge pages is done at startup only once). Note that we usually need to explicitly enable huge OS pages (as on <a href="https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/enable-the-lock-pages-in-memory-option-windows?view=sql-server-2017">Windows</a> and <a href="https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/5/html/tuning_and_optimizing_red_hat_enterprise_linux_for_oracle_9i_and_10g_databases/sect-oracle_9i_and_10g_tuning_guide-large_memory_optimization_big_pages_and_huge_pages-configuring_huge_pages_in_red_hat_enterprise_linux_4_or_5">Linux</a>)). With huge OS pages, it may be beneficial to set the setting <code>MIMALLOC_EAGER_COMMIT_DELAY=N</code> (<code>N</code> is 1 by default) to delay the initial <code>N</code> segments (of 4MiB) of a thread to not allocate in the huge OS pages; this prevents threads that are short lived and allocate just a little to take up space in the huge OS page area (which cannot be reset).</li>
</ul>
<p>Use caution when using <code>fork</code> in combination with either large or huge OS pages: on a fork, the OS uses copy-on-write for all pages in the original process including the huge OS pages. When any memory is now written in that area, the OS will copy the entire 1GiB huge page (or 2MiB large page) which can cause the memory usage to grow in big increments. </p>
</div></div><!-- PageDoc -->
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.15 </li>
</ul>
</div>
</body>
</html>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 617 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 687 B

-129
View File
@@ -1,129 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.15"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>mi-malloc: Data Fields</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="mimalloc-doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="mimalloc-logo.svg"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">mi-malloc
&#160;<span id="projectnumber">1.6</span>
</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.15 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('functions.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="contents">
<div class="textblock">Here is a list of all struct and union fields with links to the structures/unions they belong to:</div><ul>
<li>block_size
: <a class="el" href="group__analysis.html#a332a6c14d736a99699d5453a1cb04b41">mi_heap_area_t</a>
</li>
<li>blocks
: <a class="el" href="group__analysis.html#ae0085e6e1cf059a4eb7767e30e9991b8">mi_heap_area_t</a>
</li>
<li>committed
: <a class="el" href="group__analysis.html#ab47526df656d8837ec3e97f11b83f835">mi_heap_area_t</a>
</li>
<li>reserved
: <a class="el" href="group__analysis.html#ae848a3e6840414891035423948ca0383">mi_heap_area_t</a>
</li>
<li>used
: <a class="el" href="group__analysis.html#ab820302c5cd0df133eb8e51650a008b4">mi_heap_area_t</a>
</li>
</ul>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.15 </li>
</ul>
</div>
</body>
</html>
-129
View File
@@ -1,129 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.15"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>mi-malloc: Data Fields - Variables</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="mimalloc-doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="mimalloc-logo.svg"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">mi-malloc
&#160;<span id="projectnumber">1.6</span>
</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.15 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('functions_vars.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="contents">
&#160;<ul>
<li>block_size
: <a class="el" href="group__analysis.html#a332a6c14d736a99699d5453a1cb04b41">mi_heap_area_t</a>
</li>
<li>blocks
: <a class="el" href="group__analysis.html#ae0085e6e1cf059a4eb7767e30e9991b8">mi_heap_area_t</a>
</li>
<li>committed
: <a class="el" href="group__analysis.html#ab47526df656d8837ec3e97f11b83f835">mi_heap_area_t</a>
</li>
<li>reserved
: <a class="el" href="group__analysis.html#ae848a3e6840414891035423948ca0383">mi_heap_area_t</a>
</li>
<li>used
: <a class="el" href="group__analysis.html#ab820302c5cd0df133eb8e51650a008b4">mi_heap_area_t</a>
</li>
</ul>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.15 </li>
</ul>
</div>
</body>
</html>
-447
View File
@@ -1,447 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.15"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>mi-malloc: Aligned Allocation</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="mimalloc-doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="mimalloc-logo.svg"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">mi-malloc
&#160;<span id="projectnumber">1.6</span>
</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.15 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('group__aligned.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="summary">
<a href="#func-members">Functions</a> </div>
<div class="headertitle">
<div class="title">Aligned Allocation</div> </div>
</div><!--header-->
<div class="contents">
<p>Allocating aligned memory blocks.
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga68930196751fa2cca9e1fd0d71bade56"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__aligned.html#ga68930196751fa2cca9e1fd0d71bade56">mi_malloc_aligned</a> (size_t size, size_t alignment)</td></tr>
<tr class="memdesc:ga68930196751fa2cca9e1fd0d71bade56"><td class="mdescLeft">&#160;</td><td class="mdescRight">Allocate <em>size</em> bytes aligned by <em>alignment</em>. <a href="#ga68930196751fa2cca9e1fd0d71bade56">More...</a><br /></td></tr>
<tr class="separator:ga68930196751fa2cca9e1fd0d71bade56"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga0cadbcf5b89a7b6fb171bc8df8734819"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__aligned.html#ga0cadbcf5b89a7b6fb171bc8df8734819">mi_zalloc_aligned</a> (size_t size, size_t alignment)</td></tr>
<tr class="separator:ga0cadbcf5b89a7b6fb171bc8df8734819"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga53dddb4724042a90315b94bc268fb4c9"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__aligned.html#ga53dddb4724042a90315b94bc268fb4c9">mi_calloc_aligned</a> (size_t count, size_t size, size_t alignment)</td></tr>
<tr class="separator:ga53dddb4724042a90315b94bc268fb4c9"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga4028d1cf4aa4c87c880747044a8322ae"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__aligned.html#ga4028d1cf4aa4c87c880747044a8322ae">mi_realloc_aligned</a> (void *p, size_t newsize, size_t alignment)</td></tr>
<tr class="separator:ga4028d1cf4aa4c87c880747044a8322ae"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga5850da130c936bd77db039dcfbc8295d"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__aligned.html#ga5850da130c936bd77db039dcfbc8295d">mi_malloc_aligned_at</a> (size_t size, size_t alignment, size_t offset)</td></tr>
<tr class="memdesc:ga5850da130c936bd77db039dcfbc8295d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Allocate <em>size</em> bytes aligned by <em>alignment</em> at a specified <em>offset</em>. <a href="#ga5850da130c936bd77db039dcfbc8295d">More...</a><br /></td></tr>
<tr class="separator:ga5850da130c936bd77db039dcfbc8295d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga5f8c2353766db522565e642fafd8a3f8"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__aligned.html#ga5f8c2353766db522565e642fafd8a3f8">mi_zalloc_aligned_at</a> (size_t size, size_t alignment, size_t offset)</td></tr>
<tr class="separator:ga5f8c2353766db522565e642fafd8a3f8"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga08647c4593f3b2eef24a919a73eba3a3"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__aligned.html#ga08647c4593f3b2eef24a919a73eba3a3">mi_calloc_aligned_at</a> (size_t count, size_t size, size_t alignment, size_t offset)</td></tr>
<tr class="separator:ga08647c4593f3b2eef24a919a73eba3a3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaf66a9ae6c6f08bd6be6fb6ea771faffb"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__aligned.html#gaf66a9ae6c6f08bd6be6fb6ea771faffb">mi_realloc_aligned_at</a> (void *p, size_t newsize, size_t alignment, size_t offset)</td></tr>
<tr class="separator:gaf66a9ae6c6f08bd6be6fb6ea771faffb"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p>Allocating aligned memory blocks. </p>
<h2 class="groupheader">Function Documentation</h2>
<a id="ga53dddb4724042a90315b94bc268fb4c9"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga53dddb4724042a90315b94bc268fb4c9">&#9670;&nbsp;</a></span>mi_calloc_aligned()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void* mi_calloc_aligned </td>
<td>(</td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>count</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>size</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>alignment</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
</div>
</div>
<a id="ga08647c4593f3b2eef24a919a73eba3a3"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga08647c4593f3b2eef24a919a73eba3a3">&#9670;&nbsp;</a></span>mi_calloc_aligned_at()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void* mi_calloc_aligned_at </td>
<td>(</td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>count</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>size</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>alignment</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>offset</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
</div>
</div>
<a id="ga68930196751fa2cca9e1fd0d71bade56"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga68930196751fa2cca9e1fd0d71bade56">&#9670;&nbsp;</a></span>mi_malloc_aligned()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void* mi_malloc_aligned </td>
<td>(</td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>size</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>alignment</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Allocate <em>size</em> bytes aligned by <em>alignment</em>. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">size</td><td>number of bytes to allocate. </td></tr>
<tr><td class="paramname">alignment</td><td>the minimal alignment of the allocated memory. </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>pointer to the allocated memory or <em>NULL</em> if out of memory. The returned pointer is aligned by <em>alignment</em>, i.e. <code>(uintptr_t)p % alignment == 0</code>.</dd></dl>
<p>Returns a unique pointer if called with <em>size</em> 0. </p><dl class="section see"><dt>See also</dt><dd><a href="https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/aligned-malloc?view=vs-2017">_aligned_malloc</a> (on Windows) </dd>
<dd>
<a href="http://man.openbsd.org/reallocarray">aligned_alloc</a> (on BSD, with switched arguments!) </dd>
<dd>
<a href="https://linux.die.net/man/3/posix_memalign">posix_memalign</a> (on Posix, with switched arguments!) </dd>
<dd>
<a href="https://linux.die.net/man/3/posix_memalign">memalign</a> (on Linux, with switched arguments!) </dd></dl>
</div>
</div>
<a id="ga5850da130c936bd77db039dcfbc8295d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga5850da130c936bd77db039dcfbc8295d">&#9670;&nbsp;</a></span>mi_malloc_aligned_at()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void* mi_malloc_aligned_at </td>
<td>(</td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>size</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>alignment</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>offset</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Allocate <em>size</em> bytes aligned by <em>alignment</em> at a specified <em>offset</em>. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">size</td><td>number of bytes to allocate. </td></tr>
<tr><td class="paramname">alignment</td><td>the minimal alignment of the allocated memory at <em>offset</em>. </td></tr>
<tr><td class="paramname">offset</td><td>the offset that should be aligned. </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>pointer to the allocated memory or <em>NULL</em> if out of memory. The returned pointer is aligned by <em>alignment</em> at <em>offset</em>, i.e. <code>((uintptr_t)p + offset) % alignment == 0</code>.</dd></dl>
<p>Returns a unique pointer if called with <em>size</em> 0. </p><dl class="section see"><dt>See also</dt><dd><a href="https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/aligned-offset-malloc?view=vs-2017">_aligned_offset_malloc</a> (on Windows) </dd></dl>
</div>
</div>
<a id="ga4028d1cf4aa4c87c880747044a8322ae"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga4028d1cf4aa4c87c880747044a8322ae">&#9670;&nbsp;</a></span>mi_realloc_aligned()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void* mi_realloc_aligned </td>
<td>(</td>
<td class="paramtype">void *&#160;</td>
<td class="paramname"><em>p</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>newsize</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>alignment</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
</div>
</div>
<a id="gaf66a9ae6c6f08bd6be6fb6ea771faffb"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaf66a9ae6c6f08bd6be6fb6ea771faffb">&#9670;&nbsp;</a></span>mi_realloc_aligned_at()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void* mi_realloc_aligned_at </td>
<td>(</td>
<td class="paramtype">void *&#160;</td>
<td class="paramname"><em>p</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>newsize</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>alignment</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>offset</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
</div>
</div>
<a id="ga0cadbcf5b89a7b6fb171bc8df8734819"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga0cadbcf5b89a7b6fb171bc8df8734819">&#9670;&nbsp;</a></span>mi_zalloc_aligned()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void* mi_zalloc_aligned </td>
<td>(</td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>size</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>alignment</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
</div>
</div>
<a id="ga5f8c2353766db522565e642fafd8a3f8"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga5f8c2353766db522565e642fafd8a3f8">&#9670;&nbsp;</a></span>mi_zalloc_aligned_at()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void* mi_zalloc_aligned_at </td>
<td>(</td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>size</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>alignment</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>offset</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.15 </li>
</ul>
</div>
</body>
</html>
-11
View File
@@ -1,11 +0,0 @@
var group__aligned =
[
[ "mi_calloc_aligned", "group__aligned.html#ga53dddb4724042a90315b94bc268fb4c9", null ],
[ "mi_calloc_aligned_at", "group__aligned.html#ga08647c4593f3b2eef24a919a73eba3a3", null ],
[ "mi_malloc_aligned", "group__aligned.html#ga68930196751fa2cca9e1fd0d71bade56", null ],
[ "mi_malloc_aligned_at", "group__aligned.html#ga5850da130c936bd77db039dcfbc8295d", null ],
[ "mi_realloc_aligned", "group__aligned.html#ga4028d1cf4aa4c87c880747044a8322ae", null ],
[ "mi_realloc_aligned_at", "group__aligned.html#gaf66a9ae6c6f08bd6be6fb6ea771faffb", null ],
[ "mi_zalloc_aligned", "group__aligned.html#ga0cadbcf5b89a7b6fb171bc8df8734819", null ],
[ "mi_zalloc_aligned_at", "group__aligned.html#ga5f8c2353766db522565e642fafd8a3f8", null ]
];
-385
View File
@@ -1,385 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.15"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>mi-malloc: Heap Introspection</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="mimalloc-doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="mimalloc-logo.svg"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">mi-malloc
&#160;<span id="projectnumber">1.6</span>
</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.15 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('group__analysis.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="summary">
<a href="#nested-classes">Data Structures</a> &#124;
<a href="#typedef-members">Typedefs</a> &#124;
<a href="#func-members">Functions</a> </div>
<div class="headertitle">
<div class="title">Heap Introspection</div> </div>
</div><!--header-->
<div class="contents">
<p>Inspect the heap at runtime.
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="nested-classes"></a>
Data Structures</h2></td></tr>
<tr class="memitem:structmi__heap__area__t"><td class="memItemLeft" align="right" valign="top">struct &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__analysis.html#structmi__heap__area__t">mi_heap_area_t</a></td></tr>
<tr class="memdesc:structmi__heap__area__t"><td class="mdescLeft">&#160;</td><td class="mdescRight">An area of heap space contains blocks of a single size. <a href="group__analysis.html#structmi__heap__area__t">More...</a><br /></td></tr>
<tr class="separator:structmi__heap__area__t"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="typedef-members"></a>
Typedefs</h2></td></tr>
<tr class="memitem:gadfa01e2900f0e5d515ad5506b26f6d65"><td class="memItemLeft" align="right" valign="top">typedef bool()&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__analysis.html#gadfa01e2900f0e5d515ad5506b26f6d65">mi_block_visit_fun</a>(const <a class="el" href="group__heap.html#ga34a47cde5a5b38c29f1aa3c5e76943c2">mi_heap_t</a> *heap, const <a class="el" href="group__analysis.html#structmi__heap__area__t">mi_heap_area_t</a> *area, void *block, size_t block_size, void *arg)</td></tr>
<tr class="memdesc:gadfa01e2900f0e5d515ad5506b26f6d65"><td class="mdescLeft">&#160;</td><td class="mdescRight">Visitor function passed to <a class="el" href="group__analysis.html#ga70c46687dc6e9dc98b232b02646f8bed" title="Visit all areas and blocks in a heap.">mi_heap_visit_blocks()</a> <a href="#gadfa01e2900f0e5d515ad5506b26f6d65">More...</a><br /></td></tr>
<tr class="separator:gadfa01e2900f0e5d515ad5506b26f6d65"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:gaa862aa8ed8d57d84cae41fc1022d71af"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__analysis.html#gaa862aa8ed8d57d84cae41fc1022d71af">mi_heap_contains_block</a> (<a class="el" href="group__heap.html#ga34a47cde5a5b38c29f1aa3c5e76943c2">mi_heap_t</a> *heap, const void *p)</td></tr>
<tr class="memdesc:gaa862aa8ed8d57d84cae41fc1022d71af"><td class="mdescLeft">&#160;</td><td class="mdescRight">Does a heap contain a pointer to a previously allocated block? <a href="#gaa862aa8ed8d57d84cae41fc1022d71af">More...</a><br /></td></tr>
<tr class="separator:gaa862aa8ed8d57d84cae41fc1022d71af"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga0d67c1789faaa15ff366c024fcaf6377"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__analysis.html#ga0d67c1789faaa15ff366c024fcaf6377">mi_heap_check_owned</a> (<a class="el" href="group__heap.html#ga34a47cde5a5b38c29f1aa3c5e76943c2">mi_heap_t</a> *heap, const void *p)</td></tr>
<tr class="memdesc:ga0d67c1789faaa15ff366c024fcaf6377"><td class="mdescLeft">&#160;</td><td class="mdescRight">Check safely if any pointer is part of a heap. <a href="#ga0d67c1789faaa15ff366c024fcaf6377">More...</a><br /></td></tr>
<tr class="separator:ga0d67c1789faaa15ff366c024fcaf6377"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga628c237489c2679af84a4d0d143b3dd5"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__analysis.html#ga628c237489c2679af84a4d0d143b3dd5">mi_check_owned</a> (const void *p)</td></tr>
<tr class="memdesc:ga628c237489c2679af84a4d0d143b3dd5"><td class="mdescLeft">&#160;</td><td class="mdescRight">Check safely if any pointer is part of the default heap of this thread. <a href="#ga628c237489c2679af84a4d0d143b3dd5">More...</a><br /></td></tr>
<tr class="separator:ga628c237489c2679af84a4d0d143b3dd5"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga70c46687dc6e9dc98b232b02646f8bed"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__analysis.html#ga70c46687dc6e9dc98b232b02646f8bed">mi_heap_visit_blocks</a> (const <a class="el" href="group__heap.html#ga34a47cde5a5b38c29f1aa3c5e76943c2">mi_heap_t</a> *heap, bool visit_all_blocks, <a class="el" href="group__analysis.html#gadfa01e2900f0e5d515ad5506b26f6d65">mi_block_visit_fun</a> *visitor, void *arg)</td></tr>
<tr class="memdesc:ga70c46687dc6e9dc98b232b02646f8bed"><td class="mdescLeft">&#160;</td><td class="mdescRight">Visit all areas and blocks in a heap. <a href="#ga70c46687dc6e9dc98b232b02646f8bed">More...</a><br /></td></tr>
<tr class="separator:ga70c46687dc6e9dc98b232b02646f8bed"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p>Inspect the heap at runtime. </p>
<hr/><h2 class="groupheader">Data Structure Documentation</h2>
<a name="structmi__heap__area__t" id="structmi__heap__area__t"></a>
<h2 class="memtitle"><span class="permalink"><a href="#structmi__heap__area__t">&#9670;&nbsp;</a></span>mi_heap_area_t</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">struct mi_heap_area_t</td>
</tr>
</table>
</div><div class="memdoc">
<div class="textblock"><p>An area of heap space contains blocks of a single size. </p>
<p>The bytes in freed blocks are <code>committed - used</code>. </p>
</div><table class="fieldtable">
<tr><th colspan="3">Data Fields</th></tr>
<tr><td class="fieldtype">
<a id="a332a6c14d736a99699d5453a1cb04b41"></a>size_t</td>
<td class="fieldname">
block_size</td>
<td class="fielddoc">
size in bytes of one block </td></tr>
<tr><td class="fieldtype">
<a id="ae0085e6e1cf059a4eb7767e30e9991b8"></a>void *</td>
<td class="fieldname">
blocks</td>
<td class="fielddoc">
start of the area containing heap blocks </td></tr>
<tr><td class="fieldtype">
<a id="ab47526df656d8837ec3e97f11b83f835"></a>size_t</td>
<td class="fieldname">
committed</td>
<td class="fielddoc">
current committed bytes of this area </td></tr>
<tr><td class="fieldtype">
<a id="ae848a3e6840414891035423948ca0383"></a>size_t</td>
<td class="fieldname">
reserved</td>
<td class="fielddoc">
bytes reserved for this area </td></tr>
<tr><td class="fieldtype">
<a id="ab820302c5cd0df133eb8e51650a008b4"></a>size_t</td>
<td class="fieldname">
used</td>
<td class="fielddoc">
bytes in use by allocated blocks </td></tr>
</table>
</div>
</div>
<h2 class="groupheader">Typedef Documentation</h2>
<a id="gadfa01e2900f0e5d515ad5506b26f6d65"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gadfa01e2900f0e5d515ad5506b26f6d65">&#9670;&nbsp;</a></span>mi_block_visit_fun</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">typedef bool() mi_block_visit_fun(const <a class="el" href="group__heap.html#ga34a47cde5a5b38c29f1aa3c5e76943c2">mi_heap_t</a> *heap, const <a class="el" href="group__analysis.html#structmi__heap__area__t">mi_heap_area_t</a> *area, void *block, size_t block_size, void *arg)</td>
</tr>
</table>
</div><div class="memdoc">
<p>Visitor function passed to <a class="el" href="group__analysis.html#ga70c46687dc6e9dc98b232b02646f8bed" title="Visit all areas and blocks in a heap.">mi_heap_visit_blocks()</a> </p>
<dl class="section return"><dt>Returns</dt><dd><em>true</em> if ok, <em>false</em> to stop visiting (i.e. break)</dd></dl>
<p>This function is always first called for every <em>area</em> with <em>block</em> as a <em>NULL</em> pointer. If <em>visit_all_blocks</em> was <em>true</em>, the function is then called for every allocated block in that area. </p>
</div>
</div>
<h2 class="groupheader">Function Documentation</h2>
<a id="ga628c237489c2679af84a4d0d143b3dd5"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga628c237489c2679af84a4d0d143b3dd5">&#9670;&nbsp;</a></span>mi_check_owned()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">bool mi_check_owned </td>
<td>(</td>
<td class="paramtype">const void *&#160;</td>
<td class="paramname"><em>p</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Check safely if any pointer is part of the default heap of this thread. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">p</td><td>Any pointer &ndash; not required to be previously allocated by us. </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd><em>true</em> if <em>p</em> points to a block in default heap of this thread.</dd></dl>
<p>Note: expensive function, linear in the pages in the heap. </p><dl class="section see"><dt>See also</dt><dd><a class="el" href="group__analysis.html#gaa862aa8ed8d57d84cae41fc1022d71af" title="Does a heap contain a pointer to a previously allocated block?">mi_heap_contains_block()</a> </dd>
<dd>
<a class="el" href="group__heap.html#ga8db4cbb87314a989a9a187464d6b5e05" title="Get the default heap that is used for mi_malloc() et al.">mi_heap_get_default()</a> </dd></dl>
</div>
</div>
<a id="ga0d67c1789faaa15ff366c024fcaf6377"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga0d67c1789faaa15ff366c024fcaf6377">&#9670;&nbsp;</a></span>mi_heap_check_owned()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">bool mi_heap_check_owned </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__heap.html#ga34a47cde5a5b38c29f1aa3c5e76943c2">mi_heap_t</a> *&#160;</td>
<td class="paramname"><em>heap</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const void *&#160;</td>
<td class="paramname"><em>p</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Check safely if any pointer is part of a heap. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">heap</td><td>The heap. </td></tr>
<tr><td class="paramname">p</td><td>Any pointer &ndash; not required to be previously allocated by us. </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd><em>true</em> if <em>p</em> points to a block in <em>heap</em>.</dd></dl>
<p>Note: expensive function, linear in the pages in the heap. </p><dl class="section see"><dt>See also</dt><dd><a class="el" href="group__analysis.html#gaa862aa8ed8d57d84cae41fc1022d71af" title="Does a heap contain a pointer to a previously allocated block?">mi_heap_contains_block()</a> </dd>
<dd>
<a class="el" href="group__heap.html#ga8db4cbb87314a989a9a187464d6b5e05" title="Get the default heap that is used for mi_malloc() et al.">mi_heap_get_default()</a> </dd></dl>
</div>
</div>
<a id="gaa862aa8ed8d57d84cae41fc1022d71af"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaa862aa8ed8d57d84cae41fc1022d71af">&#9670;&nbsp;</a></span>mi_heap_contains_block()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">bool mi_heap_contains_block </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__heap.html#ga34a47cde5a5b38c29f1aa3c5e76943c2">mi_heap_t</a> *&#160;</td>
<td class="paramname"><em>heap</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const void *&#160;</td>
<td class="paramname"><em>p</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Does a heap contain a pointer to a previously allocated block? </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">heap</td><td>The heap. </td></tr>
<tr><td class="paramname">p</td><td>Pointer to a previously allocated block (in any heap)&ndash; cannot be some random pointer! </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd><em>true</em> if the block pointed to by <em>p</em> is in the <em>heap</em>. </dd></dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="group__analysis.html#ga0d67c1789faaa15ff366c024fcaf6377" title="Check safely if any pointer is part of a heap.">mi_heap_check_owned()</a> </dd></dl>
</div>
</div>
<a id="ga70c46687dc6e9dc98b232b02646f8bed"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga70c46687dc6e9dc98b232b02646f8bed">&#9670;&nbsp;</a></span>mi_heap_visit_blocks()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">bool mi_heap_visit_blocks </td>
<td>(</td>
<td class="paramtype">const <a class="el" href="group__heap.html#ga34a47cde5a5b38c29f1aa3c5e76943c2">mi_heap_t</a> *&#160;</td>
<td class="paramname"><em>heap</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">bool&#160;</td>
<td class="paramname"><em>visit_all_blocks</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype"><a class="el" href="group__analysis.html#gadfa01e2900f0e5d515ad5506b26f6d65">mi_block_visit_fun</a> *&#160;</td>
<td class="paramname"><em>visitor</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">void *&#160;</td>
<td class="paramname"><em>arg</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Visit all areas and blocks in a heap. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">heap</td><td>The heap to visit. </td></tr>
<tr><td class="paramname">visit_all_blocks</td><td>If <em>true</em> visits all allocated blocks, otherwise <em>visitor</em> is only called for every heap area. </td></tr>
<tr><td class="paramname">visitor</td><td>This function is called for every area in the heap (with <em>block</em> as <em>NULL</em>). If <em>visit_all_blocks</em> is <em>true</em>, <em>visitor</em> is also called for every allocated block in every area (with <code>block!=NULL</code>). return <em>false</em> from this function to stop visiting early. </td></tr>
<tr><td class="paramname">arg</td><td>Extra argument passed to <em>visitor</em>. </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd><em>true</em> if all areas and blocks were visited. </dd></dl>
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.15 </li>
</ul>
</div>
</body>
</html>
-15
View File
@@ -1,15 +0,0 @@
var group__analysis =
[
[ "mi_heap_area_t", "group__analysis.html#structmi__heap__area__t", [
[ "block_size", "group__analysis.html#a332a6c14d736a99699d5453a1cb04b41", null ],
[ "blocks", "group__analysis.html#ae0085e6e1cf059a4eb7767e30e9991b8", null ],
[ "committed", "group__analysis.html#ab47526df656d8837ec3e97f11b83f835", null ],
[ "reserved", "group__analysis.html#ae848a3e6840414891035423948ca0383", null ],
[ "used", "group__analysis.html#ab820302c5cd0df133eb8e51650a008b4", null ]
] ],
[ "mi_block_visit_fun", "group__analysis.html#gadfa01e2900f0e5d515ad5506b26f6d65", null ],
[ "mi_check_owned", "group__analysis.html#ga628c237489c2679af84a4d0d143b3dd5", null ],
[ "mi_heap_check_owned", "group__analysis.html#ga0d67c1789faaa15ff366c024fcaf6377", null ],
[ "mi_heap_contains_block", "group__analysis.html#gaa862aa8ed8d57d84cae41fc1022d71af", null ],
[ "mi_heap_visit_blocks", "group__analysis.html#ga70c46687dc6e9dc98b232b02646f8bed", null ]
];
@@ -1,8 +0,0 @@
var group__analysis_structmi__heap__area__t =
[
[ "block_size", "group__analysis.html#a332a6c14d736a99699d5453a1cb04b41", null ],
[ "blocks", "group__analysis.html#ae0085e6e1cf059a4eb7767e30e9991b8", null ],
[ "committed", "group__analysis.html#ab47526df656d8837ec3e97f11b83f835", null ],
[ "reserved", "group__analysis.html#ae848a3e6840414891035423948ca0383", null ],
[ "used", "group__analysis.html#ab820302c5cd0df133eb8e51650a008b4", null ]
];
-396
View File
@@ -1,396 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.15"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>mi-malloc: C++ wrappers</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="mimalloc-doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="mimalloc-logo.svg"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">mi-malloc
&#160;<span id="projectnumber">1.6</span>
</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.15 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('group__cpp.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="summary">
<a href="#nested-classes">Data Structures</a> &#124;
<a href="#func-members">Functions</a> </div>
<div class="headertitle">
<div class="title">C++ wrappers</div> </div>
</div><!--header-->
<div class="contents">
<p><code>mi_</code> prefixed implementations of various allocation functions that use C++ semantics on out-of-memory, generally calling <code>std::get_new_handler</code> and raising a <code>std::bad_alloc</code> exception on failure.
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="nested-classes"></a>
Data Structures</h2></td></tr>
<tr class="memitem:structmi__stl__allocator"><td class="memItemLeft" align="right" valign="top">struct &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__cpp.html#structmi__stl__allocator">mi_stl_allocator&lt; T &gt;</a></td></tr>
<tr class="memdesc:structmi__stl__allocator"><td class="mdescLeft">&#160;</td><td class="mdescRight"><em>std::allocator</em> implementation for mimalloc for use in STL containers. <a href="group__cpp.html#structmi__stl__allocator">More...</a><br /></td></tr>
<tr class="separator:structmi__stl__allocator"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:gaad048a9fce3d02c5909cd05c6ec24545"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__cpp.html#gaad048a9fce3d02c5909cd05c6ec24545">mi_new</a> (std::size_t n) noexcept(false)</td></tr>
<tr class="memdesc:gaad048a9fce3d02c5909cd05c6ec24545"><td class="mdescLeft">&#160;</td><td class="mdescRight">like <a class="el" href="group__malloc.html#ga3406e8b168bc74c8637b11571a6da83a" title="Allocate size bytes.">mi_malloc()</a>, but when out of memory, use <code>std::get_new_handler</code> and raise <code>std::bad_alloc</code> exception on failure. <a href="#gaad048a9fce3d02c5909cd05c6ec24545">More...</a><br /></td></tr>
<tr class="separator:gaad048a9fce3d02c5909cd05c6ec24545"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gae7bc4f56cd57ed3359060ff4f38bda81"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__cpp.html#gae7bc4f56cd57ed3359060ff4f38bda81">mi_new_n</a> (size_t count, size_t size) noexcept(false)</td></tr>
<tr class="memdesc:gae7bc4f56cd57ed3359060ff4f38bda81"><td class="mdescLeft">&#160;</td><td class="mdescRight">like <a class="el" href="group__malloc.html#ga0b05e2bf0f73e7401ae08597ff782ac6" title="Allocate count elements of size bytes.">mi_mallocn()</a>, but when out of memory, use <code>std::get_new_handler</code> and raise <code>std::bad_alloc</code> exception on failure. <a href="#gae7bc4f56cd57ed3359060ff4f38bda81">More...</a><br /></td></tr>
<tr class="separator:gae7bc4f56cd57ed3359060ff4f38bda81"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaef2c2bdb4f70857902d3c8903ac095f3"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__cpp.html#gaef2c2bdb4f70857902d3c8903ac095f3">mi_new_aligned</a> (std::size_t n, std::align_val_t alignment) noexcept(false)</td></tr>
<tr class="memdesc:gaef2c2bdb4f70857902d3c8903ac095f3"><td class="mdescLeft">&#160;</td><td class="mdescRight">like <a class="el" href="group__aligned.html#ga68930196751fa2cca9e1fd0d71bade56" title="Allocate size bytes aligned by alignment.">mi_malloc_aligned()</a>, but when out of memory, use <code>std::get_new_handler</code> and raise <code>std::bad_alloc</code> exception on failure. <a href="#gaef2c2bdb4f70857902d3c8903ac095f3">More...</a><br /></td></tr>
<tr class="separator:gaef2c2bdb4f70857902d3c8903ac095f3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaeaded64eda71ed6b1d569d3e723abc4a"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__cpp.html#gaeaded64eda71ed6b1d569d3e723abc4a">mi_new_nothrow</a> (size_t n)</td></tr>
<tr class="memdesc:gaeaded64eda71ed6b1d569d3e723abc4a"><td class="mdescLeft">&#160;</td><td class="mdescRight">like <code>mi_malloc</code>, but when out of memory, use <code>std::get_new_handler</code> but return <em>NULL</em> on failure. <a href="#gaeaded64eda71ed6b1d569d3e723abc4a">More...</a><br /></td></tr>
<tr class="separator:gaeaded64eda71ed6b1d569d3e723abc4a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gab5e29558926d934c3f1cae8c815f942c"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__cpp.html#gab5e29558926d934c3f1cae8c815f942c">mi_new_aligned_nothrow</a> (size_t n, size_t alignment)</td></tr>
<tr class="memdesc:gab5e29558926d934c3f1cae8c815f942c"><td class="mdescLeft">&#160;</td><td class="mdescRight">like <code>mi_malloc_aligned</code>, but when out of memory, use <code>std::get_new_handler</code> but return <em>NULL</em> on failure. <a href="#gab5e29558926d934c3f1cae8c815f942c">More...</a><br /></td></tr>
<tr class="separator:gab5e29558926d934c3f1cae8c815f942c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaab78a32f55149e9fbf432d5288e38e1e"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__cpp.html#gaab78a32f55149e9fbf432d5288e38e1e">mi_new_realloc</a> (void *p, size_t newsize)</td></tr>
<tr class="memdesc:gaab78a32f55149e9fbf432d5288e38e1e"><td class="mdescLeft">&#160;</td><td class="mdescRight">like <a class="el" href="group__malloc.html#gaf11eb497da57bdfb2de65eb191c69db6" title="Re-allocate memory to newsize bytes.">mi_realloc()</a>, but when out of memory, use <code>std::get_new_handler</code> and raise <code>std::bad_alloc</code> exception on failure. <a href="#gaab78a32f55149e9fbf432d5288e38e1e">More...</a><br /></td></tr>
<tr class="separator:gaab78a32f55149e9fbf432d5288e38e1e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga756f4b2bc6a7ecd0a90baea8e90c7907"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__cpp.html#ga756f4b2bc6a7ecd0a90baea8e90c7907">mi_new_reallocn</a> (void *p, size_t newcount, size_t size)</td></tr>
<tr class="memdesc:ga756f4b2bc6a7ecd0a90baea8e90c7907"><td class="mdescLeft">&#160;</td><td class="mdescRight">like <a class="el" href="group__malloc.html#ga61d57b4144ba24fba5c1e9b956d13853" title="Re-allocate memory to count elements of size bytes.">mi_reallocn()</a>, but when out of memory, use <code>std::get_new_handler</code> and raise <code>std::bad_alloc</code> exception on failure. <a href="#ga756f4b2bc6a7ecd0a90baea8e90c7907">More...</a><br /></td></tr>
<tr class="separator:ga756f4b2bc6a7ecd0a90baea8e90c7907"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p><code>mi_</code> prefixed implementations of various allocation functions that use C++ semantics on out-of-memory, generally calling <code>std::get_new_handler</code> and raising a <code>std::bad_alloc</code> exception on failure. </p>
<p>Note: use the <code>mimalloc-new-delete.h</code> header to override the <em>new</em> and <em>delete</em> operators globally. The wrappers here are mostly for convience for library writers that need to interface with mimalloc from C++. </p>
<hr/><h2 class="groupheader">Data Structure Documentation</h2>
<a name="structmi__stl__allocator" id="structmi__stl__allocator"></a>
<h2 class="memtitle"><span class="permalink"><a href="#structmi__stl__allocator">&#9670;&nbsp;</a></span>mi_stl_allocator</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">struct mi_stl_allocator</td>
</tr>
</table>
</div><div class="memdoc">
<div class="textblock"><h3>template&lt;class T&gt;<br />
struct mi_stl_allocator&lt; T &gt;</h3>
<p><em>std::allocator</em> implementation for mimalloc for use in STL containers. </p>
<p>For example: </p><div class="fragment"><div class="line">std::vector&lt;int, mi_stl_allocator&lt;int&gt; &gt; vec;</div><div class="line">vec.push_back(1);</div><div class="line">vec.pop_back();</div></div><!-- fragment --> </div>
</div>
</div>
<h2 class="groupheader">Function Documentation</h2>
<a id="gaad048a9fce3d02c5909cd05c6ec24545"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaad048a9fce3d02c5909cd05c6ec24545">&#9670;&nbsp;</a></span>mi_new()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">void* mi_new </td>
<td>(</td>
<td class="paramtype">std::size_t&#160;</td>
<td class="paramname"><em>n</em></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">noexcept</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>like <a class="el" href="group__malloc.html#ga3406e8b168bc74c8637b11571a6da83a" title="Allocate size bytes.">mi_malloc()</a>, but when out of memory, use <code>std::get_new_handler</code> and raise <code>std::bad_alloc</code> exception on failure. </p>
</div>
</div>
<a id="gaef2c2bdb4f70857902d3c8903ac095f3"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaef2c2bdb4f70857902d3c8903ac095f3">&#9670;&nbsp;</a></span>mi_new_aligned()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">void* mi_new_aligned </td>
<td>(</td>
<td class="paramtype">std::size_t&#160;</td>
<td class="paramname"><em>n</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">std::align_val_t&#160;</td>
<td class="paramname"><em>alignment</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">noexcept</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>like <a class="el" href="group__aligned.html#ga68930196751fa2cca9e1fd0d71bade56" title="Allocate size bytes aligned by alignment.">mi_malloc_aligned()</a>, but when out of memory, use <code>std::get_new_handler</code> and raise <code>std::bad_alloc</code> exception on failure. </p>
</div>
</div>
<a id="gab5e29558926d934c3f1cae8c815f942c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gab5e29558926d934c3f1cae8c815f942c">&#9670;&nbsp;</a></span>mi_new_aligned_nothrow()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void* mi_new_aligned_nothrow </td>
<td>(</td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>n</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>alignment</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>like <code>mi_malloc_aligned</code>, but when out of memory, use <code>std::get_new_handler</code> but return <em>NULL</em> on failure. </p>
</div>
</div>
<a id="gae7bc4f56cd57ed3359060ff4f38bda81"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gae7bc4f56cd57ed3359060ff4f38bda81">&#9670;&nbsp;</a></span>mi_new_n()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">void* mi_new_n </td>
<td>(</td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>count</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>size</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">noexcept</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>like <a class="el" href="group__malloc.html#ga0b05e2bf0f73e7401ae08597ff782ac6" title="Allocate count elements of size bytes.">mi_mallocn()</a>, but when out of memory, use <code>std::get_new_handler</code> and raise <code>std::bad_alloc</code> exception on failure. </p>
</div>
</div>
<a id="gaeaded64eda71ed6b1d569d3e723abc4a"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaeaded64eda71ed6b1d569d3e723abc4a">&#9670;&nbsp;</a></span>mi_new_nothrow()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void* mi_new_nothrow </td>
<td>(</td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>n</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>like <code>mi_malloc</code>, but when out of memory, use <code>std::get_new_handler</code> but return <em>NULL</em> on failure. </p>
</div>
</div>
<a id="gaab78a32f55149e9fbf432d5288e38e1e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaab78a32f55149e9fbf432d5288e38e1e">&#9670;&nbsp;</a></span>mi_new_realloc()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void* mi_new_realloc </td>
<td>(</td>
<td class="paramtype">void *&#160;</td>
<td class="paramname"><em>p</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>newsize</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>like <a class="el" href="group__malloc.html#gaf11eb497da57bdfb2de65eb191c69db6" title="Re-allocate memory to newsize bytes.">mi_realloc()</a>, but when out of memory, use <code>std::get_new_handler</code> and raise <code>std::bad_alloc</code> exception on failure. </p>
</div>
</div>
<a id="ga756f4b2bc6a7ecd0a90baea8e90c7907"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga756f4b2bc6a7ecd0a90baea8e90c7907">&#9670;&nbsp;</a></span>mi_new_reallocn()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void* mi_new_reallocn </td>
<td>(</td>
<td class="paramtype">void *&#160;</td>
<td class="paramname"><em>p</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>newcount</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>size</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>like <a class="el" href="group__malloc.html#ga61d57b4144ba24fba5c1e9b956d13853" title="Re-allocate memory to count elements of size bytes.">mi_reallocn()</a>, but when out of memory, use <code>std::get_new_handler</code> and raise <code>std::bad_alloc</code> exception on failure. </p>
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.15 </li>
</ul>
</div>
</body>
</html>
-11
View File
@@ -1,11 +0,0 @@
var group__cpp =
[
[ "mi_stl_allocator", "group__cpp.html#structmi__stl__allocator", null ],
[ "mi_new", "group__cpp.html#gaad048a9fce3d02c5909cd05c6ec24545", null ],
[ "mi_new_aligned", "group__cpp.html#gaef2c2bdb4f70857902d3c8903ac095f3", null ],
[ "mi_new_aligned_nothrow", "group__cpp.html#gab5e29558926d934c3f1cae8c815f942c", null ],
[ "mi_new_n", "group__cpp.html#gae7bc4f56cd57ed3359060ff4f38bda81", null ],
[ "mi_new_nothrow", "group__cpp.html#gaeaded64eda71ed6b1d569d3e723abc4a", null ],
[ "mi_new_realloc", "group__cpp.html#gaab78a32f55149e9fbf432d5288e38e1e", null ],
[ "mi_new_reallocn", "group__cpp.html#ga756f4b2bc6a7ecd0a90baea8e90c7907", null ]
];
-967
View File
@@ -1,967 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.15"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>mi-malloc: Extended Functions</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="mimalloc-doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="mimalloc-logo.svg"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">mi-malloc
&#160;<span id="projectnumber">1.6</span>
</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.15 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('group__extended.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="header">
<div class="summary">
<a href="#define-members">Macros</a> &#124;
<a href="#typedef-members">Typedefs</a> &#124;
<a href="#func-members">Functions</a> </div>
<div class="headertitle">
<div class="title">Extended Functions</div> </div>
</div><!--header-->
<div class="contents">
<p>Extended functionality.
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="define-members"></a>
Macros</h2></td></tr>
<tr class="memitem:ga1ea64283508718d9d645c38efc2f4305"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#ga1ea64283508718d9d645c38efc2f4305">MI_SMALL_SIZE_MAX</a></td></tr>
<tr class="memdesc:ga1ea64283508718d9d645c38efc2f4305"><td class="mdescLeft">&#160;</td><td class="mdescRight">Maximum size allowed for small allocations in <a class="el" href="group__extended.html#ga7136c2e55cb22c98ecf95d08d6debb99" title="Allocate a small object.">mi_malloc_small</a> and <a class="el" href="group__extended.html#ga220f29f40a44404b0061c15bc1c31152" title="Allocate a zero initialized small object.">mi_zalloc_small</a> (usually <code>128*sizeof(void*)</code> (= 1KB on 64-bit systems)) <a href="#ga1ea64283508718d9d645c38efc2f4305">More...</a><br /></td></tr>
<tr class="separator:ga1ea64283508718d9d645c38efc2f4305"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="typedef-members"></a>
Typedefs</h2></td></tr>
<tr class="memitem:ga299dae78d25ce112e384a98b7309c5be"><td class="memItemLeft" align="right" valign="top">typedef void()&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#ga299dae78d25ce112e384a98b7309c5be">mi_deferred_free_fun</a>(bool force, unsigned long long heartbeat, void *arg)</td></tr>
<tr class="memdesc:ga299dae78d25ce112e384a98b7309c5be"><td class="mdescLeft">&#160;</td><td class="mdescRight">Type of deferred free functions. <a href="#ga299dae78d25ce112e384a98b7309c5be">More...</a><br /></td></tr>
<tr class="separator:ga299dae78d25ce112e384a98b7309c5be"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gad823d23444a4b77a40f66bf075a98a0c"><td class="memItemLeft" align="right" valign="top">typedef void()&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#gad823d23444a4b77a40f66bf075a98a0c">mi_output_fun</a>(const char *msg, void *arg)</td></tr>
<tr class="memdesc:gad823d23444a4b77a40f66bf075a98a0c"><td class="mdescLeft">&#160;</td><td class="mdescRight">Type of output functions. <a href="#gad823d23444a4b77a40f66bf075a98a0c">More...</a><br /></td></tr>
<tr class="separator:gad823d23444a4b77a40f66bf075a98a0c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga251d369cda3f1c2a955c555486ed90e5"><td class="memItemLeft" align="right" valign="top">typedef void()&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#ga251d369cda3f1c2a955c555486ed90e5">mi_error_fun</a>(int err, void *arg)</td></tr>
<tr class="memdesc:ga251d369cda3f1c2a955c555486ed90e5"><td class="mdescLeft">&#160;</td><td class="mdescRight">Type of error callback functions. <a href="#ga251d369cda3f1c2a955c555486ed90e5">More...</a><br /></td></tr>
<tr class="separator:ga251d369cda3f1c2a955c555486ed90e5"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga7136c2e55cb22c98ecf95d08d6debb99"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#ga7136c2e55cb22c98ecf95d08d6debb99">mi_malloc_small</a> (size_t size)</td></tr>
<tr class="memdesc:ga7136c2e55cb22c98ecf95d08d6debb99"><td class="mdescLeft">&#160;</td><td class="mdescRight">Allocate a small object. <a href="#ga7136c2e55cb22c98ecf95d08d6debb99">More...</a><br /></td></tr>
<tr class="separator:ga7136c2e55cb22c98ecf95d08d6debb99"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga220f29f40a44404b0061c15bc1c31152"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#ga220f29f40a44404b0061c15bc1c31152">mi_zalloc_small</a> (size_t size)</td></tr>
<tr class="memdesc:ga220f29f40a44404b0061c15bc1c31152"><td class="mdescLeft">&#160;</td><td class="mdescRight">Allocate a zero initialized small object. <a href="#ga220f29f40a44404b0061c15bc1c31152">More...</a><br /></td></tr>
<tr class="separator:ga220f29f40a44404b0061c15bc1c31152"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga089c859d9eddc5f9b4bd946cd53cebee"><td class="memItemLeft" align="right" valign="top">size_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#ga089c859d9eddc5f9b4bd946cd53cebee">mi_usable_size</a> (void *p)</td></tr>
<tr class="memdesc:ga089c859d9eddc5f9b4bd946cd53cebee"><td class="mdescLeft">&#160;</td><td class="mdescRight">Return the available bytes in a memory block. <a href="#ga089c859d9eddc5f9b4bd946cd53cebee">More...</a><br /></td></tr>
<tr class="separator:ga089c859d9eddc5f9b4bd946cd53cebee"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gac057927cd06c854b45fe7847e921bd47"><td class="memItemLeft" align="right" valign="top">size_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#gac057927cd06c854b45fe7847e921bd47">mi_good_size</a> (size_t size)</td></tr>
<tr class="memdesc:gac057927cd06c854b45fe7847e921bd47"><td class="mdescLeft">&#160;</td><td class="mdescRight">Return the used allocation size. <a href="#gac057927cd06c854b45fe7847e921bd47">More...</a><br /></td></tr>
<tr class="separator:gac057927cd06c854b45fe7847e921bd47"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga421430e2226d7d468529cec457396756"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#ga421430e2226d7d468529cec457396756">mi_collect</a> (bool force)</td></tr>
<tr class="memdesc:ga421430e2226d7d468529cec457396756"><td class="mdescLeft">&#160;</td><td class="mdescRight">Eagerly free memory. <a href="#ga421430e2226d7d468529cec457396756">More...</a><br /></td></tr>
<tr class="separator:ga421430e2226d7d468529cec457396756"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga2d126e5c62d3badc35445e5d84166df2"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#ga2d126e5c62d3badc35445e5d84166df2">mi_stats_print</a> (void *out)</td></tr>
<tr class="memdesc:ga2d126e5c62d3badc35445e5d84166df2"><td class="mdescLeft">&#160;</td><td class="mdescRight">Deprecated. <a href="#ga2d126e5c62d3badc35445e5d84166df2">More...</a><br /></td></tr>
<tr class="separator:ga2d126e5c62d3badc35445e5d84166df2"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga537f13b299ddf801e49a5a94fde02c79"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#ga537f13b299ddf801e49a5a94fde02c79">mi_stats_print_out</a> (<a class="el" href="group__extended.html#gad823d23444a4b77a40f66bf075a98a0c">mi_output_fun</a> *out, void *arg)</td></tr>
<tr class="memdesc:ga537f13b299ddf801e49a5a94fde02c79"><td class="mdescLeft">&#160;</td><td class="mdescRight">Print the main statistics. <a href="#ga537f13b299ddf801e49a5a94fde02c79">More...</a><br /></td></tr>
<tr class="separator:ga537f13b299ddf801e49a5a94fde02c79"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga3bb8468b8cfcc6e2a61d98aee85c5f99"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#ga3bb8468b8cfcc6e2a61d98aee85c5f99">mi_stats_reset</a> (void)</td></tr>
<tr class="memdesc:ga3bb8468b8cfcc6e2a61d98aee85c5f99"><td class="mdescLeft">&#160;</td><td class="mdescRight">Reset statistics. <a href="#ga3bb8468b8cfcc6e2a61d98aee85c5f99">More...</a><br /></td></tr>
<tr class="separator:ga3bb8468b8cfcc6e2a61d98aee85c5f99"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga854b1de8cb067c7316286c28b2fcd3d1"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#ga854b1de8cb067c7316286c28b2fcd3d1">mi_stats_merge</a> (void)</td></tr>
<tr class="memdesc:ga854b1de8cb067c7316286c28b2fcd3d1"><td class="mdescLeft">&#160;</td><td class="mdescRight">Merge thread local statistics with the main statistics and reset. <a href="#ga854b1de8cb067c7316286c28b2fcd3d1">More...</a><br /></td></tr>
<tr class="separator:ga854b1de8cb067c7316286c28b2fcd3d1"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaf8e73efc2cbca9ebfdfb166983a04c17"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#gaf8e73efc2cbca9ebfdfb166983a04c17">mi_thread_init</a> (void)</td></tr>
<tr class="memdesc:gaf8e73efc2cbca9ebfdfb166983a04c17"><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialize mimalloc on a thread. <a href="#gaf8e73efc2cbca9ebfdfb166983a04c17">More...</a><br /></td></tr>
<tr class="separator:gaf8e73efc2cbca9ebfdfb166983a04c17"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga0ae4581e85453456a0d658b2b98bf7bf"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#ga0ae4581e85453456a0d658b2b98bf7bf">mi_thread_done</a> (void)</td></tr>
<tr class="memdesc:ga0ae4581e85453456a0d658b2b98bf7bf"><td class="mdescLeft">&#160;</td><td class="mdescRight">Uninitialize mimalloc on a thread. <a href="#ga0ae4581e85453456a0d658b2b98bf7bf">More...</a><br /></td></tr>
<tr class="separator:ga0ae4581e85453456a0d658b2b98bf7bf"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gab1dac8476c46cb9eecab767eb40c1525"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#gab1dac8476c46cb9eecab767eb40c1525">mi_thread_stats_print_out</a> (<a class="el" href="group__extended.html#gad823d23444a4b77a40f66bf075a98a0c">mi_output_fun</a> *out, void *arg)</td></tr>
<tr class="memdesc:gab1dac8476c46cb9eecab767eb40c1525"><td class="mdescLeft">&#160;</td><td class="mdescRight">Print out heap statistics for this thread. <a href="#gab1dac8476c46cb9eecab767eb40c1525">More...</a><br /></td></tr>
<tr class="separator:gab1dac8476c46cb9eecab767eb40c1525"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga3460a6ca91af97be4058f523d3cb8ece"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#ga3460a6ca91af97be4058f523d3cb8ece">mi_register_deferred_free</a> (<a class="el" href="group__extended.html#ga299dae78d25ce112e384a98b7309c5be">mi_deferred_free_fun</a> *deferred_free, void *arg)</td></tr>
<tr class="memdesc:ga3460a6ca91af97be4058f523d3cb8ece"><td class="mdescLeft">&#160;</td><td class="mdescRight">Register a deferred free function. <a href="#ga3460a6ca91af97be4058f523d3cb8ece">More...</a><br /></td></tr>
<tr class="separator:ga3460a6ca91af97be4058f523d3cb8ece"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gae5b17ff027cd2150b43a33040250cf3f"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#gae5b17ff027cd2150b43a33040250cf3f">mi_register_output</a> (<a class="el" href="group__extended.html#gad823d23444a4b77a40f66bf075a98a0c">mi_output_fun</a> *out, void *arg)</td></tr>
<tr class="memdesc:gae5b17ff027cd2150b43a33040250cf3f"><td class="mdescLeft">&#160;</td><td class="mdescRight">Register an output function. <a href="#gae5b17ff027cd2150b43a33040250cf3f">More...</a><br /></td></tr>
<tr class="separator:gae5b17ff027cd2150b43a33040250cf3f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaa1d55e0e894be240827e5d87ec3a1f45"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#gaa1d55e0e894be240827e5d87ec3a1f45">mi_register_error</a> (<a class="el" href="group__extended.html#ga251d369cda3f1c2a955c555486ed90e5">mi_error_fun</a> *errfun, void *arg)</td></tr>
<tr class="memdesc:gaa1d55e0e894be240827e5d87ec3a1f45"><td class="mdescLeft">&#160;</td><td class="mdescRight">Register an error callback function. <a href="#gaa1d55e0e894be240827e5d87ec3a1f45">More...</a><br /></td></tr>
<tr class="separator:gaa1d55e0e894be240827e5d87ec3a1f45"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga5f071b10d4df1c3658e04e7fd67a94e6"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#ga5f071b10d4df1c3658e04e7fd67a94e6">mi_is_in_heap_region</a> (const void *p)</td></tr>
<tr class="memdesc:ga5f071b10d4df1c3658e04e7fd67a94e6"><td class="mdescLeft">&#160;</td><td class="mdescRight">Is a pointer part of our heap? <a href="#ga5f071b10d4df1c3658e04e7fd67a94e6">More...</a><br /></td></tr>
<tr class="separator:ga5f071b10d4df1c3658e04e7fd67a94e6"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga3132f521fb756fc0e8ec0b74fb58df50"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#ga3132f521fb756fc0e8ec0b74fb58df50">mi_reserve_huge_os_pages_interleave</a> (size_t pages, size_t numa_nodes, size_t timeout_msecs)</td></tr>
<tr class="memdesc:ga3132f521fb756fc0e8ec0b74fb58df50"><td class="mdescLeft">&#160;</td><td class="mdescRight">Reserve <em>pages</em> of huge OS pages (1GiB) evenly divided over <em>numa_nodes</em> nodes, but stops after at most <code>timeout_msecs</code> seconds. <a href="#ga3132f521fb756fc0e8ec0b74fb58df50">More...</a><br /></td></tr>
<tr class="separator:ga3132f521fb756fc0e8ec0b74fb58df50"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga7795a13d20087447281858d2c771cca1"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#ga7795a13d20087447281858d2c771cca1">mi_reserve_huge_os_pages_at</a> (size_t pages, int numa_node, size_t timeout_msecs)</td></tr>
<tr class="memdesc:ga7795a13d20087447281858d2c771cca1"><td class="mdescLeft">&#160;</td><td class="mdescRight">Reserve <em>pages</em> of huge OS pages (1GiB) at a specific <em>numa_node</em>, but stops after at most <code>timeout_msecs</code> seconds. <a href="#ga7795a13d20087447281858d2c771cca1">More...</a><br /></td></tr>
<tr class="separator:ga7795a13d20087447281858d2c771cca1"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaad25050b19f30cd79397b227e0157a3f"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#gaad25050b19f30cd79397b227e0157a3f">mi_is_redirected</a> ()</td></tr>
<tr class="memdesc:gaad25050b19f30cd79397b227e0157a3f"><td class="mdescLeft">&#160;</td><td class="mdescRight">Is the C runtime <em>malloc</em> API redirected? <a href="#gaad25050b19f30cd79397b227e0157a3f">More...</a><br /></td></tr>
<tr class="separator:gaad25050b19f30cd79397b227e0157a3f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga7d862c2affd5790381da14eb102a364d"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__extended.html#ga7d862c2affd5790381da14eb102a364d">mi_process_info</a> (size_t *elapsed_msecs, size_t *user_msecs, size_t *system_msecs, size_t *current_rss, size_t *peak_rss, size_t *current_commit, size_t *peak_commit, size_t *page_faults)</td></tr>
<tr class="memdesc:ga7d862c2affd5790381da14eb102a364d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Return process information (time and memory usage). <a href="#ga7d862c2affd5790381da14eb102a364d">More...</a><br /></td></tr>
<tr class="separator:ga7d862c2affd5790381da14eb102a364d"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p>Extended functionality. </p>
<h2 class="groupheader">Macro Definition Documentation</h2>
<a id="ga1ea64283508718d9d645c38efc2f4305"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga1ea64283508718d9d645c38efc2f4305">&#9670;&nbsp;</a></span>MI_SMALL_SIZE_MAX</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">#define MI_SMALL_SIZE_MAX</td>
</tr>
</table>
</div><div class="memdoc">
<p>Maximum size allowed for small allocations in <a class="el" href="group__extended.html#ga7136c2e55cb22c98ecf95d08d6debb99" title="Allocate a small object.">mi_malloc_small</a> and <a class="el" href="group__extended.html#ga220f29f40a44404b0061c15bc1c31152" title="Allocate a zero initialized small object.">mi_zalloc_small</a> (usually <code>128*sizeof(void*)</code> (= 1KB on 64-bit systems)) </p>
</div>
</div>
<h2 class="groupheader">Typedef Documentation</h2>
<a id="ga299dae78d25ce112e384a98b7309c5be"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga299dae78d25ce112e384a98b7309c5be">&#9670;&nbsp;</a></span>mi_deferred_free_fun</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">typedef void() mi_deferred_free_fun(bool force, unsigned long long heartbeat, void *arg)</td>
</tr>
</table>
</div><div class="memdoc">
<p>Type of deferred free functions. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">force</td><td>If <em>true</em> all outstanding items should be freed. </td></tr>
<tr><td class="paramname">heartbeat</td><td>A monotonically increasing count. </td></tr>
<tr><td class="paramname">arg</td><td>Argument that was passed at registration to hold extra state.</td></tr>
</table>
</dd>
</dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="group__extended.html#ga3460a6ca91af97be4058f523d3cb8ece" title="Register a deferred free function.">mi_register_deferred_free</a> </dd></dl>
</div>
</div>
<a id="ga251d369cda3f1c2a955c555486ed90e5"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga251d369cda3f1c2a955c555486ed90e5">&#9670;&nbsp;</a></span>mi_error_fun</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">typedef void() mi_error_fun(int err, void *arg)</td>
</tr>
</table>
</div><div class="memdoc">
<p>Type of error callback functions. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">err</td><td>Error code (see <a class="el" href="group__extended.html#gaa1d55e0e894be240827e5d87ec3a1f45" title="Register an error callback function.">mi_register_error()</a> for a complete list). </td></tr>
<tr><td class="paramname">arg</td><td>Argument that was passed at registration to hold extra state.</td></tr>
</table>
</dd>
</dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="group__extended.html#gaa1d55e0e894be240827e5d87ec3a1f45" title="Register an error callback function.">mi_register_error()</a> </dd></dl>
</div>
</div>
<a id="gad823d23444a4b77a40f66bf075a98a0c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gad823d23444a4b77a40f66bf075a98a0c">&#9670;&nbsp;</a></span>mi_output_fun</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">typedef void() mi_output_fun(const char *msg, void *arg)</td>
</tr>
</table>
</div><div class="memdoc">
<p>Type of output functions. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">msg</td><td>Message to output. </td></tr>
<tr><td class="paramname">arg</td><td>Argument that was passed at registration to hold extra state.</td></tr>
</table>
</dd>
</dl>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="group__extended.html#gae5b17ff027cd2150b43a33040250cf3f" title="Register an output function.">mi_register_output()</a> </dd></dl>
</div>
</div>
<h2 class="groupheader">Function Documentation</h2>
<a id="ga421430e2226d7d468529cec457396756"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga421430e2226d7d468529cec457396756">&#9670;&nbsp;</a></span>mi_collect()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void mi_collect </td>
<td>(</td>
<td class="paramtype">bool&#160;</td>
<td class="paramname"><em>force</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Eagerly free memory. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">force</td><td>If <em>true</em>, aggressively return memory to the OS (can be expensive!)</td></tr>
</table>
</dd>
</dl>
<p>Regular code should not have to call this function. It can be beneficial in very narrow circumstances; in particular, when a long running thread allocates a lot of blocks that are freed by other threads it may improve resource usage by calling this every once in a while. </p>
</div>
</div>
<a id="gac057927cd06c854b45fe7847e921bd47"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gac057927cd06c854b45fe7847e921bd47">&#9670;&nbsp;</a></span>mi_good_size()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">size_t mi_good_size </td>
<td>(</td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>size</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Return the used allocation size. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">size</td><td>The minimal required size in bytes. </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>the size <code>n</code> that will be allocated, where <code>n &gt;= size</code>.</dd></dl>
<p>Generally, <code>mi_usable_size(mi_malloc(size)) == mi_good_size(size)</code>. This can be used to reduce internal wasted space when allocating buffers for example.</p>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="group__extended.html#ga089c859d9eddc5f9b4bd946cd53cebee" title="Return the available bytes in a memory block.">mi_usable_size()</a> </dd></dl>
</div>
</div>
<a id="ga5f071b10d4df1c3658e04e7fd67a94e6"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga5f071b10d4df1c3658e04e7fd67a94e6">&#9670;&nbsp;</a></span>mi_is_in_heap_region()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">bool mi_is_in_heap_region </td>
<td>(</td>
<td class="paramtype">const void *&#160;</td>
<td class="paramname"><em>p</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Is a pointer part of our heap? </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">p</td><td>The pointer to check. </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd><em>true</em> if this is a pointer into our heap. This function is relatively fast. </dd></dl>
</div>
</div>
<a id="gaad25050b19f30cd79397b227e0157a3f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaad25050b19f30cd79397b227e0157a3f">&#9670;&nbsp;</a></span>mi_is_redirected()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">bool mi_is_redirected </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Is the C runtime <em>malloc</em> API redirected? </p>
<dl class="section return"><dt>Returns</dt><dd><em>true</em> if all malloc API calls are redirected to mimalloc.</dd></dl>
<p>Currenty only used on Windows. </p>
</div>
</div>
<a id="ga7136c2e55cb22c98ecf95d08d6debb99"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga7136c2e55cb22c98ecf95d08d6debb99">&#9670;&nbsp;</a></span>mi_malloc_small()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void* mi_malloc_small </td>
<td>(</td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>size</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Allocate a small object. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">size</td><td>The size in bytes, can be at most <a class="el" href="group__extended.html#ga1ea64283508718d9d645c38efc2f4305" title="Maximum size allowed for small allocations in mi_malloc_small and mi_zalloc_small (usually 128*sizeof...">MI_SMALL_SIZE_MAX</a>. </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>a pointer to newly allocated memory of at least <em>size</em> bytes, or <em>NULL</em> if out of memory. This function is meant for use in run-time systems for best performance and does not check if <em>size</em> was indeed small &ndash; use with care! </dd></dl>
</div>
</div>
<a id="ga7d862c2affd5790381da14eb102a364d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga7d862c2affd5790381da14eb102a364d">&#9670;&nbsp;</a></span>mi_process_info()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void mi_process_info </td>
<td>(</td>
<td class="paramtype">size_t *&#160;</td>
<td class="paramname"><em>elapsed_msecs</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t *&#160;</td>
<td class="paramname"><em>user_msecs</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t *&#160;</td>
<td class="paramname"><em>system_msecs</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t *&#160;</td>
<td class="paramname"><em>current_rss</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t *&#160;</td>
<td class="paramname"><em>peak_rss</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t *&#160;</td>
<td class="paramname"><em>current_commit</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t *&#160;</td>
<td class="paramname"><em>peak_commit</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t *&#160;</td>
<td class="paramname"><em>page_faults</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Return process information (time and memory usage). </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">elapsed_msecs</td><td>Optional. Elapsed wall-clock time of the process in milli-seconds. </td></tr>
<tr><td class="paramname">user_msecs</td><td>Optional. User time in milli-seconds (as the sum over all threads). </td></tr>
<tr><td class="paramname">system_msecs</td><td>Optional. System time in milli-seconds. </td></tr>
<tr><td class="paramname">current_rss</td><td>Optional. Current working set size (touched pages). </td></tr>
<tr><td class="paramname">peak_rss</td><td>Optional. Peak working set size (touched pages). </td></tr>
<tr><td class="paramname">current_commit</td><td>Optional. Current committed memory (backed by the page file). </td></tr>
<tr><td class="paramname">peak_commit</td><td>Optional. Peak committed memory (backed by the page file). </td></tr>
<tr><td class="paramname">page_faults</td><td>Optional. Count of hard page faults.</td></tr>
</table>
</dd>
</dl>
<p>The <em>current_rss</em> is precise on Windows and MacOSX; other systems estimate this using <em>current_commit</em>. The <em>commit</em> is precise on Windows but estimated on other systems as the amount of read/write accessible memory reserved by mimalloc. </p>
</div>
</div>
<a id="ga3460a6ca91af97be4058f523d3cb8ece"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga3460a6ca91af97be4058f523d3cb8ece">&#9670;&nbsp;</a></span>mi_register_deferred_free()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void mi_register_deferred_free </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__extended.html#ga299dae78d25ce112e384a98b7309c5be">mi_deferred_free_fun</a> *&#160;</td>
<td class="paramname"><em>deferred_free</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">void *&#160;</td>
<td class="paramname"><em>arg</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Register a deferred free function. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">deferred_free</td><td>Address of a deferred free-ing function or <em>NULL</em> to unregister. </td></tr>
<tr><td class="paramname">arg</td><td>Argument that will be passed on to the deferred free function.</td></tr>
</table>
</dd>
</dl>
<p>Some runtime systems use deferred free-ing, for example when using reference counting to limit the worst case free time. Such systems can register (re-entrant) deferred free function to free more memory on demand. When the <em>force</em> parameter is <em>true</em> all possible memory should be freed. The per-thread <em>heartbeat</em> parameter is monotonically increasing and guaranteed to be deterministic if the program allocates deterministically. The <em>deferred_free</em> function is guaranteed to be called deterministically after some number of allocations (regardless of freeing or available free memory). At most one <em>deferred_free</em> function can be active. </p>
</div>
</div>
<a id="gaa1d55e0e894be240827e5d87ec3a1f45"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaa1d55e0e894be240827e5d87ec3a1f45">&#9670;&nbsp;</a></span>mi_register_error()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void mi_register_error </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__extended.html#ga251d369cda3f1c2a955c555486ed90e5">mi_error_fun</a> *&#160;</td>
<td class="paramname"><em>errfun</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">void *&#160;</td>
<td class="paramname"><em>arg</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Register an error callback function. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">errfun</td><td>The error function that is called on an error (use <em>NULL</em> for default) </td></tr>
<tr><td class="paramname">arg</td><td>Extra argument that will be passed on to the error function.</td></tr>
</table>
</dd>
</dl>
<p>The <em>errfun</em> function is called on an error in mimalloc after emitting an error message (through the output function). It as always legal to just return from the <em>errfun</em> function in which case allocation functions generally return <em>NULL</em> or ignore the condition. The default function only calls abort() when compiled in secure mode with an <em>EFAULT</em> error. The possible error codes are:</p><ul>
<li><em>EAGAIN:</em> Double free was detected (only in debug and secure mode).</li>
<li><em>EFAULT:</em> Corrupted free list or meta-data was detected (only in debug and secure mode).</li>
<li><em>ENOMEM:</em> Not enough memory available to satisfy the request.</li>
<li><em>EOVERFLOW:</em> Too large a request, for example in <a class="el" href="group__malloc.html#ga97fedb4f7107c592fd7f0f0a8949a57d" title="Allocate zero-initialized count elements of size bytes.">mi_calloc()</a>, the <em>count</em> and <em>size</em> parameters are too large.</li>
<li><em>EINVAL:</em> Trying to free or re-allocate an invalid pointer. </li>
</ul>
</div>
</div>
<a id="gae5b17ff027cd2150b43a33040250cf3f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gae5b17ff027cd2150b43a33040250cf3f">&#9670;&nbsp;</a></span>mi_register_output()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void mi_register_output </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__extended.html#gad823d23444a4b77a40f66bf075a98a0c">mi_output_fun</a> *&#160;</td>
<td class="paramname"><em>out</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">void *&#160;</td>
<td class="paramname"><em>arg</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Register an output function. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">out</td><td>The output function, use <code>NULL</code> to output to stderr. </td></tr>
<tr><td class="paramname">arg</td><td>Argument that will be passed on to the output function.</td></tr>
</table>
</dd>
</dl>
<p>The <code>out</code> function is called to output any information from mimalloc, like verbose or warning messages. </p>
</div>
</div>
<a id="ga7795a13d20087447281858d2c771cca1"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga7795a13d20087447281858d2c771cca1">&#9670;&nbsp;</a></span>mi_reserve_huge_os_pages_at()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int mi_reserve_huge_os_pages_at </td>
<td>(</td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>pages</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">int&#160;</td>
<td class="paramname"><em>numa_node</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>timeout_msecs</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Reserve <em>pages</em> of huge OS pages (1GiB) at a specific <em>numa_node</em>, but stops after at most <code>timeout_msecs</code> seconds. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">pages</td><td>The number of 1GiB pages to reserve. </td></tr>
<tr><td class="paramname">numa_node</td><td>The NUMA node where the memory is reserved (start at 0). </td></tr>
<tr><td class="paramname">timeout_msecs</td><td>Maximum number of milli-seconds to try reserving, or 0 for no timeout. </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>0 if successfull, <em>ENOMEM</em> if running out of memory, or <em>ETIMEDOUT</em> if timed out.</dd></dl>
<p>The reserved memory is used by mimalloc to satisfy allocations. May quit before <em>timeout_msecs</em> are expired if it estimates it will take more than 1.5 times <em>timeout_msecs</em>. The time limit is needed because on some operating systems it can take a long time to reserve contiguous memory if the physical memory is fragmented. </p>
</div>
</div>
<a id="ga3132f521fb756fc0e8ec0b74fb58df50"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga3132f521fb756fc0e8ec0b74fb58df50">&#9670;&nbsp;</a></span>mi_reserve_huge_os_pages_interleave()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int mi_reserve_huge_os_pages_interleave </td>
<td>(</td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>pages</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>numa_nodes</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>timeout_msecs</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Reserve <em>pages</em> of huge OS pages (1GiB) evenly divided over <em>numa_nodes</em> nodes, but stops after at most <code>timeout_msecs</code> seconds. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">pages</td><td>The number of 1GiB pages to reserve. </td></tr>
<tr><td class="paramname">numa_nodes</td><td>The number of nodes do evenly divide the pages over, or 0 for using the actual number of NUMA nodes. </td></tr>
<tr><td class="paramname">timeout_msecs</td><td>Maximum number of milli-seconds to try reserving, or 0 for no timeout. </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>0 if successfull, <em>ENOMEM</em> if running out of memory, or <em>ETIMEDOUT</em> if timed out.</dd></dl>
<p>The reserved memory is used by mimalloc to satisfy allocations. May quit before <em>timeout_msecs</em> are expired if it estimates it will take more than 1.5 times <em>timeout_msecs</em>. The time limit is needed because on some operating systems it can take a long time to reserve contiguous memory if the physical memory is fragmented. </p>
</div>
</div>
<a id="ga854b1de8cb067c7316286c28b2fcd3d1"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga854b1de8cb067c7316286c28b2fcd3d1">&#9670;&nbsp;</a></span>mi_stats_merge()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void mi_stats_merge </td>
<td>(</td>
<td class="paramtype">void&#160;</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Merge thread local statistics with the main statistics and reset. </p>
</div>
</div>
<a id="ga2d126e5c62d3badc35445e5d84166df2"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga2d126e5c62d3badc35445e5d84166df2">&#9670;&nbsp;</a></span>mi_stats_print()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void mi_stats_print </td>
<td>(</td>
<td class="paramtype">void *&#160;</td>
<td class="paramname"><em>out</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Deprecated. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">out</td><td>Ignored, outputs to the registered output function or stderr by default.</td></tr>
</table>
</dd>
</dl>
<p>Most detailed when using a debug build. </p>
</div>
</div>
<a id="ga537f13b299ddf801e49a5a94fde02c79"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga537f13b299ddf801e49a5a94fde02c79">&#9670;&nbsp;</a></span>mi_stats_print_out()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void mi_stats_print_out </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__extended.html#gad823d23444a4b77a40f66bf075a98a0c">mi_output_fun</a> *&#160;</td>
<td class="paramname"><em>out</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">void *&#160;</td>
<td class="paramname"><em>arg</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Print the main statistics. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">out</td><td>An output function or <em>NULL</em> for the default. </td></tr>
<tr><td class="paramname">arg</td><td>Optional argument passed to <em>out</em> (if not <em>NULL</em>)</td></tr>
</table>
</dd>
</dl>
<p>Most detailed when using a debug build. </p>
</div>
</div>
<a id="ga3bb8468b8cfcc6e2a61d98aee85c5f99"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga3bb8468b8cfcc6e2a61d98aee85c5f99">&#9670;&nbsp;</a></span>mi_stats_reset()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void mi_stats_reset </td>
<td>(</td>
<td class="paramtype">void&#160;</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Reset statistics. </p>
</div>
</div>
<a id="ga0ae4581e85453456a0d658b2b98bf7bf"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga0ae4581e85453456a0d658b2b98bf7bf">&#9670;&nbsp;</a></span>mi_thread_done()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void mi_thread_done </td>
<td>(</td>
<td class="paramtype">void&#160;</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Uninitialize mimalloc on a thread. </p>
<p>Should not be used as on most systems (pthreads, windows) this is done automatically. Ensures that any memory that is not freed yet (but will be freed by other threads in the future) is properly handled. </p>
</div>
</div>
<a id="gaf8e73efc2cbca9ebfdfb166983a04c17"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gaf8e73efc2cbca9ebfdfb166983a04c17">&#9670;&nbsp;</a></span>mi_thread_init()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void mi_thread_init </td>
<td>(</td>
<td class="paramtype">void&#160;</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Initialize mimalloc on a thread. </p>
<p>Should not be used as on most systems (pthreads, windows) this is done automatically. </p>
</div>
</div>
<a id="gab1dac8476c46cb9eecab767eb40c1525"></a>
<h2 class="memtitle"><span class="permalink"><a href="#gab1dac8476c46cb9eecab767eb40c1525">&#9670;&nbsp;</a></span>mi_thread_stats_print_out()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void mi_thread_stats_print_out </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__extended.html#gad823d23444a4b77a40f66bf075a98a0c">mi_output_fun</a> *&#160;</td>
<td class="paramname"><em>out</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">void *&#160;</td>
<td class="paramname"><em>arg</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Print out heap statistics for this thread. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">out</td><td>An output function or <em>NULL</em> for the default. </td></tr>
<tr><td class="paramname">arg</td><td>Optional argument passed to <em>out</em> (if not <em>NULL</em>)</td></tr>
</table>
</dd>
</dl>
<p>Most detailed when using a debug build. </p>
</div>
</div>
<a id="ga089c859d9eddc5f9b4bd946cd53cebee"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga089c859d9eddc5f9b4bd946cd53cebee">&#9670;&nbsp;</a></span>mi_usable_size()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">size_t mi_usable_size </td>
<td>(</td>
<td class="paramtype">void *&#160;</td>
<td class="paramname"><em>p</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Return the available bytes in a memory block. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">p</td><td>Pointer to previously allocated memory (or <em>NULL</em>) </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns the available bytes in the memory block, or 0 if <em>p</em> was <em>NULL</em>.</dd></dl>
<p>The returned size can be used to call <em>mi_expand</em> successfully. The returned size is always at least equal to the allocated size of <em>p</em>, and, in the current design, should be less than 16.7% more.</p>
<dl class="section see"><dt>See also</dt><dd><a href="https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/msize?view=vs-2017">_msize</a> (Windows) </dd>
<dd>
<a href="http://man7.org/linux/man-pages/man3/malloc_usable_size.3.html">malloc_usable_size</a> (Linux) </dd>
<dd>
<a class="el" href="group__extended.html#gac057927cd06c854b45fe7847e921bd47" title="Return the used allocation size.">mi_good_size()</a> </dd></dl>
</div>
</div>
<a id="ga220f29f40a44404b0061c15bc1c31152"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ga220f29f40a44404b0061c15bc1c31152">&#9670;&nbsp;</a></span>mi_zalloc_small()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void* mi_zalloc_small </td>
<td>(</td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>size</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Allocate a zero initialized small object. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">size</td><td>The size in bytes, can be at most <a class="el" href="group__extended.html#ga1ea64283508718d9d645c38efc2f4305" title="Maximum size allowed for small allocations in mi_malloc_small and mi_zalloc_small (usually 128*sizeof...">MI_SMALL_SIZE_MAX</a>. </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>a pointer to newly allocated zero-initialized memory of at least <em>size</em> bytes, or <em>NULL</em> if out of memory. This function is meant for use in run-time systems for best performance and does not check if <em>size</em> was indeed small &ndash; use with care! </dd></dl>
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.15 </li>
</ul>
</div>
</body>
</html>
-27
View File
@@ -1,27 +0,0 @@
var group__extended =
[
[ "MI_SMALL_SIZE_MAX", "group__extended.html#ga1ea64283508718d9d645c38efc2f4305", null ],
[ "mi_deferred_free_fun", "group__extended.html#ga299dae78d25ce112e384a98b7309c5be", null ],
[ "mi_error_fun", "group__extended.html#ga251d369cda3f1c2a955c555486ed90e5", null ],
[ "mi_output_fun", "group__extended.html#gad823d23444a4b77a40f66bf075a98a0c", null ],
[ "mi_collect", "group__extended.html#ga421430e2226d7d468529cec457396756", null ],
[ "mi_good_size", "group__extended.html#gac057927cd06c854b45fe7847e921bd47", null ],
[ "mi_is_in_heap_region", "group__extended.html#ga5f071b10d4df1c3658e04e7fd67a94e6", null ],
[ "mi_is_redirected", "group__extended.html#gaad25050b19f30cd79397b227e0157a3f", null ],
[ "mi_malloc_small", "group__extended.html#ga7136c2e55cb22c98ecf95d08d6debb99", null ],
[ "mi_process_info", "group__extended.html#ga7d862c2affd5790381da14eb102a364d", null ],
[ "mi_register_deferred_free", "group__extended.html#ga3460a6ca91af97be4058f523d3cb8ece", null ],
[ "mi_register_error", "group__extended.html#gaa1d55e0e894be240827e5d87ec3a1f45", null ],
[ "mi_register_output", "group__extended.html#gae5b17ff027cd2150b43a33040250cf3f", null ],
[ "mi_reserve_huge_os_pages_at", "group__extended.html#ga7795a13d20087447281858d2c771cca1", null ],
[ "mi_reserve_huge_os_pages_interleave", "group__extended.html#ga3132f521fb756fc0e8ec0b74fb58df50", null ],
[ "mi_stats_merge", "group__extended.html#ga854b1de8cb067c7316286c28b2fcd3d1", null ],
[ "mi_stats_print", "group__extended.html#ga2d126e5c62d3badc35445e5d84166df2", null ],
[ "mi_stats_print_out", "group__extended.html#ga537f13b299ddf801e49a5a94fde02c79", null ],
[ "mi_stats_reset", "group__extended.html#ga3bb8468b8cfcc6e2a61d98aee85c5f99", null ],
[ "mi_thread_done", "group__extended.html#ga0ae4581e85453456a0d658b2b98bf7bf", null ],
[ "mi_thread_init", "group__extended.html#gaf8e73efc2cbca9ebfdfb166983a04c17", null ],
[ "mi_thread_stats_print_out", "group__extended.html#gab1dac8476c46cb9eecab767eb40c1525", null ],
[ "mi_usable_size", "group__extended.html#ga089c859d9eddc5f9b4bd946cd53cebee", null ],
[ "mi_zalloc_small", "group__extended.html#ga220f29f40a44404b0061c15bc1c31152", null ]
];
Loaded 100 of 3069 files, more files were not shown because too many files have changed in this diff. Show more