From 653a54727eaa18c43447ad686c987db67f1dda74 Mon Sep 17 00:00:00 2001 From: Ian Anderson Date: Mon, 6 Jan 2025 21:33:51 -0800 Subject: [Darwin][Driver][clang] apple-none-macho orders the resource directory after internal-externc-isystem when nostdlibinc is used (#120507) Embedded development often needs to use a different C standard library, replacing the existing one normally passed as -internal-externc-isystem. This works fine for an apple-macos target, but apple-none-macho doesn't work because the MachO driver doesn't implement AddClangSystemIncludeArgs to add the resource directory as -internal-isystem like most other drivers do. Move most of the search path logic from Darwin and DarwinClang down into an AppleMachO toolchain between the MachO and Darwin toolchains. Also define \_\_MACH__ for apple-none-macho, as Swift expects all MachO targets to have that defined. --- clang/lib/Frontend/InitPreprocessor.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'clang/lib/Frontend/InitPreprocessor.cpp') diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 29723b5..8eba766 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1507,6 +1507,11 @@ static void InitializePredefinedMacros(const TargetInfo &TI, // ELF targets define __ELF__ if (TI.getTriple().isOSBinFormatELF()) Builder.defineMacro("__ELF__"); + else if (TI.getTriple().isAppleMachO()) + // Apple MachO targets define __MACH__ even when not using DarwinTargetInfo. + // Hurd will also define this in some circumstances, but that's done in + // HurdTargetInfo. Windows targets don't define this. + Builder.defineMacro("__MACH__"); // Target OS macro definitions. if (PPOpts.DefineTargetOSMacros) { -- cgit v1.1 From ab5133bbc62af4686f305a3c7d85f74b9f5b949f Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 7 Jan 2025 09:23:50 -0500 Subject: Revert "[Darwin][Driver][clang] apple-none-macho orders the resource directory after internal-externc-isystem when nostdlibinc is used (#120507)" This reverts commit 653a54727eaa18c43447ad686c987db67f1dda74. Breaks tests, see https://github.com/llvm/llvm-project/pull/120507#issuecomment-2575246281 --- clang/lib/Frontend/InitPreprocessor.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'clang/lib/Frontend/InitPreprocessor.cpp') diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 8eba766..29723b5 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1507,11 +1507,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI, // ELF targets define __ELF__ if (TI.getTriple().isOSBinFormatELF()) Builder.defineMacro("__ELF__"); - else if (TI.getTriple().isAppleMachO()) - // Apple MachO targets define __MACH__ even when not using DarwinTargetInfo. - // Hurd will also define this in some circumstances, but that's done in - // HurdTargetInfo. Windows targets don't define this. - Builder.defineMacro("__MACH__"); // Target OS macro definitions. if (PPOpts.DefineTargetOSMacros) { -- cgit v1.1 From d6bfe10ac9963eb63e141d6c50e9a183c08d35da Mon Sep 17 00:00:00 2001 From: Ian Anderson Date: Tue, 7 Jan 2025 21:13:49 -0800 Subject: [Darwin][Driver][clang] apple-none-macho orders the resource directory after internal-externc-isystem when nostdlibinc is used (#122035) Embedded development often needs to use a different C standard library, replacing the existing one normally passed as -internal-externc-isystem. This works fine for an apple-macos target, but apple-none-macho doesn't work because the MachO driver doesn't implement AddClangSystemIncludeArgs to add the resource directory as -internal-isystem like most other drivers do. Move most of the search path logic from Darwin and DarwinClang down into an AppleMachO toolchain between the MachO and Darwin toolchains. Also define __MACH__ for apple-none-macho, as Swift expects all MachO targets to have that defined. --- clang/lib/Frontend/InitPreprocessor.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'clang/lib/Frontend/InitPreprocessor.cpp') diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index 29723b5..8eba766 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1507,6 +1507,11 @@ static void InitializePredefinedMacros(const TargetInfo &TI, // ELF targets define __ELF__ if (TI.getTriple().isOSBinFormatELF()) Builder.defineMacro("__ELF__"); + else if (TI.getTriple().isAppleMachO()) + // Apple MachO targets define __MACH__ even when not using DarwinTargetInfo. + // Hurd will also define this in some circumstances, but that's done in + // HurdTargetInfo. Windows targets don't define this. + Builder.defineMacro("__MACH__"); // Target OS macro definitions. if (PPOpts.DefineTargetOSMacros) { -- cgit v1.1