Skip to content

Commit

Permalink
[lld-macho] Remove linking bitcode support
Browse files Browse the repository at this point in the history
Apple deprecated bitcode in the deployment process in Xcode 14.0. Last
month Apple started requiring Xcode 14.1+ to submit apps to the App
Store. Since there isn't a use for bundling bitcode outside of
submitting to the App Store we should be safe to delete this handling
entirely from LLD.

Differential Revision: https://reviews.llvm.org/D150697
  • Loading branch information
keith committed May 30, 2023
1 parent 5da248c commit 48e5f70
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 192 deletions.
4 changes: 0 additions & 4 deletions lld/CMakeLists.txt
Expand Up @@ -99,10 +99,6 @@ if(LLD_BUILT_STANDALONE)
set(LLVM_INCLUDE_TESTS OFF)
endif()
endif()

if(LLVM_HAVE_LIBXAR)
set(XAR_LIB xar)
endif()
endif() # standalone

set(LLD_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH
Expand Down
5 changes: 0 additions & 5 deletions lld/MachO/CMakeLists.txt
Expand Up @@ -54,13 +54,8 @@ add_lld_library(lldMachO
LINK_LIBS
lldCommon
${LLVM_PTHREAD_LIB}
${XAR_LIB}

DEPENDS
MachOOptionsTableGen
${tablegen_deps}
)

if(LLVM_HAVE_LIBXAR)
target_link_libraries(lldMachO PRIVATE ${XAR_LIB})
endif()
1 change: 0 additions & 1 deletion lld/MachO/Config.h
Expand Up @@ -131,7 +131,6 @@ struct Configuration {
bool saveTemps = false;
bool adhocCodesign = false;
bool emitFunctionStarts = false;
bool emitBitcodeBundle = false;
bool emitDataInCodeInfo = false;
bool emitEncryptionInfo = false;
bool emitInitOffsets = false;
Expand Down
6 changes: 0 additions & 6 deletions lld/MachO/Driver.cpp
Expand Up @@ -1614,7 +1614,6 @@ bool macho::link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
config->implicitDylibs = !args.hasArg(OPT_no_implicit_dylibs);
config->emitFunctionStarts =
args.hasFlag(OPT_function_starts, OPT_no_function_starts, true);
config->emitBitcodeBundle = args.hasArg(OPT_bitcode_bundle);
config->emitDataInCodeInfo =
args.hasFlag(OPT_data_in_code_info, OPT_no_data_in_code_info, true);
config->emitChainedFixups = shouldEmitChainedFixups(args);
Expand Down Expand Up @@ -1654,11 +1653,6 @@ bool macho::link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
args.hasFlag(OPT_encryptable, OPT_no_encryption,
is_contained(encryptablePlatforms, config->platform()));

#ifndef LLVM_HAVE_LIBXAR
if (config->emitBitcodeBundle)
error("-bitcode_bundle unsupported because LLD wasn't built with libxar");
#endif

if (const Arg *arg = args.getLastArg(OPT_install_name)) {
if (config->warnDylibInstallName && config->outputType != MH_DYLIB)
warn(
Expand Down
45 changes: 22 additions & 23 deletions lld/MachO/Options.td
Expand Up @@ -644,21 +644,6 @@ def add_ast_path : Separate<["-"], "add_ast_path">,
HelpText<"AST paths will be emitted as STABS">,
Group<grp_symtab>;

def grp_bitcode : OptionGroup<"bitcode">, HelpText<"BITCODE BUILD FLOW">;

def bitcode_bundle : Flag<["-"], "bitcode_bundle">,
HelpText<"Generate an embedded bitcode bundle in the __LLVM,__bundle section of the output">,
Group<grp_bitcode>;
def bitcode_hide_symbols : Flag<["-"], "bitcode_hide_symbols">,
HelpText<"With -bitcode_bundle, hide all non-exported symbols from output bitcode bundle.">,
Flags<[HelpHidden]>,
Group<grp_bitcode>;
def bitcode_symbol_map : Separate<["-"], "bitcode_symbol_map">,
MetaVarName<"<path>">,
HelpText<"Write the bitcode symbol reverse mapping to file <path>, or if a directory, to <path>/UUID.bcsymbolmap">,
Flags<[HelpHidden]>,
Group<grp_bitcode>;

def grp_rare : OptionGroup<"rare">, HelpText<"RARELY USED">;

def v : Flag<["-"], "v">,
Expand Down Expand Up @@ -1200,6 +1185,28 @@ def slow_stubs : Flag<["-"], "slow_stubs">,
Flags<[HelpHidden]>,
Group<grp_obsolete>;

def bitcode_bundle : Flag<["-"], "bitcode_bundle">,
HelpText<"Obsolete since the App Store no longer supports binaries with embedded bitcode">,
Flags<[HelpHidden]>,
Group<grp_obsolete>;
def bitcode_hide_symbols : Flag<["-"], "bitcode_hide_symbols">,
HelpText<"Obsolete since the App Store no longer supports binaries with embedded bitcode">,
Flags<[HelpHidden]>,
Group<grp_obsolete>;
def bitcode_symbol_map : Separate<["-"], "bitcode_symbol_map">,
MetaVarName<"<path>">,
HelpText<"Obsolete since the App Store no longer supports binaries with embedded bitcode">,
Flags<[HelpHidden]>,
Group<grp_obsolete>;
def bitcode_process_mode : Separate<["-"], "bitcode_process_mode">,
HelpText<"Obsolete since the App Store no longer supports binaries with embedded bitcode">,
Flags<[HelpHidden]>,
Group<grp_obsolete>;
def bitcode_verify : Flag<["-"], "bitcode_verify">,
HelpText<"Obsolete since the App Store no longer supports binaries with embedded bitcode">,
Flags<[HelpHidden]>,
Group<grp_obsolete>;

def grp_undocumented : OptionGroup<"undocumented">, HelpText<"UNDOCUMENTED">;

def add_linker_option : Flag<["-"], "add_linker_option">,
Expand All @@ -1226,14 +1233,6 @@ def allow_simulator_linking_to_macosx_dylibs : Flag<["-"], "allow_simulator_link
HelpText<"This option is undocumented in ld64">,
Flags<[HelpHidden]>,
Group<grp_undocumented>;
def bitcode_process_mode : Separate<["-"], "bitcode_process_mode">,
HelpText<"This option is undocumented in ld64">,
Flags<[HelpHidden]>,
Group<grp_undocumented>;
def bitcode_verify : Flag<["-"], "bitcode_verify">,
HelpText<"This option is undocumented in ld64">,
Flags<[HelpHidden]>,
Group<grp_undocumented>;
def classic_linker : Flag<["-"], "classic_linker">,
HelpText<"This option is undocumented in ld64">,
Flags<[HelpHidden]>,
Expand Down
63 changes: 0 additions & 63 deletions lld/MachO/SyntheticSections.cpp
Expand Up @@ -35,13 +35,6 @@
#include "llvm/Support/SHA256.h"
#endif

#ifdef LLVM_HAVE_LIBXAR
#include <fcntl.h>
extern "C" {
#include <xar/xar.h>
}
#endif

using namespace llvm;
using namespace llvm::MachO;
using namespace llvm::support;
Expand Down Expand Up @@ -1553,62 +1546,6 @@ void CodeSignatureSection::writeTo(uint8_t *buf) const {
memset(id + fileName.size(), 0, fileNamePad);
}

BitcodeBundleSection::BitcodeBundleSection()
: SyntheticSection(segment_names::llvm, section_names::bitcodeBundle) {}

class ErrorCodeWrapper {
public:
explicit ErrorCodeWrapper(std::error_code ec) : errorCode(ec.value()) {}
explicit ErrorCodeWrapper(int ec) : errorCode(ec) {}
operator int() const { return errorCode; }

private:
int errorCode;
};

#define CHECK_EC(exp) \
do { \
ErrorCodeWrapper ec(exp); \
if (ec) \
fatal(Twine("operation failed with error code ") + Twine(ec) + ": " + \
#exp); \
} while (0);

void BitcodeBundleSection::finalize() {
#ifdef LLVM_HAVE_LIBXAR
using namespace llvm::sys::fs;
CHECK_EC(createTemporaryFile("bitcode-bundle", "xar", xarPath));

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
xar_t xar(xar_open(xarPath.data(), O_RDWR));
#pragma clang diagnostic pop
if (!xar)
fatal("failed to open XAR temporary file at " + xarPath);
CHECK_EC(xar_opt_set(xar, XAR_OPT_COMPRESSION, XAR_OPT_VAL_NONE));
// FIXME: add more data to XAR
CHECK_EC(xar_close(xar));

file_size(xarPath, xarSize);
#endif // defined(LLVM_HAVE_LIBXAR)
}

void BitcodeBundleSection::writeTo(uint8_t *buf) const {
using namespace llvm::sys::fs;
file_t handle =
CHECK(openNativeFile(xarPath, CD_OpenExisting, FA_Read, OF_None),
"failed to open XAR file");
std::error_code ec;
mapped_file_region xarMap(handle, mapped_file_region::mapmode::readonly,
xarSize, 0, ec);
if (ec)
fatal("failed to map XAR file");
memcpy(buf, xarMap.const_data(), xarSize);

closeFile(handle);
remove(xarPath);
}

CStringSection::CStringSection(const char *name)
: SyntheticSection(segment_names::text, name) {
flags = S_CSTRING_LITERALS;
Expand Down
12 changes: 0 additions & 12 deletions lld/MachO/SyntheticSections.h
Expand Up @@ -533,18 +533,6 @@ class CodeSignatureSection final : public LinkEditSection {
void writeHashes(uint8_t *buf) const;
};

class BitcodeBundleSection final : public SyntheticSection {
public:
BitcodeBundleSection();
uint64_t getSize() const override { return xarSize; }
void finalize() override;
void writeTo(uint8_t *buf) const override;

private:
llvm::SmallString<261> xarPath;
uint64_t xarSize;
};

class CStringSection : public SyntheticSection {
public:
CStringSection(const char *name);
Expand Down
2 changes: 0 additions & 2 deletions lld/MachO/Writer.cpp
Expand Up @@ -978,8 +978,6 @@ template <class LP> void Writer::createOutputSections() {
dataInCodeSection = make<DataInCodeSection>();
if (config->emitFunctionStarts)
functionStartsSection = make<FunctionStartsSection>();
if (config->emitBitcodeBundle)
make<BitcodeBundleSection>();

switch (config->outputType) {
case MH_EXECUTE:
Expand Down
1 change: 0 additions & 1 deletion lld/test/CMakeLists.txt
Expand Up @@ -4,7 +4,6 @@ llvm_canonicalize_cmake_booleans(
LLVM_ENABLE_ZSTD
LLVM_ENABLE_LIBXML2
LLD_DEFAULT_LD_LLD_IS_MINGW
LLVM_HAVE_LIBXAR
LLVM_BUILD_EXAMPLES
LLVM_ENABLE_PLUGINS
LLVM_BYE_LINK_INTO_TOOLS
Expand Down
69 changes: 0 additions & 69 deletions lld/test/MachO/bitcode-bundle.ll

This file was deleted.

@@ -1,8 +1,7 @@
; REQUIRES: x86
; UNSUPPORTED: xar
; RUN: opt -module-summary %s -o %t.o
; RUN: not %lld -lSystem -bitcode_bundle %t.o -o /dev/null 2>&1 | FileCheck %s
; CHECK: error: -bitcode_bundle unsupported because LLD wasn't built with libxar
; CHECK: error: Option `-bitcode_bundle' is obsolete. Please modernize your usage.

target triple = "x86_64-apple-darwin"
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
Expand Down
3 changes: 0 additions & 3 deletions lld/test/lit.cfg.py
Expand Up @@ -125,9 +125,6 @@
if config.enable_backtrace:
config.available_features.add("backtrace")

if config.have_libxar:
config.available_features.add("xar")

if config.have_libxml2:
config.available_features.add("libxml2")

Expand Down
1 change: 0 additions & 1 deletion lld/test/lit.site.cfg.py.in
Expand Up @@ -20,7 +20,6 @@ config.target_triple = "@LLVM_TARGET_TRIPLE@"
config.python_executable = "@Python3_EXECUTABLE@"
config.have_zlib = @LLVM_ENABLE_ZLIB@
config.have_zstd = @LLVM_ENABLE_ZSTD@
config.have_libxar = @LLVM_HAVE_LIBXAR@
config.have_libxml2 = @LLVM_ENABLE_LIBXML2@
config.sizeof_void_p = @CMAKE_SIZEOF_VOID_P@
config.ld_lld_default_mingw = @LLD_DEFAULT_LD_LLD_IS_MINGW@
Expand Down

0 comments on commit 48e5f70

Please sign in to comment.