Permalink
Browse files

Add a build rule to weaken erroneous symbols in libpindwarf.a

So that we can link statically with libstdc++.

Change-Id: I3118bb20c4cab9d17fd84ebaea8d8e229298866a
  • Loading branch information...
s-kanev authored and Svilen Kanev committed Apr 29, 2016
1 parent 21130d5 commit 2853d6c62965a5327cf032bbb38fd1d089f0331d
Showing with 58 additions and 10 deletions.
  1. +2 −1 README.md
  2. +25 −9 third_party/pin/BUILD.external
  3. +31 −0 third_party/pin/weaken.bzl
View
@@ -15,7 +15,8 @@ XIOSim builds up on and integrates a significant amount of others' work:
- The DRAM models from [DRAMSim2](http://wiki.umd.edu/DRAMSim2/index.php/Main_Page).
### Dependences ###
-- Bazel 0.1 [Download](http://bazel.io/docs/install.html)
+- Bazel 0.1.4 or newer [Download](http://bazel.io/docs/install.html)
+- a recent C++ toolchain with C++14 support (GCC 4.9 or newer)
- (integration tests only) Python and py.test
XIOSim uses [bazel](http://bazel.io) for fetching and building dependences.
@@ -54,15 +54,9 @@ cc_library(
":piii" : [ "TARGET_IA32", "HOST_IA32", "TARGET_LINUX" ],
}),
srcs = select({
- ":k8" : [
- PIN_PATH + "/intel64/lib/libpin.a",
- PIN_PATH + "/intel64/lib-ext/libpindwarf.a",
- ],
- ":piii" : [
- PIN_PATH + "/ia32/lib/libpin.a",
- PIN_PATH + "/ia32/lib-ext/libpindwarf.a",
- ],
- }),
+ ":k8" : [PIN_PATH + "/intel64/lib/libpin.a"],
+ ":piii" : [PIN_PATH + "/ia32/lib/libpin.a"],
+ }) + [":weak_pindwarf"],
)
filegroup(
@@ -73,6 +67,28 @@ filegroup(
}),
)
+load("@//third_party/pin:weaken.bzl", "cc_weaken")
+# libpindwarf.a contains a few symbols from libstdc++ (which are byte-for-byte
+# equivalent). When we link libstc++ statically, they clash.
+# So, we'll patch libpindwarf to make these weak.
+cc_weaken(
+ name = "weak_pindwarf",
+ srcs = select({
+ "k8" : PIN_PATH + "/intel64/lib-ext/libpindwarf.a",
+ "piii" : PIN_PATH + "/ia32/lib-ext/libpindwarf.a",
+ }),
+ symbols = [
+ "_ZNSt14error_categoryD0Ev",
+ "_ZNSt14error_categoryD1Ev",
+ "_ZNSt14error_categoryD2Ev",
+ "_ZNKSt14error_category23default_error_conditionEi",
+ "_ZNKSt14error_category10equivalentERKSt10error_codei",
+ "_ZNKSt14error_category10equivalentEiRKSt15error_condition",
+ "_ZSt15system_categoryv",
+ "_ZSt16generic_categoryv",
+ ],
+)
+
# We want symlinks instead of copying, but
# "Bazel doesn't copy over the directory/symlink structure created by genrules"
View
@@ -0,0 +1,31 @@
+# Invoke objcopy to make a list of symbols in an archive weak
+
+ar_file_type = FileType([".a"])
+
+def _impl(ctx):
+ output = ctx.outputs.out
+ input = ctx.file.srcs
+ syms = ctx.attr.symbols
+
+ sym_params = []
+ for sym in syms:
+ sym_params += ["-W", sym]
+
+ ctx.action(
+ inputs = [input],
+ outputs = [output],
+ progress_message = "Running objcopy on %s" % input.short_path,
+ executable = ctx.fragments.cpp.objcopy_executable,
+ arguments = sym_params + [input.path, output.path],
+ )
+
+cc_weaken = rule(
+ implementation = _impl,
+ fragments = ["cpp"],
+ attrs = {
+ "srcs": attr.label(mandatory=True, allow_files=ar_file_type, single_file=True),
+ "symbols" : attr.string_list(),
+ },
+ outputs = {"out": "%{name}.weak.a"},
+)
+

0 comments on commit 2853d6c

Please sign in to comment.