aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuliano Procida <gprocida@google.com>2024-05-10 07:34:39 +0100
committerGiuliano Procida <gprocida@google.com>2024-05-10 07:34:39 +0100
commit6007ac729006c2bb7b38a31a816e30572f46f07d (patch)
tree5741024c4bf04343dbcd9b85be0033d6d42576d1
parent03ab09f3cb3ff287985df9aabcd812b7890a09ce (diff)
parent5adbe8ef91fc7932683d3f88ece819bc695e56af (diff)
downloadstg-main.tar.gz
Merge branch 'upstream-main' into 'main'HEADmastermain
* aosp/upstream-main: CMake build: add dependency version information CMake build: add check for Linux UAPI headers rust: add a test case for tagged enum with negative discriminant Signed-off-by: Giuliano Procida <gprocida@google.com> Change-Id: I565348756b71a48c1a87e7682382725c8176f627
-rw-r--r--CMakeLists.txt11
-rw-r--r--README.md26
-rw-r--r--cmake/FindLinuxUAPI.cmake55
-rw-r--r--test_cases/info_tests/variant/expected/negative_discriminant_rs.elf_stg33
-rw-r--r--test_cases/info_tests/variant/negative_discriminant.rs14
5 files changed, 121 insertions, 18 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 38bb294..f28e0d5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -49,10 +49,11 @@ set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
-find_package(LibElf REQUIRED)
-find_package(LibDw REQUIRED)
-find_package(LibXml2 REQUIRED)
-find_package(Protobuf REQUIRED)
+find_package(LibElf 0.189 REQUIRED)
+find_package(LibDw 0.189 REQUIRED)
+find_package(LibXml2 2.9 REQUIRED)
+find_package(LinuxUAPI 5.19 REQUIRED)
+find_package(Protobuf 3.19 REQUIRED)
if(NOT Protobuf_PROTOC_EXECUTABLE)
message(FATAL_ERROR "Could NOT find protobuf::protoc.
@@ -66,7 +67,7 @@ set(COMMON_LIBRARIES
protobuf::libprotobuf)
if(NOT Jemalloc_DISABLE)
- find_package(Jemalloc)
+ find_package(Jemalloc 5)
if(Jemalloc_FOUND)
list(APPEND COMMON_LIBRARIES Jemalloc::Jemalloc)
else()
diff --git a/README.md b/README.md
index 9906ce8..969c4ca 100644
--- a/README.md
+++ b/README.md
@@ -38,19 +38,19 @@ Instructions are included for local and Docker builds.
### Dependencies
STG is written in C++20. It is known to compile with GCC 11, Clang 15 or
-later versions.
-
-| *Dependency* | *Debian* | *RedHat* |
-| ------------- | ----------------- | ----------------- |
-| build | cmake | cmake |
-| ELF, BTF | libelf-dev | elfutils-devel |
-| DWARF | libdw-dev | elfutils-devel |
-| XML | libxml2-dev | libxml2-devel |
-| BTF | linux-libc-dev | kernel-headers |
-| native format | libprotobuf-dev | protobuf-devel |
-| native format | protobuf-compiler | protobuf-compiler |
-| allocator[^1] | libjemalloc-dev | jemalloc-devel |
-| catch2[^2] | catch2 | catch2-devel |
+later versions. Mininum requirements for a local build are:
+
+| *Dependency* | *Debian* | *RedHat* | *Version* |
+| ------------- | ----------------- | ----------------- | --------- |
+| build | cmake | cmake | 3.14 |
+| ELF, BTF | libelf-dev | elfutils-devel | 0.189 |
+| DWARF | libdw-dev | elfutils-devel | 0.189 |
+| XML | libxml2-dev | libxml2-devel | 2.9 |
+| BTF | linux-libc-dev | kernel-headers | 5.19 |
+| native format | libprotobuf-dev | protobuf-devel | 3.19 |
+| native format | protobuf-compiler | protobuf-compiler | 3.19 |
+| allocator[^1] | libjemalloc-dev | jemalloc-devel | 5 |
+| catch2[^2] | catch2 | catch2-devel | 2 (only) |
[^1]: jemalloc is optional, but will likely improve performance.
[^2]: catch2 is optional, but required to build the test suite.
diff --git a/cmake/FindLinuxUAPI.cmake b/cmake/FindLinuxUAPI.cmake
new file mode 100644
index 0000000..b662f3e
--- /dev/null
+++ b/cmake/FindLinuxUAPI.cmake
@@ -0,0 +1,55 @@
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+# Copyright 2024 Google LLC
+#
+# Licensed under the Apache License v2.0 with LLVM Exceptions (the "License");
+# you may not use this file except in compliance with the License. You may
+# obtain a copy of the License at
+#
+# https://llvm.org/LICENSE.txt
+#
+# 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.
+#
+# Author: Giuliano Procida
+
+#[=======================================================================[.rst:
+FindLinuxUAPI
+-------------
+
+Finds the Linux UAPI headers.
+
+Result Variables
+^^^^^^^^^^^^^^^^
+
+This will define the following variables:
+
+``LinuxUAPI_FOUND``
+ True if the system has the Linux UAPI headers.
+``LinuxUAPI_INCLUDE_DIR``
+ The Linux UAPI include directory.
+``LinuxUAPI_VERSION``
+ The version of the Linux UAPI headers which were found.
+
+#]=======================================================================]
+
+find_path(
+ LinuxUAPI_INCLUDE_DIR
+ linux/version.h
+)
+mark_as_advanced(LinuxUAPI_INCLUDE_DIR)
+
+if(LinuxUAPI_INCLUDE_DIR)
+ file(READ "${LinuxUAPI_INCLUDE_DIR}/linux/version.h" _version_header)
+ string(REGEX REPLACE ".*#define LINUX_VERSION_MAJOR ([0-9]+).*#define LINUX_VERSION_PATCHLEVEL ([0-9]+).*#define LINUX_VERSION_SUBLEVEL ([0-9]+).*" "\\1.\\2.\\3" LinuxUAPI_VERSION "${_version_header}")
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(
+ LinuxUAPI
+ REQUIRED_VARS LinuxUAPI_INCLUDE_DIR
+ VERSION_VAR LinuxUAPI_VERSION
+)
diff --git a/test_cases/info_tests/variant/expected/negative_discriminant_rs.elf_stg b/test_cases/info_tests/variant/expected/negative_discriminant_rs.elf_stg
new file mode 100644
index 0000000..debfaf8
--- /dev/null
+++ b/test_cases/info_tests/variant/expected/negative_discriminant_rs.elf_stg
@@ -0,0 +1,33 @@
+version: 0x00000002
+root_id: 0x84ea5130 # interface
+primitive {
+ id: 0x62aebfd4
+ name: "bool"
+ encoding: BOOLEAN
+ bytesize: 0x00000001
+}
+struct_union {
+ id: 0x7a8d8645
+ kind: STRUCT
+ name: "negative_discriminant::Foo"
+ definition {
+ bytesize: 16
+ }
+}
+function {
+ id: 0xa0f30a2f
+ return_type_id: 0x62aebfd4 # bool
+ parameter_id: 0x7a8d8645 # struct negative_discriminant::Foo
+}
+elf_symbol {
+ id: 0x0f95dadc
+ name: "is_minus_one"
+ is_defined: true
+ symbol_type: FUNCTION
+ type_id: 0xa0f30a2f # bool(struct negative_discriminant::Foo)
+ full_name: "negative_discriminant::is_minus_one"
+}
+interface {
+ id: 0x84ea5130
+ symbol_id: 0x0f95dadc # bool negative_discriminant::is_minus_one(struct negative_discriminant::Foo)
+}
diff --git a/test_cases/info_tests/variant/negative_discriminant.rs b/test_cases/info_tests/variant/negative_discriminant.rs
new file mode 100644
index 0000000..0a51235
--- /dev/null
+++ b/test_cases/info_tests/variant/negative_discriminant.rs
@@ -0,0 +1,14 @@
+#[repr(i64)]
+pub enum Foo {
+ MinusTwo(u32) = -2,
+ MinusOne = -1,
+ Zero(u32),
+}
+
+#[no_mangle]
+pub fn is_minus_one(foo: Foo) -> bool {
+ match foo {
+ Foo::MinusOne => true,
+ _ => false,
+ }
+}