[PATCH] D138999: [libc] Make libc symbols weak by default for bazel

Guillaume Chatelet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 2 00:43:12 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG5bdada9c69cd: [libc] Make libc memory functions weak by default for bazel (authored by gchatelet).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138999/new/

https://reviews.llvm.org/D138999

Files:
  utils/bazel/llvm-project-overlay/libc/BUILD.bazel
  utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl


Index: utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl
===================================================================
--- utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl
+++ utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl
@@ -10,7 +10,7 @@
 LIBC_ROOT_TARGET = ":libc_root"
 INTERNAL_SUFFIX = ".__internal__"
 
-def libc_function(name, srcs, deps = None, copts = None, **kwargs):
+def libc_function(name, srcs, weak = False, deps = None, copts = None, **kwargs):
     """Add target for a libc function.
 
     The libc function is eventually available as a cc_library target by name
@@ -23,6 +23,7 @@
       name: Target name. It is normally the name of the function this target is
             for.
       srcs: The .cpp files which contain the function implementation.
+      weak: Whether the symbol is marked weak.
       deps: The list of target dependencies if any.
       copts: The list of options to add to the C++ compilation command.
       **kwargs: Other attributes relevant for a cc_library. For example, deps.
@@ -47,6 +48,8 @@
 
     # This second target is the llvm libc C function.
     copts.append("-DLLVM_LIBC_PUBLIC_PACKAGING")
+    if weak:
+        copts.append("-DLLVM_LIBC_FUNCTION_ATTR=__attribute__((weak))")
     native.cc_library(
         name = name,
         srcs = srcs,
Index: utils/bazel/llvm-project-overlay/libc/BUILD.bazel
===================================================================
--- utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -1096,6 +1096,7 @@
     hdrs = ["src/string/memcpy.h"],
     copts = ["-mllvm --tail-merge-threshold=0"],
     features = no_sanitize_features,
+    weak = True,
     deps = [
         ":__support_common",
         ":string_memory_utils",
@@ -1107,6 +1108,7 @@
     srcs = ["src/string/memset.cpp"],
     hdrs = ["src/string/memset.h"],
     features = no_sanitize_features,
+    weak = True,
     deps = [
         ":__support_common",
         ":string_memory_utils",
@@ -1118,6 +1120,7 @@
     srcs = ["src/string/memmove.cpp"],
     hdrs = ["src/string/memmove.h"],
     features = no_sanitize_features,
+    weak = True,
     deps = [
         ":__support_common",
         ":string_memory_utils",
@@ -1140,6 +1143,7 @@
     srcs = ["src/string/memcmp.cpp"],
     hdrs = ["src/string/memcmp.h"],
     features = no_sanitize_features,
+    weak = True,
     deps = [
         ":__support_common",
         ":__support_integer_operations",
@@ -1152,6 +1156,7 @@
     srcs = ["src/string/bcmp.cpp"],
     hdrs = ["src/string/bcmp.h"],
     features = no_sanitize_features,
+    weak = True,
     deps = [
         ":__support_common",
         ":string_memory_utils",
@@ -1163,6 +1168,7 @@
     srcs = ["src/string/bzero.cpp"],
     hdrs = ["src/string/bzero.h"],
     features = no_sanitize_features,
+    weak = True,
     deps = [
         ":__support_common",
         ":string_memory_utils",


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138999.479542.patch
Type: text/x-patch
Size: 2977 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221202/044541b7/attachment.bin>


More information about the llvm-commits mailing list