[libclc] [libclc] use default paths with find_program when possible (PR #105969)
https://github.com/RossComputerGuy created https://github.com/llvm/llvm-project/pull/105969 Patch pulled from https://github.com/NixOS/nixpkgs/pull/336465 This PR removes `NO_DEFAULT_PATH` where possible, the flag prevents Nix from building libclc correctly. >From e8b910246d0c7c3d9fff994f71c6f8a48ec09a50 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Sat, 24 Aug 2024 19:56:24 -0700 Subject: [PATCH] [libclc] use default paths with find_program when possible --- libclc/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index 02bb859ae8590b..6bcd8ae52a5794 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -55,7 +55,7 @@ if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DI # Import required tools if( NOT EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} ) foreach( tool IN ITEMS clang llvm-as llvm-link opt ) - find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) + find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} ) set( ${tool}_exe ${LLVM_TOOL_${tool}} ) set( ${tool}_target ) endforeach() @@ -104,7 +104,7 @@ foreach( tool IN ITEMS clang opt llvm-as llvm-link ) endforeach() # llvm-spirv is an optional dependency, used to build spirv-* targets. -find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) +find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} ) if( LLVM_SPIRV ) add_executable( libclc::llvm-spirv IMPORTED GLOBAL ) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] use default paths with find_program when possible (PR #105969)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/105969 >From 056e0f9b7c7b788ad0d85a1479000fd1af4f98ce Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Sat, 24 Aug 2024 19:56:24 -0700 Subject: [PATCH] [libclc] use default paths with find_program when possible --- libclc/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt index 1bf7eb2ca7ed7e..2b3a4e6a6c1043 100644 --- a/libclc/CMakeLists.txt +++ b/libclc/CMakeLists.txt @@ -55,7 +55,7 @@ if( LIBCLC_STANDALONE_BUILD OR CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DI # Import required tools if( NOT EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} ) foreach( tool IN ITEMS clang llvm-as llvm-link opt ) - find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) +find_program( LLVM_TOOL_${tool} ${tool} PATHS ${LLVM_TOOLS_BINARY_DIR} ) set( ${tool}_exe ${LLVM_TOOL_${tool}} ) set( ${tool}_target ) endforeach() @@ -91,7 +91,7 @@ if( EXISTS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} ) # and custom tools. foreach( tool IN ITEMS clang llvm-as llvm-link opt ) find_program( LLVM_CUSTOM_TOOL_${tool} ${tool} - PATHS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) + PATHS ${LIBCLC_CUSTOM_LLVM_TOOLS_BINARY_DIR} ) set( ${tool}_exe ${LLVM_CUSTOM_TOOL_${tool}} ) set( ${tool}_target ) endforeach() @@ -108,7 +108,7 @@ endforeach() if( TARGET llvm-spirv ) get_host_tool_path( llvm-spirv LLVM_SPIRV llvm-spirv_exe llvm-spirv_target ) else() - find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH ) + find_program( LLVM_SPIRV llvm-spirv PATHS ${LLVM_TOOLS_BINARY_DIR} ) set( llvm-spirv_exe "${LLVM_SPIRV}" ) set( llvm-spirv_target ) endif() ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Include LLVM CodeGen CMake file (PR #109601)
https://github.com/RossComputerGuy created https://github.com/llvm/llvm-project/pull/109601 Fixes a build failure with Clang being built from standalone sources (environments like Nix). Exact error: ``` CMake Error at /nix/store/h9yw8mg03z3dz6rgcjr7gbzkjysqc2sj-llvm-20.0.0-unstable-2024-09-22-dev/lib/cmake/llvm/AddLLVM.cmake:587 (add_dependencies): The dependency target "vt_gen" of target "obj.clangCodeGen" does not exist. Call Stack (most recent call first): cmake/modules/AddClang.cmake:109 (llvm_add_library) lib/CodeGen/CMakeLists.txt:57 (add_clang_library) CMake Error at /nix/store/h9yw8mg03z3dz6rgcjr7gbzkjysqc2sj-llvm-20.0.0-unstable-2024-09-22-dev/lib/cmake/llvm/AddLLVM.cmake:807 (add_dependencies): The dependency target "vt_gen" of target "clangCodeGen" does not exist. Call Stack (most recent call first): cmake/modules/AddClang.cmake:109 (llvm_add_library) lib/CodeGen/CMakeLists.txt:57 (add_clang_library) ``` This fix can be reproduced via the following script (just set out to some remote source and monorepoSrc to your LLVM source dir): ``` mkdir -p "$out" cp -r ${monorepoSrc}/cmake "$out" cp -r ${monorepoSrc}/${pname} "$out" cp -r ${monorepoSrc}/clang-tools-extra "$out" mkdir -p "$out/llvm/include/llvm/CodeGen" cp -r ${monorepoSrc}/llvm/include/llvm/CodeGen/CMakeLists.txt "$out/llvm/include/llvm/CodeGen/" mkdir -p "$out/clang/include/llvm" cp -r ${monorepoSrc}/llvm/include/llvm/CodeGen $out/clang/include/llvm/CodeGen ``` >From a64ba9cc4f2c70f6040c1954fedc5674bba96575 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Sun, 22 Sep 2024 21:02:12 -0700 Subject: [PATCH] [Clang] Include LLVM CodeGen CMake file --- clang/lib/CodeGen/CMakeLists.txt | 4 1 file changed, 4 insertions(+) diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt index 868ec847b9634b..2b1be3f4c3035d 100644 --- a/clang/lib/CodeGen/CMakeLists.txt +++ b/clang/lib/CodeGen/CMakeLists.txt @@ -1,3 +1,7 @@ +if(EXISTS ${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen) + add_subdirectory(${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen llvm/lib/CodeGen) +endif() + set(LLVM_LINK_COMPONENTS AggressiveInstCombine Analysis ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Include LLVM CodeGen CMake file (PR #109601)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/109601 >From cab2a5cebdc63425ed03a31028e6eb2aee00e5d9 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Sun, 22 Sep 2024 21:02:12 -0700 Subject: [PATCH] [Clang] Include LLVM CodeGen CMake file --- clang/lib/CodeGen/CMakeLists.txt | 4 1 file changed, 4 insertions(+) diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt index 868ec847b9634b..351a606f65b5be 100644 --- a/clang/lib/CodeGen/CMakeLists.txt +++ b/clang/lib/CodeGen/CMakeLists.txt @@ -1,3 +1,7 @@ +if(EXISTS ${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen AND CLANG_BUILT_STANDALONE) + add_subdirectory(${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen llvm/lib/CodeGen) +endif() + set(LLVM_LINK_COMPONENTS AggressiveInstCombine Analysis ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Include LLVM CodeGen CMake file (PR #109601)
@@ -1,3 +1,7 @@ +if(EXISTS ${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen AND CLANG_BUILT_STANDALONE) RossComputerGuy wrote: Ok, will do. https://github.com/llvm/llvm-project/pull/109601 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Include LLVM CodeGen CMake file (PR #109601)
@@ -1,3 +1,7 @@ +if(EXISTS ${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen AND CLANG_BUILT_STANDALONE) + add_subdirectory(${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen llvm/lib/CodeGen) +endif() RossComputerGuy wrote: I'm not sure, are you meaning to use `LLVM_DIR` instead of `LLVM_MAIN_SRC_DIR`? https://github.com/llvm/llvm-project/pull/109601 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] use default paths with find_program when possible (PR #105969)
RossComputerGuy wrote: > IMO libclc should not support the standalone build, and this should be > version locked to the exact compiler commit. So it should be built along with the core of LLVM? Also, we package LLVM per version per subproject. > could this be avoided by changing the Nixpkgs build to install symlinks to > all needed tools in a single directory (possibly a temporary directory > populated during the libclc build), and making that directory available as > `LLVM_TOOLS_BINARY_DIR`? Maybe, although that sounds a bit hacky. https://github.com/llvm/llvm-project/pull/105969 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] use default paths with find_program when possible (PR #105969)
RossComputerGuy wrote: > Apologies, but I'm having a bit of trouble understanding the scenario that > this PR addresses. Nixpkgs adds the tools being used to `$PATH` so find program needs to use path. https://github.com/llvm/llvm-project/pull/105969 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] use default paths with find_program when possible (PR #105969)
RossComputerGuy wrote: > The nix build should probably migrate to using the non-standalone build Nixpkgs has no intention of moving away from standalone builds. https://github.com/llvm/llvm-project/pull/105969 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libclc] [libclc] use default paths with find_program when possible (PR #105969)
RossComputerGuy wrote: > Yes, it should be built along with the core (but doesn't need to ship in the > same package as the core). Sounds good, I'll communicate with the other LLVM Nix maintainers and see if this is a good idea to fully go ahead on. https://github.com/llvm/llvm-project/pull/105969 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Replace vt_gen with LLVMCodeGenTypes (PR #109601)
https://github.com/RossComputerGuy closed https://github.com/llvm/llvm-project/pull/109601 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Replace vt_gen with LLVMCodeGenTypes (PR #109601)
RossComputerGuy wrote: Replaced by #109817 https://github.com/llvm/llvm-project/pull/109601 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Replace vt_gen with LLVMCodeGenTypes (PR #109601)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/109601 >From b97cb5af6dbf92edeeceedac38d0b657e3856fbe Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Sun, 22 Sep 2024 21:02:12 -0700 Subject: [PATCH] [Clang] Replace vt_gen with LLVMCodeGenTypes --- clang/lib/CodeGen/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt index 868ec847b9634b..372e944cfa1082 100644 --- a/clang/lib/CodeGen/CMakeLists.txt +++ b/clang/lib/CodeGen/CMakeLists.txt @@ -31,6 +31,7 @@ set(LLVM_LINK_COMPONENTS Target TargetParser TransformUtils + CodeGenTypes ) # Workaround for MSVC ARM64 performance regression: @@ -144,7 +145,6 @@ add_clang_library(clangCodeGen VarBypassDetector.cpp DEPENDS - vt_gen intrinsics_gen ClangDriverOptions # These generated headers are included transitively. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Replace vt_gen with LLVMCodeGenTypes (PR #109601)
RossComputerGuy wrote: You're welcome, though it looks like CI is borked. ``` ld.lld: error: unable to find library -lLLVMLLVMCodeGenTypes clang: error: linker command failed with exit code 1 (use -v to see invocation) ``` I've changed it from `LLVMCodeGenTypes` to `CodeGenTypes` so hopefully CI passes now. https://github.com/llvm/llvm-project/pull/109601 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Include LLVM CodeGen CMake file (PR #109601)
@@ -1,3 +1,7 @@ +if(EXISTS ${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen AND CLANG_BUILT_STANDALONE) + add_subdirectory(${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen llvm/lib/CodeGen) +endif() RossComputerGuy wrote: I'm not exactly sure what you're meaning. https://github.com/llvm/llvm-project/pull/109601 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Include LLVM CodeGen CMake file (PR #109601)
RossComputerGuy wrote: > The `add_subdirectory` is definitely odd and I'm not sure if that is a proper > solution. I'm not familiar with how LLVM CodeGen works and I am a bit new to LLVM but I looked at [`clang/CMakeLists.txt`](https://github.com/llvm/llvm-project/blob/d61b2590f8e360695a5298311855c8649337969f/clang/CMakeLists.txt#L111-L123) and so I basically just copied this `add_directories`. https://github.com/llvm/llvm-project/pull/109601 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Include LLVM CodeGen CMake file (PR #109601)
@@ -1,3 +1,7 @@ +if(EXISTS ${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen AND CLANG_BUILT_STANDALONE) + add_subdirectory(${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen llvm/lib/CodeGen) +endif() RossComputerGuy wrote: Ok, so the solution is to set `-DLLVM_DIR` which is done by `find_package`? We already have LLVM inside Clang's CMake search path so I am not sure why the error in the PR toplevel comment is happening. https://github.com/llvm/llvm-project/pull/109601 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Replace vt_gen with LLVMCodeGenTypes (PR #109601)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/109601 >From 6902072452f92d8893b42dc7ef32fb610a579f8d Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Sun, 22 Sep 2024 21:02:12 -0700 Subject: [PATCH] [Clang] Replace vt_gen with LLVMCodeGenTypes --- clang/lib/CodeGen/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt index 868ec847b9634b..aa0c871c5352a8 100644 --- a/clang/lib/CodeGen/CMakeLists.txt +++ b/clang/lib/CodeGen/CMakeLists.txt @@ -144,7 +144,6 @@ add_clang_library(clangCodeGen VarBypassDetector.cpp DEPENDS - vt_gen intrinsics_gen ClangDriverOptions # These generated headers are included transitively. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Replace vt_gen with LLVMCodeGenTypes (PR #109601)
@@ -31,6 +31,7 @@ set(LLVM_LINK_COMPONENTS Target TargetParser TransformUtils + LLVMCodeGenTypes RossComputerGuy wrote: Oh, didn't realize that. https://github.com/llvm/llvm-project/pull/109601 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Replace vt_gen with LLVMCodeGenTypes (PR #109601)
@@ -31,6 +31,7 @@ set(LLVM_LINK_COMPONENTS Target TargetParser TransformUtils + CodeGenTypes RossComputerGuy wrote: Removed. https://github.com/llvm/llvm-project/pull/109601 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Include LLVM CodeGen CMake file (PR #109601)
@@ -1,3 +1,7 @@ +if(EXISTS ${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen AND CLANG_BUILT_STANDALONE) + add_subdirectory(${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen llvm/lib/CodeGen) +endif() RossComputerGuy wrote: Looks like CMake accepted that change, let's see if it actually compiles. https://github.com/llvm/llvm-project/pull/109601 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] add llvm abi support (PR #121123)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/121123 >From 23922b886739b2e298e4288dd53d6f59e8e2e86e Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Wed, 25 Dec 2024 14:38:30 -0800 Subject: [PATCH] [clang] add llvm abi support --- clang/lib/Driver/Driver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index dc84c1b9d1cc4e..98b8e6e97419c6 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1531,7 +1531,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { // Check if the environment version is valid except wasm case. llvm::Triple Triple = TC.getTriple(); - if (!Triple.isWasm()) { + if (!Triple.isWasm() && Triple.getEnvironment() != llvm::Triple::LLVM) { StringRef TripleVersionName = Triple.getEnvironmentVersionString(); StringRef TripleObjectFormat = Triple.getObjectFormatTypeName(Triple.getObjectFormat()); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] add llvm abi support (PR #121123)
@@ -1531,7 +1531,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { // Check if the environment version is valid except wasm case. llvm::Triple Triple = TC.getTriple(); - if (!Triple.isWasm()) { + if (!Triple.isWasm() && Triple.getEnvironment() != llvm::Triple::LLVM) { RossComputerGuy wrote: The problem I was running into was I'd get invalid version error. My assumption was that the LLVM ABI would not have a version because that would be the version of the entire LLVM stack. I didn't see any other ways when grepping the source that could disable the error. https://github.com/llvm/llvm-project/pull/121123 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] add llvm abi support (PR #121123)
RossComputerGuy wrote: Why close? LLVM libc is maturing and one of the goals I had was to try using it in Nixpkgs to build whatever I can. LLVM libc doesn't work well in an overlay mode so we have to use full builds. It's true that a lot of functions are still missing or not implemented but by having the ability to properly specify it can make it easier to find what to do next. Also, from what I can tell Clang and LLVM itself have already gotten some support for the ABI. This PR simply unblocks 1 error which makes the ABI usable. https://github.com/llvm/llvm-project/pull/121123 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] add llvm abi support (PR #121123)
RossComputerGuy wrote: > That said, I tend to agree with the review at [#121123 > (comment)](https://github.com/llvm/llvm-project/pull/121123#discussion_r1900548165) > that this doesn't seem like the right approach. Yeah I agree too, I'm not sure what the right approach is but that's one of the reasons why PR's get reviewed. https://github.com/llvm/llvm-project/pull/121123 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] add llvm abi support (PR #121123)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/121123 >From f5ef9c9fc9aac6058f5dd070f9e24932b4e4cf9a Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Wed, 25 Dec 2024 14:38:30 -0800 Subject: [PATCH] [clang] add llvm abi support --- clang/lib/Driver/Driver.cpp | 2 +- clang/test/Driver/invalid-version.cpp | 10 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index dc84c1b9d1cc4e..98b8e6e97419c6 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1531,7 +1531,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { // Check if the environment version is valid except wasm case. llvm::Triple Triple = TC.getTriple(); - if (!Triple.isWasm()) { + if (!Triple.isWasm() && Triple.getEnvironment() != llvm::Triple::LLVM) { StringRef TripleVersionName = Triple.getEnvironmentVersionString(); StringRef TripleObjectFormat = Triple.getObjectFormatTypeName(Triple.getObjectFormat()); diff --git a/clang/test/Driver/invalid-version.cpp b/clang/test/Driver/invalid-version.cpp index 6a4702a9b66b0f..15ba8a9616f86d 100644 --- a/clang/test/Driver/invalid-version.cpp +++ b/clang/test/Driver/invalid-version.cpp @@ -29,3 +29,13 @@ // RUN: FileCheck --check-prefix=CHECK-WASM1 %s // CHECK-WASM1: "-triple" "wasm32-unknown-wasi-pthread" + +// RUN: %clang --target=aarch64-unknown-linux-llvm -c %s -### 2>&1 | \ +// RUN: FileCheck --check-prefix=CHECK-AARCH64-LLVM %s + +// CHECK-AARCH64-LLVM: "-triple" "aarch64-unknown-linux-llvm" + +// RUN: %clang --target=x86_64-unknown-linux-llvm -c %s -### 2>&1 | \ +// RUN: FileCheck --check-prefix=CHECK-X86-64-LLVM %s + +// CHECK-X86-64-LLVM: "-triple" "x86_64-unknown-linux-llvm" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
RossComputerGuy wrote: > Should we have an entry for `-fdefine-target-os-macros` as well? I think so, it wouldn't be a bad idea. > Also needs a test I might need some guidance on adding a test since I'm not fully familiar with the clang side of LLVM. https://github.com/llvm/llvm-project/pull/120632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/120632 >From 2ee88359c3be20f3b6697bf75466fa44e7b10ab5 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 10:54:58 -0800 Subject: [PATCH 1/2] [clang] fix uefi data layout on x86 & aarch64 --- clang/lib/Basic/Targets/AArch64.cpp | 3 +++ clang/lib/Basic/Targets/X86.h | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index 53e102bbe44687..dd5d033afd8763 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -1537,6 +1537,9 @@ void AArch64leTargetInfo::setDataLayout() { resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-" "n32:64-S128-Fn32", "_"); + } else if (getTriple().isUEFI() && getTriple().isOSBinFormatCOFF()) { +resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-" +"i64:64-i128:128-n32:64-S128-Fn32"); } else resetDataLayout("e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-" "i64:64-i128:128-n32:64-S128-Fn32"); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 3ed36c8fa724b5..1d6fe468af3be1 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -713,8 +713,8 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : X86TargetInfo(Triple, Opts) { const bool IsX32 = getTriple().isX32(); -bool IsWinCOFF = -getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF(); +bool IsWinCOFF = (getTriple().isOSWindows() || getTriple().isUEFI()) && + getTriple().isOSBinFormatCOFF(); LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64; LongDoubleWidth = 128; LongDoubleAlign = 128; >From 71eb5ea788558ce31984715edc14106c44fe7a8c Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 08:37:46 -0800 Subject: [PATCH 2/2] [clang] add __uefi__ define --- clang/lib/Basic/Targets/OSTargets.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index cd9b3760ca5874..24ffd542d664c7 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -790,7 +790,9 @@ template class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { protected: void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, -MacroBuilder &Builder) const override {} +MacroBuilder &Builder) const override { +DefineStd(Builder, "uefi", Opts); + } public: UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/120632 >From 2ee88359c3be20f3b6697bf75466fa44e7b10ab5 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 10:54:58 -0800 Subject: [PATCH 1/5] [clang] fix uefi data layout on x86 & aarch64 --- clang/lib/Basic/Targets/AArch64.cpp | 3 +++ clang/lib/Basic/Targets/X86.h | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index 53e102bbe44687..dd5d033afd8763 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -1537,6 +1537,9 @@ void AArch64leTargetInfo::setDataLayout() { resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-" "n32:64-S128-Fn32", "_"); + } else if (getTriple().isUEFI() && getTriple().isOSBinFormatCOFF()) { +resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-" +"i64:64-i128:128-n32:64-S128-Fn32"); } else resetDataLayout("e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-" "i64:64-i128:128-n32:64-S128-Fn32"); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 3ed36c8fa724b5..1d6fe468af3be1 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -713,8 +713,8 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : X86TargetInfo(Triple, Opts) { const bool IsX32 = getTriple().isX32(); -bool IsWinCOFF = -getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF(); +bool IsWinCOFF = (getTriple().isOSWindows() || getTriple().isUEFI()) && + getTriple().isOSBinFormatCOFF(); LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64; LongDoubleWidth = 128; LongDoubleAlign = 128; >From 71eb5ea788558ce31984715edc14106c44fe7a8c Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 08:37:46 -0800 Subject: [PATCH 2/5] [clang] add __uefi__ define --- clang/lib/Basic/Targets/OSTargets.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index cd9b3760ca5874..24ffd542d664c7 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -790,7 +790,9 @@ template class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { protected: void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, -MacroBuilder &Builder) const override {} +MacroBuilder &Builder) const override { +DefineStd(Builder, "uefi", Opts); + } public: UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) >From 370366fdcfa3f905a855e9f53e35014a15166150 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 13:40:50 -0800 Subject: [PATCH 3/5] [clang] add __uefi__ test for aarch64 & x86_64 --- clang/test/Preprocessor/init.c | 7 +++ 1 file changed, 7 insertions(+) diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 05225c120b13de..8708b12e6cf0c5 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -2742,3 +2742,10 @@ // RISCV64-LINUX: #define __unix__ 1 // RISCV64-LINUX: #define linux 1 // RISCV64-LINUX: #define unix 1 +// +// RUN: %clang_cc1 -dM -triple=aarch64-unknown-uefi -E < /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s +// RUN: %clang_cc1 -dM -triple=x86_64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s +// +// UEFI: #define __uefi 1 +// UEFI: #define __uefi__ 1 +// UEFI: #define uefi 1 >From c7a6fcd9c8c99bcba6689d5dab270cd16f001764 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 13:52:26 -0800 Subject: [PATCH 4/5] [clang] add uefi to target os macros --- clang/include/clang/Basic/TargetOSMacros.def | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/include/clang/Basic/TargetOSMacros.def b/clang/include/clang/Basic/TargetOSMacros.def index 58dce330f9c8fd..f4f3276ad1c256 100644 --- a/clang/include/clang/Basic/TargetOSMacros.def +++ b/clang/include/clang/Basic/TargetOSMacros.def @@ -53,4 +53,7 @@ TARGET_OS(TARGET_OS_NANO, Triple.isWatchOS()) TARGET_OS(TARGET_IPHONE_SIMULATOR, Triple.isSimulatorEnvironment()) TARGET_OS(TARGET_OS_UIKITFORMAC, Triple.isMacCatalystEnvironment()) +// UEFI target. +TARGET_OS(TARGET_OS_UEFI, Triple.isUEFI()) + #undef TARGET_OS >From 81cd003aac395e00e306623f45444052ec810e22 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 14:13:09 -0800 Subject: [PATCH 5/5] [clang] use mixin for aarch64 and x86_64 uefi --- clang/lib/Basic/Targets.cpp | 6 - clang/lib/Basic/Targets/OSTa
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
@@ -788,16 +789,28 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public OSTargetInfo { // UEFI target template class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { + llvm::Triple Triple; protected: void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, -MacroBuilder &Builder) const override {} +MacroBuilder &Builder) const override { +DefineStd(Builder, "uefi", Opts); + } public: UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) - : OSTargetInfo(Triple, Opts) { + : OSTargetInfo(Triple, Opts), Triple(Triple) { this->WCharType = TargetInfo::UnsignedShort; this->WIntType = TargetInfo::UnsignedShort; } + + TargetInfo::CallingConvKind + getCallingConvKind(bool ClangABICompat4) const override { +if (Triple.getArch() == llvm::Triple::x86_64) { + return TargetInfo::CallingConvKind::CCK_MicrosoftWin64; +} RossComputerGuy wrote: Fixed + clang-format check should be happy again. https://github.com/llvm/llvm-project/pull/120632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
@@ -820,43 +820,6 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { } }; -// x86-64 UEFI target -class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo -: public UEFITargetInfo { -public: - UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) - : UEFITargetInfo(Triple, Opts) { -this->TheCXXABI.set(TargetCXXABI::Microsoft); RossComputerGuy wrote: I'm not sure. https://github.com/llvm/llvm-project/pull/120632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
RossComputerGuy wrote: Clang driver unit tests have been fixed. https://github.com/llvm/llvm-project/pull/120632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
@@ -820,43 +820,6 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { } }; -// x86-64 UEFI target -class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo -: public UEFITargetInfo { -public: - UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) - : UEFITargetInfo(Triple, Opts) { -this->TheCXXABI.set(TargetCXXABI::Microsoft); RossComputerGuy wrote: I'm not sure what the behavior even is. Looking at the UEFI spec, it doesn't mention C++ ABI stuff. https://github.com/llvm/llvm-project/pull/120632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
@@ -790,7 +790,9 @@ template class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { protected: void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, -MacroBuilder &Builder) const override {} +MacroBuilder &Builder) const override { +Builder.defineMacro("__UEFI__"); RossComputerGuy wrote: Probably, although UEFI spec-wise is similar to Windows afaict. I'm not sure which style we'd want. GCC does not support UEFI targets and prefer to do a Windows style toolchain. https://github.com/llvm/llvm-project/pull/120632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
@@ -790,7 +790,9 @@ template class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { protected: void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, -MacroBuilder &Builder) const override {} +MacroBuilder &Builder) const override { +Builder.defineMacro("__UEFI__"); RossComputerGuy wrote: I'm not familiar with any other toolchains supporting UEFI targets. LLVM would be the first I think. I know zig has some UEFI support but it's based on Windows stuff and they have their own stdlib for the language. But as far as C goes, LLVM would be the first. https://github.com/llvm/llvm-project/pull/120632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/120632 >From 2ee88359c3be20f3b6697bf75466fa44e7b10ab5 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 10:54:58 -0800 Subject: [PATCH 1/5] [clang] fix uefi data layout on x86 & aarch64 --- clang/lib/Basic/Targets/AArch64.cpp | 3 +++ clang/lib/Basic/Targets/X86.h | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index 53e102bbe44687..dd5d033afd8763 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -1537,6 +1537,9 @@ void AArch64leTargetInfo::setDataLayout() { resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-" "n32:64-S128-Fn32", "_"); + } else if (getTriple().isUEFI() && getTriple().isOSBinFormatCOFF()) { +resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-" +"i64:64-i128:128-n32:64-S128-Fn32"); } else resetDataLayout("e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-" "i64:64-i128:128-n32:64-S128-Fn32"); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 3ed36c8fa724b5..1d6fe468af3be1 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -713,8 +713,8 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : X86TargetInfo(Triple, Opts) { const bool IsX32 = getTriple().isX32(); -bool IsWinCOFF = -getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF(); +bool IsWinCOFF = (getTriple().isOSWindows() || getTriple().isUEFI()) && + getTriple().isOSBinFormatCOFF(); LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64; LongDoubleWidth = 128; LongDoubleAlign = 128; >From 71eb5ea788558ce31984715edc14106c44fe7a8c Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 08:37:46 -0800 Subject: [PATCH 2/5] [clang] add __uefi__ define --- clang/lib/Basic/Targets/OSTargets.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index cd9b3760ca5874..24ffd542d664c7 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -790,7 +790,9 @@ template class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { protected: void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, -MacroBuilder &Builder) const override {} +MacroBuilder &Builder) const override { +DefineStd(Builder, "uefi", Opts); + } public: UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) >From 370366fdcfa3f905a855e9f53e35014a15166150 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 13:40:50 -0800 Subject: [PATCH 3/5] [clang] add __uefi__ test for aarch64 & x86_64 --- clang/test/Preprocessor/init.c | 7 +++ 1 file changed, 7 insertions(+) diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 05225c120b13de..8708b12e6cf0c5 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -2742,3 +2742,10 @@ // RISCV64-LINUX: #define __unix__ 1 // RISCV64-LINUX: #define linux 1 // RISCV64-LINUX: #define unix 1 +// +// RUN: %clang_cc1 -dM -triple=aarch64-unknown-uefi -E < /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s +// RUN: %clang_cc1 -dM -triple=x86_64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s +// +// UEFI: #define __uefi 1 +// UEFI: #define __uefi__ 1 +// UEFI: #define uefi 1 >From c7a6fcd9c8c99bcba6689d5dab270cd16f001764 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 13:52:26 -0800 Subject: [PATCH 4/5] [clang] add uefi to target os macros --- clang/include/clang/Basic/TargetOSMacros.def | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/include/clang/Basic/TargetOSMacros.def b/clang/include/clang/Basic/TargetOSMacros.def index 58dce330f9c8fd..f4f3276ad1c256 100644 --- a/clang/include/clang/Basic/TargetOSMacros.def +++ b/clang/include/clang/Basic/TargetOSMacros.def @@ -53,4 +53,7 @@ TARGET_OS(TARGET_OS_NANO, Triple.isWatchOS()) TARGET_OS(TARGET_IPHONE_SIMULATOR, Triple.isSimulatorEnvironment()) TARGET_OS(TARGET_OS_UIKITFORMAC, Triple.isMacCatalystEnvironment()) +// UEFI target. +TARGET_OS(TARGET_OS_UEFI, Triple.isUEFI()) + #undef TARGET_OS >From 06becc15af65b012ad4871ac817c6bb44c8a519f Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 14:13:09 -0800 Subject: [PATCH 5/5] [clang] use mixin for aarch64 and x86_64 uefi --- clang/lib/Basic/Targets.cpp | 6 - clang/lib/Basic/Targets/OSTa
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/120632 >From 2ee88359c3be20f3b6697bf75466fa44e7b10ab5 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 10:54:58 -0800 Subject: [PATCH 1/4] [clang] fix uefi data layout on x86 & aarch64 --- clang/lib/Basic/Targets/AArch64.cpp | 3 +++ clang/lib/Basic/Targets/X86.h | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index 53e102bbe44687..dd5d033afd8763 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -1537,6 +1537,9 @@ void AArch64leTargetInfo::setDataLayout() { resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-" "n32:64-S128-Fn32", "_"); + } else if (getTriple().isUEFI() && getTriple().isOSBinFormatCOFF()) { +resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-" +"i64:64-i128:128-n32:64-S128-Fn32"); } else resetDataLayout("e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-" "i64:64-i128:128-n32:64-S128-Fn32"); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 3ed36c8fa724b5..1d6fe468af3be1 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -713,8 +713,8 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : X86TargetInfo(Triple, Opts) { const bool IsX32 = getTriple().isX32(); -bool IsWinCOFF = -getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF(); +bool IsWinCOFF = (getTriple().isOSWindows() || getTriple().isUEFI()) && + getTriple().isOSBinFormatCOFF(); LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64; LongDoubleWidth = 128; LongDoubleAlign = 128; >From 71eb5ea788558ce31984715edc14106c44fe7a8c Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 08:37:46 -0800 Subject: [PATCH 2/4] [clang] add __uefi__ define --- clang/lib/Basic/Targets/OSTargets.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index cd9b3760ca5874..24ffd542d664c7 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -790,7 +790,9 @@ template class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { protected: void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, -MacroBuilder &Builder) const override {} +MacroBuilder &Builder) const override { +DefineStd(Builder, "uefi", Opts); + } public: UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) >From a9fb7e7b26ef375a2a8e2e920f5fcd696d5cf4fc Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 13:40:50 -0800 Subject: [PATCH 3/4] [clang] add __uefi__ test for aarch64 & x86_64 --- clang/test/Preprocessor/init.c | 8 1 file changed, 8 insertions(+) diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 05225c120b13de..e0693df72180d9 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -2742,3 +2742,11 @@ // RISCV64-LINUX: #define __unix__ 1 // RISCV64-LINUX: #define linux 1 // RISCV64-LINUX: #define unix 1 +// +// RUN: %clang_cc1 -dM -triple=aarch64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix uefi %s +// +// AARCH64-UEFI: #define __uefi__ 1 +// +// RUN: %clang_cc1 -dM -triple=x86_64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix uefi %s +// +// X86-64-UEFI: #define __uefi__ 1 >From 905d34693b2f0aebd2a54e6e3b82dc81c22b7210 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 13:51:08 -0800 Subject: [PATCH 4/4] [clang] add missing uefi support to aarch64 --- clang/lib/Basic/Targets.cpp | 3 +++ clang/lib/Basic/Targets/AArch64.cpp | 12 clang/lib/Basic/Targets/AArch64.h | 10 ++ 3 files changed, 25 insertions(+) diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 706a391023b3a3..d1aacafe704dd7 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -165,6 +165,9 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, case llvm::Triple::OpenBSD: return std::make_unique>(Triple, Opts); +case llvm::Triple::UEFI: + return std::make_unique(Triple, Opts); + case llvm::Triple::Win32: switch (Triple.getEnvironment()) { case llvm::Triple::GNU: diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index dd5d033afd8763..94d
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/120632 >From 2ee88359c3be20f3b6697bf75466fa44e7b10ab5 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 10:54:58 -0800 Subject: [PATCH 1/5] [clang] fix uefi data layout on x86 & aarch64 --- clang/lib/Basic/Targets/AArch64.cpp | 3 +++ clang/lib/Basic/Targets/X86.h | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index 53e102bbe44687..dd5d033afd8763 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -1537,6 +1537,9 @@ void AArch64leTargetInfo::setDataLayout() { resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-" "n32:64-S128-Fn32", "_"); + } else if (getTriple().isUEFI() && getTriple().isOSBinFormatCOFF()) { +resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-" +"i64:64-i128:128-n32:64-S128-Fn32"); } else resetDataLayout("e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-" "i64:64-i128:128-n32:64-S128-Fn32"); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 3ed36c8fa724b5..1d6fe468af3be1 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -713,8 +713,8 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : X86TargetInfo(Triple, Opts) { const bool IsX32 = getTriple().isX32(); -bool IsWinCOFF = -getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF(); +bool IsWinCOFF = (getTriple().isOSWindows() || getTriple().isUEFI()) && + getTriple().isOSBinFormatCOFF(); LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64; LongDoubleWidth = 128; LongDoubleAlign = 128; >From 71eb5ea788558ce31984715edc14106c44fe7a8c Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 08:37:46 -0800 Subject: [PATCH 2/5] [clang] add __uefi__ define --- clang/lib/Basic/Targets/OSTargets.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index cd9b3760ca5874..24ffd542d664c7 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -790,7 +790,9 @@ template class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { protected: void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, -MacroBuilder &Builder) const override {} +MacroBuilder &Builder) const override { +DefineStd(Builder, "uefi", Opts); + } public: UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) >From a9fb7e7b26ef375a2a8e2e920f5fcd696d5cf4fc Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 13:40:50 -0800 Subject: [PATCH 3/5] [clang] add __uefi__ test for aarch64 & x86_64 --- clang/test/Preprocessor/init.c | 8 1 file changed, 8 insertions(+) diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 05225c120b13de..e0693df72180d9 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -2742,3 +2742,11 @@ // RISCV64-LINUX: #define __unix__ 1 // RISCV64-LINUX: #define linux 1 // RISCV64-LINUX: #define unix 1 +// +// RUN: %clang_cc1 -dM -triple=aarch64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix uefi %s +// +// AARCH64-UEFI: #define __uefi__ 1 +// +// RUN: %clang_cc1 -dM -triple=x86_64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix uefi %s +// +// X86-64-UEFI: #define __uefi__ 1 >From 905d34693b2f0aebd2a54e6e3b82dc81c22b7210 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 13:51:08 -0800 Subject: [PATCH 4/5] [clang] add missing uefi support to aarch64 --- clang/lib/Basic/Targets.cpp | 3 +++ clang/lib/Basic/Targets/AArch64.cpp | 12 clang/lib/Basic/Targets/AArch64.h | 10 ++ 3 files changed, 25 insertions(+) diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 706a391023b3a3..d1aacafe704dd7 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -165,6 +165,9 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, case llvm::Triple::OpenBSD: return std::make_unique>(Triple, Opts); +case llvm::Triple::UEFI: + return std::make_unique(Triple, Opts); + case llvm::Triple::Win32: switch (Triple.getEnvironment()) { case llvm::Triple::GNU: diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index dd5d033afd8763..94d
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
@@ -165,6 +165,9 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, case llvm::Triple::OpenBSD: return std::make_unique>(Triple, Opts); +case llvm::Triple::UEFI: + return std::make_unique(Triple, Opts); RossComputerGuy wrote: I'm not sure how we should make a mixin. Also, from what I can find, the call convention and some of the data layouts are different between x86 and other UEFI capable ISA's. We could add in checks, the solution I came up with is simple enough lol. But I do agree a mixin would probably be better. https://github.com/llvm/llvm-project/pull/120632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
@@ -820,43 +820,6 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { } }; -// x86-64 UEFI target -class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo -: public UEFITargetInfo { -public: - UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) - : UEFITargetInfo(Triple, Opts) { -this->TheCXXABI.set(TargetCXXABI::Microsoft); -this->MaxTLSAlign = 8192u * this->getCharWidth(); -this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-" - "i64:64-i128:128-f80:128-n8:16:32:64-S128"); - } - - void getTargetDefines(const LangOptions &Opts, -MacroBuilder &Builder) const override { -getOSDefines(Opts, X86TargetInfo::getTriple(), Builder); RossComputerGuy wrote: I forgot about that. https://github.com/llvm/llvm-project/pull/120632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
@@ -820,43 +820,6 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { } }; -// x86-64 UEFI target -class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo -: public UEFITargetInfo { -public: - UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) - : UEFITargetInfo(Triple, Opts) { -this->TheCXXABI.set(TargetCXXABI::Microsoft); -this->MaxTLSAlign = 8192u * this->getCharWidth(); -this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-" - "i64:64-i128:128-f80:128-n8:16:32:64-S128"); - } - - void getTargetDefines(const LangOptions &Opts, -MacroBuilder &Builder) const override { -getOSDefines(Opts, X86TargetInfo::getTriple(), Builder); RossComputerGuy wrote: Hmm, it looks like it might be using the default for `OSTargetInfo` which should do fine? https://github.com/llvm/llvm-project/pull/120632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
RossComputerGuy wrote: Tests have been adjusted, they should pass now. https://github.com/llvm/llvm-project/pull/120632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/120632 >From 2ee88359c3be20f3b6697bf75466fa44e7b10ab5 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 10:54:58 -0800 Subject: [PATCH 1/5] [clang] fix uefi data layout on x86 & aarch64 --- clang/lib/Basic/Targets/AArch64.cpp | 3 +++ clang/lib/Basic/Targets/X86.h | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index 53e102bbe44687..dd5d033afd8763 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -1537,6 +1537,9 @@ void AArch64leTargetInfo::setDataLayout() { resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-" "n32:64-S128-Fn32", "_"); + } else if (getTriple().isUEFI() && getTriple().isOSBinFormatCOFF()) { +resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-" +"i64:64-i128:128-n32:64-S128-Fn32"); } else resetDataLayout("e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-" "i64:64-i128:128-n32:64-S128-Fn32"); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 3ed36c8fa724b5..1d6fe468af3be1 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -713,8 +713,8 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : X86TargetInfo(Triple, Opts) { const bool IsX32 = getTriple().isX32(); -bool IsWinCOFF = -getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF(); +bool IsWinCOFF = (getTriple().isOSWindows() || getTriple().isUEFI()) && + getTriple().isOSBinFormatCOFF(); LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64; LongDoubleWidth = 128; LongDoubleAlign = 128; >From 71eb5ea788558ce31984715edc14106c44fe7a8c Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 08:37:46 -0800 Subject: [PATCH 2/5] [clang] add __uefi__ define --- clang/lib/Basic/Targets/OSTargets.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index cd9b3760ca5874..24ffd542d664c7 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -790,7 +790,9 @@ template class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { protected: void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, -MacroBuilder &Builder) const override {} +MacroBuilder &Builder) const override { +DefineStd(Builder, "uefi", Opts); + } public: UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) >From a9fb7e7b26ef375a2a8e2e920f5fcd696d5cf4fc Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 13:40:50 -0800 Subject: [PATCH 3/5] [clang] add __uefi__ test for aarch64 & x86_64 --- clang/test/Preprocessor/init.c | 8 1 file changed, 8 insertions(+) diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 05225c120b13de..e0693df72180d9 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -2742,3 +2742,11 @@ // RISCV64-LINUX: #define __unix__ 1 // RISCV64-LINUX: #define linux 1 // RISCV64-LINUX: #define unix 1 +// +// RUN: %clang_cc1 -dM -triple=aarch64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix uefi %s +// +// AARCH64-UEFI: #define __uefi__ 1 +// +// RUN: %clang_cc1 -dM -triple=x86_64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix uefi %s +// +// X86-64-UEFI: #define __uefi__ 1 >From 371f6d667cf9e2f219f04719264877c820df33bb Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 13:51:08 -0800 Subject: [PATCH 4/5] [clang] add missing uefi support to aarch64 --- clang/lib/Basic/Targets.cpp | 3 +++ clang/lib/Basic/Targets/AArch64.cpp | 12 clang/lib/Basic/Targets/AArch64.h | 10 ++ 3 files changed, 25 insertions(+) diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 706a391023b3a3..d1aacafe704dd7 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -165,6 +165,9 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, case llvm::Triple::OpenBSD: return std::make_unique>(Triple, Opts); +case llvm::Triple::UEFI: + return std::make_unique(Triple, Opts); + case llvm::Triple::Win32: switch (Triple.getEnvironment()) { case llvm::Triple::GNU: diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index dd5d033afd8763..a9f
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
@@ -165,6 +165,9 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, case llvm::Triple::OpenBSD: return std::make_unique>(Triple, Opts); +case llvm::Triple::UEFI: + return std::make_unique(Triple, Opts); RossComputerGuy wrote: I think so or it might be better to leave the data layout to the architecture side. The call convention is simple enough that it could be in the mixin. https://github.com/llvm/llvm-project/pull/120632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/120632 >From 2ee88359c3be20f3b6697bf75466fa44e7b10ab5 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 10:54:58 -0800 Subject: [PATCH 1/5] [clang] fix uefi data layout on x86 & aarch64 --- clang/lib/Basic/Targets/AArch64.cpp | 3 +++ clang/lib/Basic/Targets/X86.h | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index 53e102bbe44687..dd5d033afd8763 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -1537,6 +1537,9 @@ void AArch64leTargetInfo::setDataLayout() { resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-" "n32:64-S128-Fn32", "_"); + } else if (getTriple().isUEFI() && getTriple().isOSBinFormatCOFF()) { +resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-" +"i64:64-i128:128-n32:64-S128-Fn32"); } else resetDataLayout("e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-" "i64:64-i128:128-n32:64-S128-Fn32"); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 3ed36c8fa724b5..1d6fe468af3be1 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -713,8 +713,8 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : X86TargetInfo(Triple, Opts) { const bool IsX32 = getTriple().isX32(); -bool IsWinCOFF = -getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF(); +bool IsWinCOFF = (getTriple().isOSWindows() || getTriple().isUEFI()) && + getTriple().isOSBinFormatCOFF(); LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64; LongDoubleWidth = 128; LongDoubleAlign = 128; >From 71eb5ea788558ce31984715edc14106c44fe7a8c Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 08:37:46 -0800 Subject: [PATCH 2/5] [clang] add __uefi__ define --- clang/lib/Basic/Targets/OSTargets.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index cd9b3760ca5874..24ffd542d664c7 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -790,7 +790,9 @@ template class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { protected: void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, -MacroBuilder &Builder) const override {} +MacroBuilder &Builder) const override { +DefineStd(Builder, "uefi", Opts); + } public: UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) >From a9fb7e7b26ef375a2a8e2e920f5fcd696d5cf4fc Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 13:40:50 -0800 Subject: [PATCH 3/5] [clang] add __uefi__ test for aarch64 & x86_64 --- clang/test/Preprocessor/init.c | 8 1 file changed, 8 insertions(+) diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 05225c120b13de..e0693df72180d9 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -2742,3 +2742,11 @@ // RISCV64-LINUX: #define __unix__ 1 // RISCV64-LINUX: #define linux 1 // RISCV64-LINUX: #define unix 1 +// +// RUN: %clang_cc1 -dM -triple=aarch64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix uefi %s +// +// AARCH64-UEFI: #define __uefi__ 1 +// +// RUN: %clang_cc1 -dM -triple=x86_64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix uefi %s +// +// X86-64-UEFI: #define __uefi__ 1 >From 9249d6ba2b44514a0e8eeb0b88c036b8e33e37a3 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 13:52:26 -0800 Subject: [PATCH 4/5] [clang] add uefi to target os macros --- clang/include/clang/Basic/TargetOSMacros.def | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/include/clang/Basic/TargetOSMacros.def b/clang/include/clang/Basic/TargetOSMacros.def index 58dce330f9c8fd..f4f3276ad1c256 100644 --- a/clang/include/clang/Basic/TargetOSMacros.def +++ b/clang/include/clang/Basic/TargetOSMacros.def @@ -53,4 +53,7 @@ TARGET_OS(TARGET_OS_NANO, Triple.isWatchOS()) TARGET_OS(TARGET_IPHONE_SIMULATOR, Triple.isSimulatorEnvironment()) TARGET_OS(TARGET_OS_UIKITFORMAC, Triple.isMacCatalystEnvironment()) +// UEFI target. +TARGET_OS(TARGET_OS_UEFI, Triple.isUEFI()) + #undef TARGET_OS >From 2e3b764994d1938897ef81025c4584d8b754a250 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 14:13:09 -0800 Subject: [PATCH 5/5] [clang] use mixin for aarch64 and x86_64 uefi --- clang/lib/Basic/Targets.cpp | 6 +- clang/lib/Basic/Targets/X86.h | 37
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
@@ -165,6 +165,9 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, case llvm::Triple::OpenBSD: return std::make_unique>(Triple, Opts); +case llvm::Triple::UEFI: + return std::make_unique(Triple, Opts); RossComputerGuy wrote: I've moved it over to a mixin. I'm not sure how to test if the call convention and stuff is working as expected. https://github.com/llvm/llvm-project/pull/120632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
https://github.com/RossComputerGuy created https://github.com/llvm/llvm-project/pull/120632 This PR introduces some fixes where the data layout wasn't propagated correctly. To test this, feed clang any C file (I used an empty main for testing) and pass `-target aarch64-uefi` or `-target x86_64-uefi`. Before this PR, you would get an error similar to this: ``` error: backend data layout 'e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128' does not match expected target description 'e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128' 1 error generated. ``` This PR also adds a new `__uefi__` macro which will hopefully let us work towards getting compiler-rt and libc working with UEFI. >From 965537e08a14416629f3891f4af0a59925ada38d Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 10:54:58 -0800 Subject: [PATCH 1/2] [clang] fix uefi data layout on x86 & aarch64 --- clang/lib/Basic/Targets/AArch64.cpp | 4 clang/lib/Basic/Targets/X86.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index 53e102bbe44687..d8aef4837f9267 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -1537,6 +1537,10 @@ void AArch64leTargetInfo::setDataLayout() { resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-" "n32:64-S128-Fn32", "_"); + } else if (getTriple().isUEFI() && getTriple().isOSBinFormatCOFF()) { +resetDataLayout( +"e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-" +"i64:64-i128:128-n32:64-S128-Fn32"); } else resetDataLayout("e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-" "i64:64-i128:128-n32:64-S128-Fn32"); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 3ed36c8fa724b5..bb72a92b1cf5b7 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -714,7 +714,7 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { : X86TargetInfo(Triple, Opts) { const bool IsX32 = getTriple().isX32(); bool IsWinCOFF = -getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF(); +(getTriple().isOSWindows() || getTriple().isUEFI()) && getTriple().isOSBinFormatCOFF(); LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64; LongDoubleWidth = 128; LongDoubleAlign = 128; >From 8f5ef58d51aac7b91faf9e9b6e56eda137bad9ce Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 08:37:46 -0800 Subject: [PATCH 2/2] [clang] add __uefi__ define --- clang/lib/Basic/Targets/OSTargets.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index cd9b3760ca5874..53dd23c3129636 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -790,7 +790,9 @@ template class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { protected: void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, -MacroBuilder &Builder) const override {} +MacroBuilder &Builder) const override { +Builder.defineMacro("__UEFI__"); + } public: UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/120632 >From 2ee88359c3be20f3b6697bf75466fa44e7b10ab5 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 10:54:58 -0800 Subject: [PATCH 1/2] [clang] fix uefi data layout on x86 & aarch64 --- clang/lib/Basic/Targets/AArch64.cpp | 3 +++ clang/lib/Basic/Targets/X86.h | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index 53e102bbe44687..dd5d033afd8763 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -1537,6 +1537,9 @@ void AArch64leTargetInfo::setDataLayout() { resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-" "n32:64-S128-Fn32", "_"); + } else if (getTriple().isUEFI() && getTriple().isOSBinFormatCOFF()) { +resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-" +"i64:64-i128:128-n32:64-S128-Fn32"); } else resetDataLayout("e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-" "i64:64-i128:128-n32:64-S128-Fn32"); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 3ed36c8fa724b5..1d6fe468af3be1 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -713,8 +713,8 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : X86TargetInfo(Triple, Opts) { const bool IsX32 = getTriple().isX32(); -bool IsWinCOFF = -getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF(); +bool IsWinCOFF = (getTriple().isOSWindows() || getTriple().isUEFI()) && + getTriple().isOSBinFormatCOFF(); LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64; LongDoubleWidth = 128; LongDoubleAlign = 128; >From 7b210e9713a6d86e196d8cb38d9619eb21fb01ff Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 08:37:46 -0800 Subject: [PATCH 2/2] [clang] add __uefi__ define --- clang/lib/Basic/Targets/OSTargets.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index cd9b3760ca5874..53dd23c3129636 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -790,7 +790,9 @@ template class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { protected: void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, -MacroBuilder &Builder) const override {} +MacroBuilder &Builder) const override { +Builder.defineMacro("__UEFI__"); + } public: UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
@@ -790,7 +790,9 @@ template class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { protected: void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, -MacroBuilder &Builder) const override {} +MacroBuilder &Builder) const override { +Builder.defineMacro("__UEFI__"); RossComputerGuy wrote: I've switched over to `DefineStd`. https://github.com/llvm/llvm-project/pull/120632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] UEFI backend for x86_64 (PR #109320)
RossComputerGuy wrote: Some of the clang changes seem kinda *odd*, maybe some of this work and #120632 could be conjoined? The LLVM stuff itself looks great, it's mainly the target stuff in clang seems odd to me. https://github.com/llvm/llvm-project/pull/109320 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxx] [clang][driver] Cleanup UEFI toolchain driver (PR #111473)
https://github.com/RossComputerGuy approved this pull request. Looks good to me. https://github.com/llvm/llvm-project/pull/111473 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
@@ -788,16 +789,28 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public OSTargetInfo { // UEFI target template class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { + llvm::Triple Triple; + protected: void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, -MacroBuilder &Builder) const override {} +MacroBuilder &Builder) const override { +DefineStd(Builder, "uefi", Opts); RossComputerGuy wrote: Yeah, I like making medium sized PR's typically with few small commits. It's much easier to review or look at specific components. https://github.com/llvm/llvm-project/pull/120632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
@@ -788,16 +789,28 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public OSTargetInfo { // UEFI target template class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { + llvm::Triple Triple; + protected: void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, -MacroBuilder &Builder) const override {} +MacroBuilder &Builder) const override { +DefineStd(Builder, "uefi", Opts); RossComputerGuy wrote: We can probably get the cleanup PR first then this one. Kinda on the fence with the define one. https://github.com/llvm/llvm-project/pull/120632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver][UEFI] Enable Microsoft extensions (PR #121875)
RossComputerGuy wrote: > @RossComputerGuy FYI Already have seen this, I'm not sure I understand what the flag does exactly. I've got LLVM libc PR subscriptions so I'll see any future PR's. https://github.com/llvm/llvm-project/pull/121875 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
@@ -713,8 +713,8 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : X86TargetInfo(Triple, Opts) { const bool IsX32 = getTriple().isX32(); -bool IsWinCOFF = -getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF(); +bool IsWinCOFF = (getTriple().isOSWindows() || getTriple().isUEFI()) && + getTriple().isOSBinFormatCOFF(); LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64; RossComputerGuy wrote: Maybe, doesn't sound right that the various types and stuff aren't right for x86. https://github.com/llvm/llvm-project/pull/120632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/120632 >From a9b162f2dbf8e2e102bc8f4cf7af51331e648502 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 10:54:58 -0800 Subject: [PATCH 1/5] [clang] fix uefi data layout on x86 & aarch64 --- clang/lib/Basic/Targets/AArch64.cpp | 3 +++ clang/lib/Basic/Targets/X86.h | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index 53e102bbe44687..dd5d033afd8763 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -1537,6 +1537,9 @@ void AArch64leTargetInfo::setDataLayout() { resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-" "n32:64-S128-Fn32", "_"); + } else if (getTriple().isUEFI() && getTriple().isOSBinFormatCOFF()) { +resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-" +"i64:64-i128:128-n32:64-S128-Fn32"); } else resetDataLayout("e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-" "i64:64-i128:128-n32:64-S128-Fn32"); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 553c452d4ba3c2..033c7c525bb6cd 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -713,8 +713,8 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : X86TargetInfo(Triple, Opts) { const bool IsX32 = getTriple().isX32(); -bool IsWinCOFF = -getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF(); +bool IsWinCOFF = (getTriple().isOSWindows() || getTriple().isUEFI()) && + getTriple().isOSBinFormatCOFF(); LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64; LongDoubleWidth = 128; LongDoubleAlign = 128; >From e0008eb4fd9081ca00c1e3813f724450bcce0ce2 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 08:37:46 -0800 Subject: [PATCH 2/5] [clang] add __uefi__ define --- clang/lib/Basic/Targets/OSTargets.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index cd9b3760ca5874..24ffd542d664c7 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -790,7 +790,9 @@ template class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { protected: void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, -MacroBuilder &Builder) const override {} +MacroBuilder &Builder) const override { +DefineStd(Builder, "uefi", Opts); + } public: UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) >From 166e2fdbe0db4098a20fb72c1ffb3dec43e4f159 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 13:40:50 -0800 Subject: [PATCH 3/5] [clang] add __uefi__ test for aarch64 & x86_64 --- clang/test/Preprocessor/init.c | 7 +++ 1 file changed, 7 insertions(+) diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 05225c120b13de..8708b12e6cf0c5 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -2742,3 +2742,10 @@ // RISCV64-LINUX: #define __unix__ 1 // RISCV64-LINUX: #define linux 1 // RISCV64-LINUX: #define unix 1 +// +// RUN: %clang_cc1 -dM -triple=aarch64-unknown-uefi -E < /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s +// RUN: %clang_cc1 -dM -triple=x86_64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s +// +// UEFI: #define __uefi 1 +// UEFI: #define __uefi__ 1 +// UEFI: #define uefi 1 >From 7d89fa6997b36bc0ab00093a0e407128d2996dd9 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 13:52:26 -0800 Subject: [PATCH 4/5] [clang] add uefi to target os macros --- clang/include/clang/Basic/TargetOSMacros.def | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/include/clang/Basic/TargetOSMacros.def b/clang/include/clang/Basic/TargetOSMacros.def index 58dce330f9c8fd..f4f3276ad1c256 100644 --- a/clang/include/clang/Basic/TargetOSMacros.def +++ b/clang/include/clang/Basic/TargetOSMacros.def @@ -53,4 +53,7 @@ TARGET_OS(TARGET_OS_NANO, Triple.isWatchOS()) TARGET_OS(TARGET_IPHONE_SIMULATOR, Triple.isSimulatorEnvironment()) TARGET_OS(TARGET_OS_UIKITFORMAC, Triple.isMacCatalystEnvironment()) +// UEFI target. +TARGET_OS(TARGET_OS_UEFI, Triple.isUEFI()) + #undef TARGET_OS >From b41e7a80f67fb9c82fdf81d2acebf9aa4ff11b57 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 14:13:09 -0800 Subject: [PATCH 5/5] [clang] use mixin for aarch64 and x86_64 uefi --- clang/lib/Basic/Targets.cpp | 6 +- clang/lib/Basic/Targets/OST
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
RossComputerGuy wrote: We have a problem where everything related to `i128` / `long double` fail to compile in LLVM libc without compiler-rt on aarch64 and possibly x86_64, this is a problem. Related ABI info: - [aarch64](https://github.com/ARM-software/abi-aa/releases/download/2024Q3/aapcs64.pdf) - [UEFI 2.10](https://uefi.org/sites/default/files/resources/UEFI_Spec_2_10_Aug29.pdf) - 2.3.6.4 We probably should fix that in this PR. https://github.com/llvm/llvm-project/pull/120632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] add llvm abi support (PR #121123)
https://github.com/RossComputerGuy created https://github.com/llvm/llvm-project/pull/121123 This PR makes it possible to use the LLVM ABI which uses LLVM libc. >From 058c4d297822cbde97641eb9c35d78d5742b96f2 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Wed, 25 Dec 2024 14:38:30 -0800 Subject: [PATCH] [clang] add llvm abi support --- clang/lib/Driver/Driver.cpp | 2 +- clang/lib/Driver/ToolChains/Gnu.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index dc84c1b9d1cc4e..98b8e6e97419c6 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1531,7 +1531,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { // Check if the environment version is valid except wasm case. llvm::Triple Triple = TC.getTriple(); - if (!Triple.isWasm()) { + if (!Triple.isWasm() && Triple.getEnvironment() != llvm::Triple::LLVM) { StringRef TripleVersionName = Triple.getEnvironmentVersionString(); StringRef TripleObjectFormat = Triple.getObjectFormatTypeName(Triple.getObjectFormat()); diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index 8397f1121ec2ce..2c9539ef56683c 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -464,7 +464,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (!Args.hasArg(options::OPT_shared)) { if (Args.hasArg(options::OPT_pg)) crt1 = "gcrt1.o"; -else if (IsPIE) +else if (IsPIE && Triple.getEnvironment() != llvm::Triple::LLVM) crt1 = "Scrt1.o"; else if (IsStaticPIE) crt1 = "rcrt1.o"; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
RossComputerGuy wrote: Will rebase tonight since #111719 was just merged. If we can get this merged soon then I can try more testing. https://github.com/llvm/llvm-project/pull/120632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
RossComputerGuy wrote: This has been rebased now, conflicts are gone. https://github.com/llvm/llvm-project/pull/120632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/120632 >From 1a76395c0dbe55146d1dd1ff943909f34c19a90a Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 10:54:58 -0800 Subject: [PATCH 1/4] [clang] fix uefi data layout on x86 & aarch64 --- clang/lib/Basic/Targets/AArch64.cpp | 3 +++ clang/lib/Basic/Targets/X86.h | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index 53e102bbe44687..dd5d033afd8763 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -1537,6 +1537,9 @@ void AArch64leTargetInfo::setDataLayout() { resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-" "n32:64-S128-Fn32", "_"); + } else if (getTriple().isUEFI() && getTriple().isOSBinFormatCOFF()) { +resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-" +"i64:64-i128:128-n32:64-S128-Fn32"); } else resetDataLayout("e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-" "i64:64-i128:128-n32:64-S128-Fn32"); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 553c452d4ba3c2..033c7c525bb6cd 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -713,8 +713,8 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : X86TargetInfo(Triple, Opts) { const bool IsX32 = getTriple().isX32(); -bool IsWinCOFF = -getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF(); +bool IsWinCOFF = (getTriple().isOSWindows() || getTriple().isUEFI()) && + getTriple().isOSBinFormatCOFF(); LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64; LongDoubleWidth = 128; LongDoubleAlign = 128; >From 01abdabed47fd6142c87568aba3e8ae16032b939 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 13:40:50 -0800 Subject: [PATCH 2/4] [clang] add __uefi__ test for aarch64 & x86_64 --- clang/test/Preprocessor/init.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 3b99204acd7a44..afb4af8b5f6c4b 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -2744,5 +2744,7 @@ // RISCV64-LINUX: #define unix 1 // RUN: %clang_cc1 -dM -triple=x86_64-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s +// RUN: %clang_cc1 -dM -triple=aarch64-unknown-uefi -E < /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s +// RUN: %clang_cc1 -dM -triple=x86_64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s // UEFI: #define __UEFI__ 1 >From 7336509917aa6be8ca822252d1061eb2758890af Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 13:52:26 -0800 Subject: [PATCH 3/4] [clang] add uefi to target os macros --- clang/include/clang/Basic/TargetOSMacros.def | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/include/clang/Basic/TargetOSMacros.def b/clang/include/clang/Basic/TargetOSMacros.def index 58dce330f9c8fd..f4f3276ad1c256 100644 --- a/clang/include/clang/Basic/TargetOSMacros.def +++ b/clang/include/clang/Basic/TargetOSMacros.def @@ -53,4 +53,7 @@ TARGET_OS(TARGET_OS_NANO, Triple.isWatchOS()) TARGET_OS(TARGET_IPHONE_SIMULATOR, Triple.isSimulatorEnvironment()) TARGET_OS(TARGET_OS_UIKITFORMAC, Triple.isMacCatalystEnvironment()) +// UEFI target. +TARGET_OS(TARGET_OS_UEFI, Triple.isUEFI()) + #undef TARGET_OS >From 1a29a74cdd4d591a3bd4265fad5510af8ef7086c Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 14:13:09 -0800 Subject: [PATCH 4/4] [clang] use mixin for aarch64 and x86_64 uefi --- clang/lib/Basic/Targets.cpp | 6 +- clang/lib/Basic/Targets/OSTargets.h | 13 +++- clang/lib/Basic/Targets/X86.h | 32 - 3 files changed, 17 insertions(+), 34 deletions(-) diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 706a391023b3a3..1820e489c4446e 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -165,6 +165,10 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, case llvm::Triple::OpenBSD: return std::make_unique>(Triple, Opts); +case llvm::Triple::UEFI: + return std::make_unique>(Triple, + Opts); + case llvm::Triple::Win32: switch (Triple.getEnvironment()) { case llvm::Triple::GNU: @@ -614,7 +618,7 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, return std::make_unique>(Triple,
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
@@ -820,43 +820,6 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { } }; -// x86-64 UEFI target -class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo -: public UEFITargetInfo { -public: - UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) - : UEFITargetInfo(Triple, Opts) { -this->TheCXXABI.set(TargetCXXABI::Microsoft); RossComputerGuy wrote: Ok, I'll add a `this->TheCXXABI.set(TargetCXXABI::Microsoft)` to the `UEFITargetInfo` template class. https://github.com/llvm/llvm-project/pull/120632 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/120632 >From 1a76395c0dbe55146d1dd1ff943909f34c19a90a Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 10:54:58 -0800 Subject: [PATCH 1/5] [clang] fix uefi data layout on x86 & aarch64 --- clang/lib/Basic/Targets/AArch64.cpp | 3 +++ clang/lib/Basic/Targets/X86.h | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index 53e102bbe44687..dd5d033afd8763 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -1537,6 +1537,9 @@ void AArch64leTargetInfo::setDataLayout() { resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-" "n32:64-S128-Fn32", "_"); + } else if (getTriple().isUEFI() && getTriple().isOSBinFormatCOFF()) { +resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-" +"i64:64-i128:128-n32:64-S128-Fn32"); } else resetDataLayout("e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-" "i64:64-i128:128-n32:64-S128-Fn32"); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 553c452d4ba3c2..033c7c525bb6cd 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -713,8 +713,8 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : X86TargetInfo(Triple, Opts) { const bool IsX32 = getTriple().isX32(); -bool IsWinCOFF = -getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF(); +bool IsWinCOFF = (getTriple().isOSWindows() || getTriple().isUEFI()) && + getTriple().isOSBinFormatCOFF(); LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64; LongDoubleWidth = 128; LongDoubleAlign = 128; >From 01abdabed47fd6142c87568aba3e8ae16032b939 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 13:40:50 -0800 Subject: [PATCH 2/5] [clang] add __uefi__ test for aarch64 & x86_64 --- clang/test/Preprocessor/init.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 3b99204acd7a44..afb4af8b5f6c4b 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -2744,5 +2744,7 @@ // RISCV64-LINUX: #define unix 1 // RUN: %clang_cc1 -dM -triple=x86_64-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s +// RUN: %clang_cc1 -dM -triple=aarch64-unknown-uefi -E < /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s +// RUN: %clang_cc1 -dM -triple=x86_64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s // UEFI: #define __UEFI__ 1 >From 7336509917aa6be8ca822252d1061eb2758890af Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 13:52:26 -0800 Subject: [PATCH 3/5] [clang] add uefi to target os macros --- clang/include/clang/Basic/TargetOSMacros.def | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/include/clang/Basic/TargetOSMacros.def b/clang/include/clang/Basic/TargetOSMacros.def index 58dce330f9c8fd..f4f3276ad1c256 100644 --- a/clang/include/clang/Basic/TargetOSMacros.def +++ b/clang/include/clang/Basic/TargetOSMacros.def @@ -53,4 +53,7 @@ TARGET_OS(TARGET_OS_NANO, Triple.isWatchOS()) TARGET_OS(TARGET_IPHONE_SIMULATOR, Triple.isSimulatorEnvironment()) TARGET_OS(TARGET_OS_UIKITFORMAC, Triple.isMacCatalystEnvironment()) +// UEFI target. +TARGET_OS(TARGET_OS_UEFI, Triple.isUEFI()) + #undef TARGET_OS >From 1a29a74cdd4d591a3bd4265fad5510af8ef7086c Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 14:13:09 -0800 Subject: [PATCH 4/5] [clang] use mixin for aarch64 and x86_64 uefi --- clang/lib/Basic/Targets.cpp | 6 +- clang/lib/Basic/Targets/OSTargets.h | 13 +++- clang/lib/Basic/Targets/X86.h | 32 - 3 files changed, 17 insertions(+), 34 deletions(-) diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index 706a391023b3a3..1820e489c4446e 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -165,6 +165,10 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, case llvm::Triple::OpenBSD: return std::make_unique>(Triple, Opts); +case llvm::Triple::UEFI: + return std::make_unique>(Triple, + Opts); + case llvm::Triple::Win32: switch (Triple.getEnvironment()) { case llvm::Triple::GNU: @@ -614,7 +618,7 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, return std::make_unique>(Triple,
[clang] [libc] [libcxx] [lldb] [llvm] [doc] Add Discord invite link alongside channel links (PR #126352)
https://github.com/RossComputerGuy approved this pull request. https://github.com/llvm/llvm-project/pull/126352 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Add unw_strerror function (PR #129084)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/129084 >From 9357008872e3b12b3601a45d4fd5453dfa779ff3 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 27 Feb 2025 09:10:22 -0800 Subject: [PATCH] [libunwind] Add unw_strerror function Co-authored-by: Randy Eckenrode --- libunwind/include/libunwind.h | 2 ++ libunwind/src/libunwind.cpp | 35 +++ 2 files changed, 37 insertions(+) diff --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h index b2dae8feed9a3..839aa3dcf31c5 100644 --- a/libunwind/include/libunwind.h +++ b/libunwind/include/libunwind.h @@ -131,6 +131,8 @@ extern int unw_is_signal_frame(unw_cursor_t *) LIBUNWIND_AVAIL; extern int unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *) LIBUNWIND_AVAIL; //extern int unw_get_save_loc(unw_cursor_t*, int, unw_save_loc_t*); +extern const char *unw_strerror(int) LIBUNWIND_AVAIL; + extern unw_addr_space_t unw_local_addr_space; #ifdef __cplusplus diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp index cf39ec5f7dbdf..5bb40ff795bb9 100644 --- a/libunwind/src/libunwind.cpp +++ b/libunwind/src/libunwind.cpp @@ -260,6 +260,41 @@ _LIBUNWIND_HIDDEN int __unw_is_signal_frame(unw_cursor_t *cursor) { } _LIBUNWIND_WEAK_ALIAS(__unw_is_signal_frame, unw_is_signal_frame) +_LIBUNWIND_HIDDEN const char *__unw_strerror(int error_code) { + switch (error_code) { + case UNW_ESUCCESS: +return "no error"; + case UNW_EUNSPEC: +return "unspecified (general) error"; + case UNW_ENOMEM: +return "out of memory"; + case UNW_EBADREG: +return "bad register number"; + case UNW_EREADONLYREG: +return "attempt to write read-only register"; + case UNW_ESTOPUNWIND: +return "stop unwinding"; + case UNW_EINVALIDIP: +return "invalid IP"; + case UNW_EBADFRAME: +return "bad frame"; + case UNW_EINVAL: +return "unsupported operation or bad value"; + case UNW_EBADVERSION: +return "unwind info has unsupported version"; + case UNW_ENOINFO: +return "no unwind info found"; +#if defined(_LIBUNWIND_TARGET_AARCH64) && !defined(_LIBUNWIND_IS_NATIVE_ONLY) + case UNW_ECROSSRASIGNING: +return "cross unwind with return address signing"; +#endif + default: +return "unknown error occurred"; + } +} +} +_LIBUNWIND_WEAK_ALIAS(__unw_strerror, unw_strerror) + #ifdef _AIX _LIBUNWIND_EXPORT uintptr_t __unw_get_data_rel_base(unw_cursor_t *cursor) { _LIBUNWIND_TRACE_API("unw_get_data_rel_base(cursor=%p)", ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Add unw_strerror function (PR #129084)
https://github.com/RossComputerGuy created https://github.com/llvm/llvm-project/pull/129084 Original implementation comes from https://github.com/reckenrode/nixpkgs/commit/099adeef42048d853df03f181103c6985c356d21 with permission from @reckenrode This implements the `unw_strerror` function which the other libunwind implements. Many packages, notable Xorg ones, use the strerror function from libunwind. When trying to link with the LLVM one, this causes a missing symbol error. By implementing this function, we are compatible with the non-LLVM libunwind. >From be32e69b68b1c72b034ea3c3001377c6bb74a36e Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 27 Feb 2025 09:10:22 -0800 Subject: [PATCH] [libunwind] Add unw_strerror function --- libunwind/include/libunwind.h | 2 ++ libunwind/src/libunwind.cpp | 35 +++ 2 files changed, 37 insertions(+) diff --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h index b2dae8feed9a3..839aa3dcf31c5 100644 --- a/libunwind/include/libunwind.h +++ b/libunwind/include/libunwind.h @@ -131,6 +131,8 @@ extern int unw_is_signal_frame(unw_cursor_t *) LIBUNWIND_AVAIL; extern int unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *) LIBUNWIND_AVAIL; //extern int unw_get_save_loc(unw_cursor_t*, int, unw_save_loc_t*); +extern const char *unw_strerror(int) LIBUNWIND_AVAIL; + extern unw_addr_space_t unw_local_addr_space; #ifdef __cplusplus diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp index cf39ec5f7dbdf..5bb40ff795bb9 100644 --- a/libunwind/src/libunwind.cpp +++ b/libunwind/src/libunwind.cpp @@ -260,6 +260,41 @@ _LIBUNWIND_HIDDEN int __unw_is_signal_frame(unw_cursor_t *cursor) { } _LIBUNWIND_WEAK_ALIAS(__unw_is_signal_frame, unw_is_signal_frame) +_LIBUNWIND_HIDDEN const char *__unw_strerror(int error_code) { + switch (error_code) { + case UNW_ESUCCESS: +return "no error"; + case UNW_EUNSPEC: +return "unspecified (general) error"; + case UNW_ENOMEM: +return "out of memory"; + case UNW_EBADREG: +return "bad register number"; + case UNW_EREADONLYREG: +return "attempt to write read-only register"; + case UNW_ESTOPUNWIND: +return "stop unwinding"; + case UNW_EINVALIDIP: +return "invalid IP"; + case UNW_EBADFRAME: +return "bad frame"; + case UNW_EINVAL: +return "unsupported operation or bad value"; + case UNW_EBADVERSION: +return "unwind info has unsupported version"; + case UNW_ENOINFO: +return "no unwind info found"; +#if defined(_LIBUNWIND_TARGET_AARCH64) && !defined(_LIBUNWIND_IS_NATIVE_ONLY) + case UNW_ECROSSRASIGNING: +return "cross unwind with return address signing"; +#endif + default: +return "unknown error occurred"; + } +} +} +_LIBUNWIND_WEAK_ALIAS(__unw_strerror, unw_strerror) + #ifdef _AIX _LIBUNWIND_EXPORT uintptr_t __unw_get_data_rel_base(unw_cursor_t *cursor) { _LIBUNWIND_TRACE_API("unw_get_data_rel_base(cursor=%p)", ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Add unw_strerror function (PR #129084)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/129084 >From 144809d95fab64843761629b384f9d41c1887cf3 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 27 Feb 2025 09:10:22 -0800 Subject: [PATCH] [libunwind] Add unw_strerror function Co-authored-by: Randy Eckenrode --- libunwind/include/libunwind.h | 2 ++ libunwind/src/libunwind.cpp | 34 ++ 2 files changed, 36 insertions(+) diff --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h index b2dae8feed9a3..839aa3dcf31c5 100644 --- a/libunwind/include/libunwind.h +++ b/libunwind/include/libunwind.h @@ -131,6 +131,8 @@ extern int unw_is_signal_frame(unw_cursor_t *) LIBUNWIND_AVAIL; extern int unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *) LIBUNWIND_AVAIL; //extern int unw_get_save_loc(unw_cursor_t*, int, unw_save_loc_t*); +extern const char *unw_strerror(int) LIBUNWIND_AVAIL; + extern unw_addr_space_t unw_local_addr_space; #ifdef __cplusplus diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp index cf39ec5f7dbdf..9f50c43ef10f0 100644 --- a/libunwind/src/libunwind.cpp +++ b/libunwind/src/libunwind.cpp @@ -260,6 +260,40 @@ _LIBUNWIND_HIDDEN int __unw_is_signal_frame(unw_cursor_t *cursor) { } _LIBUNWIND_WEAK_ALIAS(__unw_is_signal_frame, unw_is_signal_frame) +_LIBUNWIND_HIDDEN const char *__unw_strerror(int error_code) { + switch (error_code) { + case UNW_ESUCCESS: +return "no error"; + case UNW_EUNSPEC: +return "unspecified (general) error"; + case UNW_ENOMEM: +return "out of memory"; + case UNW_EBADREG: +return "bad register number"; + case UNW_EREADONLYREG: +return "attempt to write read-only register"; + case UNW_ESTOPUNWIND: +return "stop unwinding"; + case UNW_EINVALIDIP: +return "invalid IP"; + case UNW_EBADFRAME: +return "bad frame"; + case UNW_EINVAL: +return "unsupported operation or bad value"; + case UNW_EBADVERSION: +return "unwind info has unsupported version"; + case UNW_ENOINFO: +return "no unwind info found"; +#if defined(_LIBUNWIND_TARGET_AARCH64) && !defined(_LIBUNWIND_IS_NATIVE_ONLY) + case UNW_ECROSSRASIGNING: +return "cross unwind with return address signing"; +#endif + default: +return "unknown error occurred"; + } +} +_LIBUNWIND_WEAK_ALIAS(__unw_strerror, unw_strerror) + #ifdef _AIX _LIBUNWIND_EXPORT uintptr_t __unw_get_data_rel_base(unw_cursor_t *cursor) { _LIBUNWIND_TRACE_API("unw_get_data_rel_base(cursor=%p)", ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Add unw_strerror function (PR #129084)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/129084 >From b976a982b6ea9963bd88744b8ca1314852948a60 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 27 Feb 2025 09:10:22 -0800 Subject: [PATCH] [libunwind] Add unw_strerror function Co-authored-by: Randy Eckenrode --- libunwind/include/libunwind.h | 1 + libunwind/src/libunwind.cpp | 34 ++ libunwind/src/libunwind_ext.h | 1 + 3 files changed, 36 insertions(+) diff --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h index b2dae8feed9a3..f75101e030428 100644 --- a/libunwind/include/libunwind.h +++ b/libunwind/include/libunwind.h @@ -114,6 +114,7 @@ extern int unw_get_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t *) LIBUNWIND_ extern int unw_set_reg(unw_cursor_t *, unw_regnum_t, unw_word_t) LIBUNWIND_AVAIL; extern int unw_set_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t) LIBUNWIND_AVAIL; extern int unw_resume(unw_cursor_t *) LIBUNWIND_AVAIL; +extern const char *unw_strerror(int) LIBUNWIND_AVAIL; #ifdef __arm__ /* Save VFP registers in FSTMX format (instead of FSTMD). */ diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp index cf39ec5f7dbdf..9f50c43ef10f0 100644 --- a/libunwind/src/libunwind.cpp +++ b/libunwind/src/libunwind.cpp @@ -260,6 +260,40 @@ _LIBUNWIND_HIDDEN int __unw_is_signal_frame(unw_cursor_t *cursor) { } _LIBUNWIND_WEAK_ALIAS(__unw_is_signal_frame, unw_is_signal_frame) +_LIBUNWIND_HIDDEN const char *__unw_strerror(int error_code) { + switch (error_code) { + case UNW_ESUCCESS: +return "no error"; + case UNW_EUNSPEC: +return "unspecified (general) error"; + case UNW_ENOMEM: +return "out of memory"; + case UNW_EBADREG: +return "bad register number"; + case UNW_EREADONLYREG: +return "attempt to write read-only register"; + case UNW_ESTOPUNWIND: +return "stop unwinding"; + case UNW_EINVALIDIP: +return "invalid IP"; + case UNW_EBADFRAME: +return "bad frame"; + case UNW_EINVAL: +return "unsupported operation or bad value"; + case UNW_EBADVERSION: +return "unwind info has unsupported version"; + case UNW_ENOINFO: +return "no unwind info found"; +#if defined(_LIBUNWIND_TARGET_AARCH64) && !defined(_LIBUNWIND_IS_NATIVE_ONLY) + case UNW_ECROSSRASIGNING: +return "cross unwind with return address signing"; +#endif + default: +return "unknown error occurred"; + } +} +_LIBUNWIND_WEAK_ALIAS(__unw_strerror, unw_strerror) + #ifdef _AIX _LIBUNWIND_EXPORT uintptr_t __unw_get_data_rel_base(unw_cursor_t *cursor) { _LIBUNWIND_TRACE_API("unw_get_data_rel_base(cursor=%p)", diff --git a/libunwind/src/libunwind_ext.h b/libunwind/src/libunwind_ext.h index 28db43a4f6eef..b157a24300862 100644 --- a/libunwind/src/libunwind_ext.h +++ b/libunwind/src/libunwind_ext.h @@ -31,6 +31,7 @@ extern int __unw_get_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t *); extern int __unw_set_reg(unw_cursor_t *, unw_regnum_t, unw_word_t); extern int __unw_set_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t); extern int __unw_resume(unw_cursor_t *); +extern const char* __unw_strerror(int); #ifdef __arm__ /* Save VFP registers in FSTMX format (instead of FSTMD). */ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Add unw_strerror function (PR #129084)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/129084 >From 8fed3873f228232081533b614ac534473f6aa996 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 27 Feb 2025 09:10:22 -0800 Subject: [PATCH] [libunwind] Add unw_strerror function Co-authored-by: Randy Eckenrode --- libunwind/include/libunwind.h | 1 + libunwind/src/libunwind.cpp | 34 ++ libunwind/src/libunwind_ext.h | 1 + 3 files changed, 36 insertions(+) diff --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h index b2dae8feed9a3..f75101e030428 100644 --- a/libunwind/include/libunwind.h +++ b/libunwind/include/libunwind.h @@ -114,6 +114,7 @@ extern int unw_get_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t *) LIBUNWIND_ extern int unw_set_reg(unw_cursor_t *, unw_regnum_t, unw_word_t) LIBUNWIND_AVAIL; extern int unw_set_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t) LIBUNWIND_AVAIL; extern int unw_resume(unw_cursor_t *) LIBUNWIND_AVAIL; +extern const char *unw_strerror(int) LIBUNWIND_AVAIL; #ifdef __arm__ /* Save VFP registers in FSTMX format (instead of FSTMD). */ diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp index cf39ec5f7dbdf..9f50c43ef10f0 100644 --- a/libunwind/src/libunwind.cpp +++ b/libunwind/src/libunwind.cpp @@ -260,6 +260,40 @@ _LIBUNWIND_HIDDEN int __unw_is_signal_frame(unw_cursor_t *cursor) { } _LIBUNWIND_WEAK_ALIAS(__unw_is_signal_frame, unw_is_signal_frame) +_LIBUNWIND_HIDDEN const char *__unw_strerror(int error_code) { + switch (error_code) { + case UNW_ESUCCESS: +return "no error"; + case UNW_EUNSPEC: +return "unspecified (general) error"; + case UNW_ENOMEM: +return "out of memory"; + case UNW_EBADREG: +return "bad register number"; + case UNW_EREADONLYREG: +return "attempt to write read-only register"; + case UNW_ESTOPUNWIND: +return "stop unwinding"; + case UNW_EINVALIDIP: +return "invalid IP"; + case UNW_EBADFRAME: +return "bad frame"; + case UNW_EINVAL: +return "unsupported operation or bad value"; + case UNW_EBADVERSION: +return "unwind info has unsupported version"; + case UNW_ENOINFO: +return "no unwind info found"; +#if defined(_LIBUNWIND_TARGET_AARCH64) && !defined(_LIBUNWIND_IS_NATIVE_ONLY) + case UNW_ECROSSRASIGNING: +return "cross unwind with return address signing"; +#endif + default: +return "unknown error occurred"; + } +} +_LIBUNWIND_WEAK_ALIAS(__unw_strerror, unw_strerror) + #ifdef _AIX _LIBUNWIND_EXPORT uintptr_t __unw_get_data_rel_base(unw_cursor_t *cursor) { _LIBUNWIND_TRACE_API("unw_get_data_rel_base(cursor=%p)", diff --git a/libunwind/src/libunwind_ext.h b/libunwind/src/libunwind_ext.h index 28db43a4f6eef..ad9d15237fdc4 100644 --- a/libunwind/src/libunwind_ext.h +++ b/libunwind/src/libunwind_ext.h @@ -31,6 +31,7 @@ extern int __unw_get_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t *); extern int __unw_set_reg(unw_cursor_t *, unw_regnum_t, unw_word_t); extern int __unw_set_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t); extern int __unw_resume(unw_cursor_t *); +extern const char *__unw_strerror(int); #ifdef __arm__ /* Save VFP registers in FSTMX format (instead of FSTMD). */ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix UEFI Target info (PR #127290)
RossComputerGuy wrote: Alright, if it does fix it then we should get this moving so libc pre-commits working with UEFI isn't blocked. https://github.com/llvm/llvm-project/pull/127290 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] fix uefi target for aarch64 & x86_64 (PR #120632)
https://github.com/RossComputerGuy updated https://github.com/llvm/llvm-project/pull/120632 >From e0d525f801f65588aa6b22a2827036a4c2d9c91c Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 10:54:58 -0800 Subject: [PATCH 1/4] [clang] fix uefi data layout on x86 & aarch64 --- clang/lib/Basic/Targets/AArch64.cpp | 3 +++ clang/lib/Basic/Targets/X86.h | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/Targets/AArch64.cpp b/clang/lib/Basic/Targets/AArch64.cpp index 3633bab6e0df9..56fb1c42e3883 100644 --- a/clang/lib/Basic/Targets/AArch64.cpp +++ b/clang/lib/Basic/Targets/AArch64.cpp @@ -1626,6 +1626,9 @@ void AArch64leTargetInfo::setDataLayout() { resetDataLayout("e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-" "n32:64-S128-Fn32", "_"); + } else if (getTriple().isUEFI() && getTriple().isOSBinFormatCOFF()) { +resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-" +"i64:64-i128:128-n32:64-S128-Fn32"); } else resetDataLayout("e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-" "i64:64-i128:128-n32:64-S128-Fn32"); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 205edcab9ccb3..e3a56f2c9f56f 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -722,8 +722,8 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { X86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : X86TargetInfo(Triple, Opts) { const bool IsX32 = getTriple().isX32(); -bool IsWinCOFF = -getTriple().isOSWindows() && getTriple().isOSBinFormatCOFF(); +bool IsWinCOFF = (getTriple().isOSWindows() || getTriple().isUEFI()) && + getTriple().isOSBinFormatCOFF(); LongWidth = LongAlign = PointerWidth = PointerAlign = IsX32 ? 32 : 64; LongDoubleWidth = 128; LongDoubleAlign = 128; >From 6d242b0e4d095f93b99ff927b4064a8b95d69fc5 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 13:40:50 -0800 Subject: [PATCH 2/4] [clang] add __uefi__ test for aarch64 & x86_64 --- clang/test/Preprocessor/init.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 1ac325d444662..a61822683a805 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/test/Preprocessor/init.c @@ -2835,6 +2835,8 @@ // RISCV64-LINUX: #define unix 1 // RUN: %clang_cc1 -dM -triple=x86_64-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s +// RUN: %clang_cc1 -dM -triple=aarch64-unknown-uefi -E < /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s +// RUN: %clang_cc1 -dM -triple=x86_64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s // UEFI: #define __UEFI__ 1 >From dfcd456a4a64f6fd87f2ab3b2d2b744882151761 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 13:52:26 -0800 Subject: [PATCH 3/4] [clang] add uefi to target os macros --- clang/include/clang/Basic/TargetOSMacros.def | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/include/clang/Basic/TargetOSMacros.def b/clang/include/clang/Basic/TargetOSMacros.def index 58dce330f9c8f..f4f3276ad1c25 100644 --- a/clang/include/clang/Basic/TargetOSMacros.def +++ b/clang/include/clang/Basic/TargetOSMacros.def @@ -53,4 +53,7 @@ TARGET_OS(TARGET_OS_NANO, Triple.isWatchOS()) TARGET_OS(TARGET_IPHONE_SIMULATOR, Triple.isSimulatorEnvironment()) TARGET_OS(TARGET_OS_UIKITFORMAC, Triple.isMacCatalystEnvironment()) +// UEFI target. +TARGET_OS(TARGET_OS_UEFI, Triple.isUEFI()) + #undef TARGET_OS >From 3177fc84a83730850d86083373056b3efd4bc2b1 Mon Sep 17 00:00:00 2001 From: Tristan Ross Date: Thu, 19 Dec 2024 14:13:09 -0800 Subject: [PATCH 4/4] [clang] use mixin for aarch64 and x86_64 uefi --- clang/lib/Basic/Targets.cpp | 6 +- clang/lib/Basic/Targets/OSTargets.h | 13 +++- clang/lib/Basic/Targets/X86.h | 32 - 3 files changed, 17 insertions(+), 34 deletions(-) diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index c6d228fe98100..fcc253fc8cbcb 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -170,6 +170,10 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, case llvm::Triple::OpenBSD: return std::make_unique>(Triple, Opts); +case llvm::Triple::UEFI: + return std::make_unique>(Triple, + Opts); + case llvm::Triple::Win32: switch (Triple.getEnvironment()) { case llvm::Triple::GNU: @@ -631,7 +635,7 @@ std::unique_ptr AllocateTarget(const llvm::Triple &Triple, return std::make_unique>(Triple,
[clang] [clang] Fix UEFI Target info (PR #127290)
RossComputerGuy wrote: Would this unblock #131376? https://github.com/llvm/llvm-project/pull/127290 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix UEFI Target info (PR #127290)
@@ -835,16 +835,22 @@ class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo public: UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) : UEFITargetInfo(Triple, Opts) { +LongWidth = LongAlign = 32; +DoubleAlign = LongLongAlign = 64; +IntMaxType = SignedLongLong; +Int64Type = SignedLongLong; +SizeType = UnsignedLongLong; +PtrDiffType = SignedLongLong; +IntPtrType = SignedLongLong; +LongDoubleWidth = LongDoubleAlign = 64; +LongDoubleFormat = &llvm::APFloat::IEEEdouble(); RossComputerGuy wrote: I've asked someone who does work quite often with EFI stuff and they don't know either. It sounds like it's up to the developer to handle it. It's possible it's not even allowed. https://github.com/llvm/llvm-project/pull/127290 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits