[PATCH] D124347: [BOLT] RFC: Add golang support

Vladislav Khmelevsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 24 09:52:28 PDT 2022


yota9 created this revision.
yota9 added reviewers: maksfb, rafauler, Amir.
Herald added subscribers: ayermolo, pengfei, kristof.beyls, mgorny.
Herald added a project: All.
yota9 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch adds golang binaries support built with original golang
compiler (gc). The golang support requers 3 separate optimization
passes:

- golang-preprocess: This pass must be executed before any changes were

perfomed in BinaryFunctions. Its main purpose is to parse the initial
metadata for golang functions.

- golang-postprocess: This pass must be executed after all optimizations

were performed (except for the LongJmp) pass. Its main purpose is too
adjust the code to sync it with functions metadata.

- golang: This pass must be executed after all code changes were

performed, no code changes are allowed by this pass or after it. This
pass only changes golang-specific data sections that contains functions
metadata.

Golang compiler patches:
Aarch64 support needs mapping symbols patch support, the PR was created
here: https://go-review.googlesource.com/c/go/+/343150 . The patches for
the gc supported versions might be found here:
https://github.com/yota9/golang_aarch64_mapping_symbols . Apply the
patch for your gc version and rebuilt the compiler.

Golang binaries compilation:
The golang default linker does not support emit-relocs option, the
external linker must be used for that purpose. The compilation command
examples:

- x86_64 (pie): go build -a -buildmode=pie -ldflags='-linkmode=external -extld=gcc -extldflags "-fuse-ld=gold -fPIE -pie -Wl,--threads -Wl,--emit-relocs -Wl,--compress-debug-sections=none"
- x86_64 (no-pie): go build -a -buildmode=exe -ldflags='-linkmode=external -extld=gcc -extldflags "-fuse-ld=gold -no-pie -Wl,--threads -Wl,--emit-relocs -Wl,--compress-debug-sections=none"
- aarch64 (non-pie): go build -a -ldflags='-linkmode=external -extld=gcc -extldflags "-no-pie -Wl,--emit-relocs -Wl,--compress-debug-sections=none"

NOTE: The aarch64 ld and gold linkers currently has some bugs related to
PIE binaries. The ld emits wrong addresses in data sections, which does
not affect runtime due to dynamic relocations, but affects our binary
data extractions. The gold linker emits static relocations on the wrong offsets.

Restrictions:

- The golang support is tightly connected to the gc version, so we only

can optimize supported by BOLT gc versions compiled binaries.

- The inlining, frame optimization, split functions, lite mode

optimizations are unsupported.

Results:
Up to 19% of performance improvements were received on internal services.

NOTE: Golang binaries are compatible with instrumentation!

Testing:
TBD, probably a few binaries would be add in bolt-tests repo for both
x86 and aarch64 platforms.

Vladislav Khmelevsky,
Advanced Software Technology Lab, Huawei


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124347

Files:
  bolt/CODE_OWNERS.TXT
  bolt/README.md
  bolt/include/bolt/Core/BinaryBasicBlock.h
  bolt/include/bolt/Core/BinaryContext.h
  bolt/include/bolt/Core/BinaryData.h
  bolt/include/bolt/Core/BinaryFunction.h
  bolt/include/bolt/Core/BinarySection.h
  bolt/include/bolt/Core/MCPlusBuilder.h
  bolt/include/bolt/Core/Relocation.h
  bolt/include/bolt/Passes/Golang.h
  bolt/include/bolt/Passes/Golang/go_base.h
  bolt/include/bolt/Passes/Golang/go_common.h
  bolt/include/bolt/Passes/Golang/go_v1_14.h
  bolt/include/bolt/Passes/Golang/go_v1_16_5.h
  bolt/include/bolt/Passes/Golang/go_v1_17.h
  bolt/include/bolt/Passes/IdenticalCodeFolding.h
  bolt/include/bolt/Passes/LongJmp.h
  bolt/include/bolt/Rewrite/RewriteInstance.h
  bolt/include/bolt/Utils/CommandLineOpts.h
  bolt/include/bolt/Utils/NameResolver.h
  bolt/lib/Core/BinaryBasicBlock.cpp
  bolt/lib/Core/BinaryContext.cpp
  bolt/lib/Core/BinaryEmitter.cpp
  bolt/lib/Core/BinaryFunction.cpp
  bolt/lib/Core/BinarySection.cpp
  bolt/lib/Core/Relocation.cpp
  bolt/lib/Passes/BinaryPasses.cpp
  bolt/lib/Passes/CMakeLists.txt
  bolt/lib/Passes/Golang-postprocess.cpp
  bolt/lib/Passes/Golang-preprocess.cpp
  bolt/lib/Passes/Golang.cpp
  bolt/lib/Passes/IdenticalCodeFolding.cpp
  bolt/lib/Passes/Inliner.cpp
  bolt/lib/Passes/Instrumentation.cpp
  bolt/lib/Passes/LongJmp.cpp
  bolt/lib/Passes/ReorderFunctions.cpp
  bolt/lib/Passes/SplitFunctions.cpp
  bolt/lib/Rewrite/BinaryPassManager.cpp
  bolt/lib/Rewrite/RewriteInstance.cpp
  bolt/lib/RuntimeLibs/InstrumentationRuntimeLibrary.cpp
  bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
  bolt/lib/Target/X86/X86MCPlusBuilder.cpp
  bolt/lib/Utils/CommandLineOpts.cpp
  bolt/runtime/instr.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124347.424789.patch
Type: text/x-patch
Size: 205588 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220424/6f65eb9f/attachment-0001.bin>


More information about the llvm-commits mailing list