diff options
author | Juan Yescas <jyescas@google.com> | 2023-11-10 19:53:13 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-11-10 19:53:13 +0000 |
commit | 5a386cf25818bc19d738e325510e2a996c1155fa (patch) | |
tree | de89ddb9e66763e573c0a8a458ae3add4dcf5353 | |
parent | 330d28ec2492677be5dbeded0d72daa7a337e736 (diff) | |
parent | bb1f8ff6a0beae916d77215709eef12fc8c0d97f (diff) | |
download | bazel-5a386cf25818bc19d738e325510e2a996c1155fa.tar.gz |
16k: bazel: Add linker flag -Wl,-z,max-page-size for x86-84 to align binaries and .so am: 897596c9b9 am: bb1f8ff6a0
Original change: https://android-review.googlesource.com/c/platform/build/bazel/+/2824869
Change-Id: Id13d35f25c31d8c3444a9797ca534d3264ca8ab5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
3 files changed, 80 insertions, 18 deletions
diff --git a/tests/products/product_labels.bzl b/tests/products/product_labels.bzl index d70dc689..8b9d4018 100644 --- a/tests/products/product_labels.bzl +++ b/tests/products/product_labels.bzl @@ -1,3 +1,19 @@ +# Copyright (C) 2023 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Product definitions for Android's C/C++ toolchain.""" + load("@//build/bazel/tests/products:aosp_arm.variables.bzl", _soong_variables_arm = "variables") load("@//build/bazel/tests/products:aosp_arm64.variables.bzl", _soong_variables_arm64 = "variables") load("@//build/bazel/tests/products:aosp_x86.variables.bzl", _soong_variables_x86 = "variables") @@ -55,6 +71,10 @@ products = { {"CFIExcludePaths": ["build/bazel/rules/cc"]}, ), "aosp_x86_64_for_testing": _soong_variables_x86_64, + "aosp_x86_64_for_testing_custom_linker_alignment": dicts.add( + _soong_variables_x86_64, + {"DeviceMaxPageSizeSupported": "65536"}, + ), "aosp_arm64_for_testing_min_sdk_version_override_tiramisu": dicts.add( _soong_variables_arm64, {"ApexGlobalMinSdkVersionOverride": "Tiramisu"}, diff --git a/toolchains/clang/host/linux-x86/cc_toolchain_features.bzl b/toolchains/clang/host/linux-x86/cc_toolchain_features.bzl index 63632f79..7f41f394 100644 --- a/toolchains/clang/host/linux-x86/cc_toolchain_features.bzl +++ b/toolchains/clang/host/linux-x86/cc_toolchain_features.bzl @@ -2172,6 +2172,7 @@ def _manual_binder_interface_feature(): ) # Create the full list of features. +# buildifier: disable=function-docstring def get_features( ctx, builtin_include_dirs, @@ -2181,10 +2182,10 @@ def get_features( target_flags = ctx.attr.target_flags compile_only_flags = ctx.attr.compiler_flags linker_only_flags = ctx.attr.linker_flags - deviceMaxPageSize = ctx.attr._device_max_page_size_supported[BuildSettingInfo].value - if deviceMaxPageSize and target_arch == "arm64": + device_max_page_size = ctx.attr._device_max_page_size_supported[BuildSettingInfo].value + if device_max_page_size and (target_arch == "arm64" or target_arch == "x86_64"): linker_only_flags = ctx.attr.linker_flags + \ - ["-Wl,-z,max-page-size=" + deviceMaxPageSize] + ["-Wl,-z,max-page-size=" + device_max_page_size] libclang_rt_builtin = ctx.file.libclang_rt_builtin libclang_rt_ubsan_minimal = ctx.file.libclang_rt_ubsan_minimal diff --git a/toolchains/clang/host/linux-x86/cc_toolchain_features_linker_alignment_test.bzl b/toolchains/clang/host/linux-x86/cc_toolchain_features_linker_alignment_test.bzl index 44b03191..633697b2 100644 --- a/toolchains/clang/host/linux-x86/cc_toolchain_features_linker_alignment_test.bzl +++ b/toolchains/clang/host/linux-x86/cc_toolchain_features_linker_alignment_test.bzl @@ -16,7 +16,8 @@ limitations under the License. load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") def _test_linker_alignment_flag_impl(ctx): - """ + """ Checks that linker alignment flag is present. + This test checks that the linker alignment flag is present for arm and arm 64 targets but it is not present for x86 and x86_64 targets. """ @@ -94,6 +95,14 @@ custom_linker_alignment_flag_arm64_test = analysistest.make( }, ) +custom_linker_alignment_flag_x86_64_test = analysistest.make( + impl = _test_linker_alignment_flag_impl, + attrs = test_attrs, + config_settings = { + "//command_line_option:platforms": "@//build/bazel/tests/products:aosp_x86_64_for_testing_custom_linker_alignment", + }, +) + linker_alignment_flag_x86_test = analysistest.make( impl = _test_linker_alignment_flag_impl, attrs = test_attrs, @@ -110,7 +119,9 @@ linker_alignment_flag_x86_64_test = analysistest.make( }, ) -def test_linker_alignment_flag_arm(): +def _test_linker_alignment_flag_arm(): + """ Checks that max-page-size flag is not present for arm targets. + """ name = "linker_alignment_flag_arm" test_name = name + "_test" @@ -133,7 +144,9 @@ def test_linker_alignment_flag_arm(): ) return test_name -def test_linker_alignment_flag_arm64(): +def _test_linker_alignment_flag_arm64(): + """ Checks that max-page-size flag is present for arm64 targets. + """ name = "linker_alignment_flag_arm64" test_name = name + "_test" @@ -154,7 +167,9 @@ def test_linker_alignment_flag_arm64(): ) return test_name -def test_custom_linker_alignment_flag_arm64(): +def _test_custom_linker_alignment_flag_arm64(): + """ Checks that max-page-size flag has the custom alignment for arm64. + """ name = "custom_linker_alignment_flag_arm64" test_name = name + "_test" @@ -175,7 +190,9 @@ def test_custom_linker_alignment_flag_arm64(): ) return test_name -def test_linker_alignment_flag_x86(): +def _test_linker_alignment_flag_x86(): + """ Checks that max-page-size flag is not present for x86. + """ name = "linker_alignment_flag_x86" test_name = name + "_test" @@ -198,7 +215,9 @@ def test_linker_alignment_flag_x86(): ) return test_name -def test_linker_alignment_flag_x86_64(): +def _test_linker_alignment_flag_x86_64(): + """ Checks that max-page-size flag is present for x86_64. + """ name = "linker_alignment_flag_x86_64" test_name = name + "_test" @@ -211,13 +230,34 @@ def test_linker_alignment_flag_x86_64(): linker_alignment_flag_x86_64_test( name = test_name, target_under_test = name, - expected_action_mnemonics = ["CppCompile", "CppLink"], - expected_flags = [], - no_expected_flags = [ + expected_action_mnemonics = ["CppLink"], + expected_flags = [ "-Wl,-z,max-page-size=4096", - "-Wl,-z,max-page-size=16384", + ], + no_expected_flags = [], + ) + return test_name + +def _test_custom_linker_alignment_flag_x86_64(): + """ Checks that max-page-size flag has the custom alignment for x86_64. + """ + name = "custom_linker_alignment_flag_x86_64" + test_name = name + "_test" + + native.cc_binary( + name = name, + srcs = ["foo.cpp"], + tags = ["manual"], + ) + + custom_linker_alignment_flag_x86_64_test( + name = test_name, + target_under_test = name, + expected_action_mnemonics = ["CppLink"], + expected_flags = [ "-Wl,-z,max-page-size=65536", ], + no_expected_flags = [], ) return test_name @@ -225,10 +265,11 @@ def cc_toolchain_features_linker_alignment_test_suite(name): native.test_suite( name = name, tests = [ - test_linker_alignment_flag_arm(), - test_linker_alignment_flag_arm64(), - test_custom_linker_alignment_flag_arm64(), - test_linker_alignment_flag_x86(), - test_linker_alignment_flag_x86_64(), + _test_linker_alignment_flag_arm(), + _test_linker_alignment_flag_arm64(), + _test_custom_linker_alignment_flag_arm64(), + _test_linker_alignment_flag_x86(), + _test_linker_alignment_flag_x86_64(), + _test_custom_linker_alignment_flag_x86_64(), ], ) |