gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/pkg/sentry/platform/systrap/sysmsg/BUILD (about)

     1  load("//tools:arch.bzl", "arch_genrule", "select_arch")
     2  load("//tools:defs.bzl", "cc_flags_supplier", "cc_toolchain", "go_library")
     3  load("build.bzl", "cc_pie_obj")
     4  
     5  package(
     6      default_applicable_licenses = ["//:license"],
     7      licenses = ["notice"],
     8  )
     9  
    10  cc_flags_supplier(
    11      name = "no_pie_cc_flags",
    12      features = ["-pie"],
    13  )
    14  
    15  cc_pie_obj(
    16      name = "sighandler",
    17      srcs = select_arch(
    18          amd64 = [
    19              "sighandler_amd64.c",
    20              "sysmsg_offsets_amd64.h",
    21          ],
    22          arm64 = ["sighandler_arm64.c"],
    23      ) + [
    24          "atomic.h",
    25          "sysmsg.h",
    26          "sysmsg_offsets.h",
    27      ],
    28      outs = ["sighandler.o"],
    29  )
    30  
    31  cc_pie_obj(
    32      name = "sysmsg_lib",
    33      srcs = [
    34          "atomic.h",
    35          "sysmsg.h",
    36          "sysmsg_lib.c",
    37          "sysmsg_offsets.h",
    38      ],
    39      outs = ["sysmsg_lib.o"],
    40  )
    41  
    42  cc_pie_obj(
    43      name = "sysrestorer",
    44      srcs = select_arch(
    45          amd64 = ["sigrestorer_amd64.S"],
    46          arm64 = ["sigrestorer_arm64.S"],
    47      ),
    48      outs = ["sysrestorer.o"],
    49  )
    50  
    51  cc_pie_obj(
    52      name = "syshandler",
    53      srcs = select_arch(
    54          amd64 = [
    55              "syshandler_amd64.S",
    56              "sysmsg_offsets_amd64.h",
    57          ],
    58          arm64 = ["syshandler_arm64.S"],
    59      ) + [
    60          "sysmsg_offsets.h",
    61      ],
    62      outs = ["syshandler.o"],
    63  )
    64  
    65  genrule(
    66      name = "sighandler_object",
    67      srcs = [
    68          "pie.lds.S",
    69          ":sighandler",
    70          ":syshandler",
    71          ":sysrestorer",
    72          ":sysmsg_lib",
    73      ],
    74      outs = ["sighandler.built-in.bin.o"],
    75      cmd = "$(LD) " +
    76            "-pie -z noexecstack -T $(location pie.lds.S) " +
    77            "$(location :sysrestorer) $(location :sighandler) " +
    78            "$(location :syshandler) $(location :sysmsg_lib) " +
    79            "-o $@",
    80      features = ["-pie"],
    81      toolchains = [
    82          cc_toolchain,
    83      ],
    84  )
    85  
    86  genrule(
    87      name = "sighandler_binary",
    88      srcs = [":sighandler_object"],
    89      outs = ["sighandler.built-in.bin"],
    90      cmd = "$(OBJCOPY) -O binary $(SRCS) $@",
    91      toolchains = [
    92          cc_toolchain,
    93      ],
    94  )
    95  
    96  arch_genrule(
    97      name = "sighandler_binary_arch",
    98      src = ":sighandler_binary",
    99      template = "sighandler.built-in.%s.bin",
   100  )
   101  
   102  genrule(
   103      name = "sighandler_go",
   104      srcs = [":sighandler_object"],
   105      outs = ["sighandler.go.arch"],
   106      cmd = "bash -x $(location gen_offsets_go.sh) sighandler Sighandler " +
   107            "$(SRCS) > $@",
   108      tools = ["gen_offsets_go.sh"],
   109  )
   110  
   111  arch_genrule(
   112      name = "sighandler_go_arch",
   113      src = ":sighandler_go",
   114      template = "sighandler_%s.go",
   115  )
   116  
   117  go_library(
   118      name = "sysmsg",
   119      srcs = [
   120          "sysmsg.go",
   121          "sysmsg_amd64.go",
   122          "sysmsg_arm64.go",
   123          "sysmsg_unsafe.go",
   124          ":sighandler_go_arch",
   125      ],
   126      embedsrcs = [
   127          ":sighandler_binary_arch",  # keep
   128      ],
   129      visibility = ["//:sandbox"],
   130      deps = [
   131          "//pkg/abi/linux",
   132          "//pkg/cpuid",
   133          "//pkg/hostarch",
   134          "//pkg/sentry/platform",
   135          "@org_golang_x_sys//unix:go_default_library",
   136      ],
   137  )