Skip to content

Commit

Permalink
Remove BITCODE_TOUCH_SYMBOL_MAP
Browse files Browse the repository at this point in the history
This was a workaround for a ld64 bug that has been fixed as far back as
Xcode 10.x. The logic (from Xcode 10.2) is now:

```
int ret = ::stat(fReverseMapPath, &statbuf);
if ( ret == 0 && S_ISDIR(statbuf.st_mode)) {
```

Closes #12379.

PiperOrigin-RevId: 341880058
  • Loading branch information
keith authored and copybara-github committed Nov 11, 2020
1 parent c7df294 commit a1471a8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5961,7 +5961,7 @@ def _impl(ctx):
"-Xlinker",
"-bitcode_symbol_map",
"-Xlinker",
"BITCODE_TOUCH_SYMBOL_MAP=%{bitcode_symbol_map_path}",
"%{bitcode_symbol_map_path}",
],
),
],
Expand Down
2 changes: 1 addition & 1 deletion tools/osx/crosstool/cc_toolchain_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6009,7 +6009,7 @@ def _impl(ctx):
"-Xlinker",
"-bitcode_symbol_map",
"-Xlinker",
"BITCODE_TOUCH_SYMBOL_MAP=%{bitcode_symbol_map_path}",
"%{bitcode_symbol_map_path}",
],
expand_if_available = "bitcode_symbol_map_path",
),
Expand Down
20 changes: 1 addition & 19 deletions tools/osx/crosstool/wrapped_clang.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@
// "DSYM_HINT_LINKED_BINARY": Workspace-relative path to binary output of the
// link action generating the dsym file.
// "DSYM_HINT_DSYM_PATH": Workspace-relative path to dSYM dwarf file.
//
// Likewise, this wrapper also contains a workaround for a bug in ld that causes
// flaky builds when using Bitcode symbol maps. ld allows the
// -bitcode_symbol_map to be either a directory (into which the file will be
// written) or a file, but the return value of the call to ::stat is never
// checked so examining the S_ISDIR bit of the struct afterwards returns
// true/false randomly depending on what data happened to be in memory at the
// time it was called:
// https://github.com/michaelweiser/ld64/blob/9c3700b64ed03e2d55ba094176bf6a172bf2bc6b/src/ld/Options.cpp#L3261
// To address this, we prepend a special "BITCODE_TOUCH_SYMBOL_MAP=" flag to the
// symbol map filename and touch it before passing it along to clang, forcing
// the file to exist.

#include <libgen.h>
#include <spawn.h>
Expand Down Expand Up @@ -191,7 +179,7 @@ int main(int argc, char *argv[]) {

std::vector<std::string> processed_args = {"/usr/bin/xcrun", tool_name};

std::string linked_binary, dsym_path, bitcode_symbol_map;
std::string linked_binary, dsym_path;
std::string dest_dir;

std::unique_ptr<char, decltype(std::free) *> cwd{getcwd(nullptr, 0),
Expand All @@ -211,12 +199,6 @@ int main(int argc, char *argv[]) {
if (SetArgIfFlagPresent(arg, "DSYM_HINT_DSYM_PATH", &dsym_path)) {
continue;
}
if (SetArgIfFlagPresent(arg, "BITCODE_TOUCH_SYMBOL_MAP",
&bitcode_symbol_map)) {
// Touch bitcode_symbol_map.
std::ofstream bitcode_symbol_map_file(bitcode_symbol_map);
arg = bitcode_symbol_map;
}
if (arg.compare("OSO_PREFIX_MAP_PWD") == 0) {
arg = "-Wl,-oso_prefix," + std::string(cwd.get()) + "/";
}
Expand Down

0 comments on commit a1471a8

Please sign in to comment.