Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
arm64: relocatable: Tweak linker flags to yield a smaller Image with LLD
Browse files Browse the repository at this point in the history
Currently, there is a regression of 689 KiB in Image.gz's size when the
kernel is linked with LLD. This is reduced to 213 KiB when we use -pie
rather than -shared when invoking the linker.

Unfortunately, ld.bfd dislikes this change and regresses in size by 163
KiB with -pie as compared to using -shared. To address this problem, we
add checks so that -pie is used with LLD and -shared is used with
ld.bfd. That way, both linkers are able to perform their best.

List of Image.gz sizes:
  ld.bfd -shared: 10,066,988 bytes
  ld.bfd -pie:    10,230,316 bytes
  LLD -shared:    10,796,872 bytes
  LLD -pie:       10,280,168 bytes

Test: kernel compiles and boots with both ld.bfd and LLD
Signed-off-by: Danny Lin <danny@kdrag0n.dev>
[@0ctobot: Simplify checks so that ld.gold remains unaffected]
Signed-off-by: Adam W. Willis <return.of.octobot@gmail.com>
  • Loading branch information
kdrag0n authored and THEBOSS619 committed Apr 26, 2020
1 parent c3c897f commit 8e8c7c9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion arch/arm64/Makefile
Expand Up @@ -18,8 +18,15 @@ ifeq ($(CONFIG_RELOCATABLE), y)
# Pass --no-apply-dynamic-relocs to restore pre-binutils-2.27 behaviour
# for relative relocs, since this leads to better Image compression
# with the relocation offsets always being zero.
LDFLAGS_vmlinux += -shared -Bsymbolic -z notext -z norelro \
LDFLAGS_vmlinux += -Bsymbolic -z notext -z norelro \
$(call ld-option, --no-apply-dynamic-relocs)

# Pass -pie for lld to minimize image size
ifeq ($(ld-name),lld)
LDFLAGS_vmlinux += -pie
else
LDFLAGS_vmlinux += -shared
endif
endif

ifeq ($(CONFIG_ARM64_ERRATUM_843419),y)
Expand Down

0 comments on commit 8e8c7c9

Please sign in to comment.