[PATCH] D118570: [lld-macho] Add support for -image_base, -static, -pagezero_size, and -version_load_command
Jared Irwin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 30 10:22:44 PST 2022
Link1J created this revision.
Link1J added a reviewer: lld-macho.
Link1J added projects: lld, lld-macho.
Herald added a reviewer: MaskRay.
Herald added a subscriber: dang.
Link1J requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This adds the `-image_base`, `-static`, `-pagezero_size`, and `-version_load_command`.
`-image_base`, `-static`, and `-pagezero_size` commonly used for kernel development. So I don't know how useful these will be to most people, but I do believe that having lld be a more complete replacement for the Apple linker is a good thing.
`-image_base` sets the virtual address of the first section, changing the starting address the binary is loaded at. Basically the same thing as `/BASE` from link and lld-link.
`-pagezero_size` changes the `__PAGEZERO` size, removing that segment if it is set to zero. I personally have no idea what `__PAGEZERO` is for, but it isn't useful with a custom image base.
`-static` does alot. It changes the entry point command from `LC_MAIN` to `LC_UNIXTHREAD`. It also stops the `LC_BUILD_VERSION`, `LC_VERSION_MIN_*`, `LC_LOAD_DYLINKER`, `LC_DATA_IN_CODE`, and `LC_FUNCTION_STARTS` commands from being added to the binary. It appears that `-function_starts` and `-version_load_command` readds their respective commands to the binary, so `-static` only changes the default for commands.
`-version_load_command` adds `LC_BUILD_VERSION` or `LC_VERSION_MIN_*` when `-static` is used. It got added because it was easy to add as I was doing `-static`. I only learnt about `-version_load_command` from reading the Makefiles for the XNU kernel used in macOS. Maybe in the future, it can be extended to control which version command gets added, but that is far beyond what I intended to do.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D118570
Files:
lld/Common/Args.cpp
lld/MachO/Arch/ARM.cpp
lld/MachO/Arch/ARM64.cpp
lld/MachO/Arch/X86_64.cpp
lld/MachO/Config.h
lld/MachO/Driver.cpp
lld/MachO/Options.td
lld/MachO/SyntheticSections.h
lld/MachO/Target.h
lld/MachO/Writer.cpp
lld/include/lld/Common/Args.h
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118570.404386.patch
Type: text/x-patch
Size: 12432 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220130/da202607/attachment.bin>
More information about the llvm-commits
mailing list