[lld-macho] Only emit one BIND_OPCODE_SET_SYMBOL per symbol
authorJez Ng <jezng@fb.com>
Tue, 6 Jul 2021 00:00:09 +0000 (20:00 -0400)
committerJez Ng <jezng@fb.com>
Tue, 6 Jul 2021 00:00:19 +0000 (20:00 -0400)
commit718c32175b3bcced88d9ca25ab1482a682ae5bbb
treec8277dc53461c37be3259cb555337ed8fc12abef
parente2904c8e0fa901adeefe579297cb2ece2757fb18
[lld-macho] Only emit one BIND_OPCODE_SET_SYMBOL per symbol

Size-wise, BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM is the most
expensive opcode, since it comes with an associated symbol string. We
were previously emitting it once per binding, instead of once per
symbol. This diff groups all bindings for a given symbol together and
ensures we only emit one such opcode per symbol. This matches ld64's
behavior.

While this is a relatively small win on chromium_framework (-72KiB), for
programs that have more dynamic bindings, the difference can be quite
large.

This change is perf-neutral when linking chromium_framework.

Reviewed By: #lld-macho, thakis

Differential Revision: https://reviews.llvm.org/D105075
lld/MachO/SyntheticSections.cpp
lld/MachO/SyntheticSections.h
lld/test/MachO/bind-opcodes.s [new file with mode: 0644]