This patch is bringing the section name encoding of llvm-objcopy to the same level as what's done in llvm/lib/MC/WinCOFFObjectWriter.cpp, the base64 encoding code is taken from there.
The section name encoding for llvm-objcopy had two main issues, the first is that the size used for the snprintf in the original code is incorrect because snprintf adds a null byte, so this code was only able to encode offsets of 6 digits, /, \0 and 6 digits of the offset, rather than the 7 digits it should support.
And the second part is that it didn't support the base64 encoding for offsets larger than 7 digits.
This issue specifically showed up when using the clang-offload-bundler with a binary containing a lot of symbols/sections, since it uses llvm-objcopy to add the sections containing the offload code.
This patch may need some modifications and/or follow up.
It would be good to de-duplicate some of this code, at least the base64 encoding code, there's a base64 encoding function in support however it encodes bytes, rather than re-interpret a number into base64, but I'm not sure where it would go best.
And I'm also a little unsure on how to approach testing for this, yaml2obj, however it is also missing base64 encoding which should definitely be added, but even then the yaml file ends up very large to be able to test all the different encodings. The MC counterpart of this uses llvm-mc and assembler macros to generate the very large string tables, would it be okay to do the same in llvm-objcopy testing?
llvm-objcopy generally uses # and ## in lit test files, the former for test directives, like RUN lines, and FileCheck patterns, the latter for pure comments.
(If llvm-mc doesn't like # as a comment marker, then I'd use //// still for true comments, to distinguish them from test directives).