[llvm-branch-commits] [libc] [llvm] [libc][bazel] Add targets for startup objects on linux (PR #218995)

Alexey Samsonov via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Aug 27 14:50:34 PDT 2026


================
@@ -75,21 +75,46 @@ def libc_release_copts():
     })
     return copts + platform_copts
 
-def _libc_library(name, deps = [], **kwargs):
+# Allowlisted sets of copts that may be used for a single libc library target.
+# Adding copts here is discouraged, as it complicates the build.
+_LIBC_LIBRARY_COPT_SETS = {
+    "startup_object": [
+        "-ffreestanding",
+        "-fno-builtin",
+        "-fno-omit-frame-pointer",
+        "-fno-stack-protector",
+    ],
+    "threading": [
+        "-fno-omit-frame-pointer",
+        "-Wno-frame-address",
+    ],
+}
+
+def _libc_library(
+        name,
+        deps = [],
+        copt_sets = [],
+        **kwargs):
     """Internal macro to serve as a base for all other libc library rules.
 
     Args:
       name: Target name.
       deps: cc_library deps.
+      copt_sets: Which sets of allow-listed copts to include.
       **kwargs: All other attributes relevant for the cc_library rule.
     """
 
     for attr in ["copts", "local_defines"]:
         if attr in kwargs:
             fail("disallowed attribute: '{}' in rule: '{}'".format(attr, name))
+
+    copts = []
+    for feature in copt_sets:
+        copts.extend(_LIBC_LIBRARY_COPT_SETS[feature])
----------------
vonosmas wrote:

This will fail if the feature is unknown, right?

https://github.com/llvm/llvm-project/pull/218995


More information about the llvm-branch-commits mailing list