From 2b8b7780d10728eccf5747b64f4abfd263ecf666 Mon Sep 17 00:00:00 2001 From: Ruoyu Zhong Date: Sat, 7 Dec 2024 17:20:24 +0800 Subject: [PATCH] WIP --- Library/Homebrew/extend/ENV/super.rb | 1 + .../extend/os/linux/extend/ENV/super.rb | 18 ++++++++++++++++-- Library/Homebrew/shims/super/cc | 14 ++++++++------ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index c21bd3ce846f2..ae9cb6c927019 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -306,6 +306,7 @@ def determine_optflags odebug "Building a bottle for custom architecture (#{effective_arch})..." Hardware::CPU.arch_flag(effective_arch) end + alias generic_determine_optflags determine_optflags sig { returns(String) } def determine_cccfg diff --git a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb index f0aa87920edad..2ff75afa1240b 100644 --- a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb @@ -45,8 +45,9 @@ def homebrew_extra_paths def homebrew_extra_isystem_paths paths = [] - # Add paths for GCC headers when building against glibc@2.13 because we have to use -nostdinc. - if deps.any? { |d| d.name == "glibc@2.13" } + # Add paths for GCC headers when building against glibc@2.13 or glibc@2.17 + # because we have to use -nostdinc. + if deps.any? { |d| d.name == "glibc@2.13" || d.name == "glibc@2.17" } gcc_include_dir = Utils.safe_popen_read(cc, "--print-file-name=include").chomp gcc_include_fixed_dir = Utils.safe_popen_read(cc, "--print-file-name=include-fixed").chomp paths << gcc_include_dir << gcc_include_fixed_dir @@ -54,6 +55,19 @@ def homebrew_extra_isystem_paths paths end + sig { returns(String) } + def determine_optflags + if effective_arch == :armv8 && + compiler.match?(GNU_GCC_REGEXP) && + DevelopmentTools.gcc_version(compiler.to_s) >= "9.3.1" + # Out-of-line atomics are not supported out-of-the-box on all systems. + # https://learn.arm.com/learning-paths/servers-and-cloud-computing/lse/intro/ + "#{generic_determine_optflags} -mno-outline-atomics" + else + generic_determine_optflags + end + end + def determine_rpath_paths(formula) PATH.new( *formula&.lib, diff --git a/Library/Homebrew/shims/super/cc b/Library/Homebrew/shims/super/cc index 458a5dc236fa2..c2233ffa20697 100755 --- a/Library/Homebrew/shims/super/cc +++ b/Library/Homebrew/shims/super/cc @@ -313,8 +313,9 @@ class Cmd def cppflags args = [] args += path_flags("-isystem", isystem_paths) + path_flags("-I", include_paths) - # Add -nostdinc when building against glibc@2.13 to avoid mixing system and brewed glibc headers. - args << "-nostdinc" if @deps.include?("glibc@2.13") + # Add -nostdinc when building against glibc@2.13 or glibc@2.17 to avoid + # mixing system and brewed glibc headers. + args << "-nostdinc" if (@deps & ["glibc@2.13", "glibc@2.17"]).any? # Ideally this would be -ffile-prefix-map, but that requires a minimum of GCC 8, LLVM Clang 10 or Apple Clang 12 # and detecting the version dynamically based on what `HOMEBREW_CC` may have been rewritten to point to is awkward args << "-fdebug-prefix-map=#{formula_buildpath}=." if formula_buildpath && !debug_symbols? @@ -340,19 +341,20 @@ class Cmd end def ldflags_linux(args) + versioned_glibc_dep = (@deps & ["glibc@2.13", "glibc@2.17"]).first unless mode == :ld wl = "-Wl," - if @deps.include?("glibc@2.13") - args << "-B#{@opt}/glibc@2.13/lib" + if versioned_glibc_dep + args << "-B#{@opt}/#{versioned_glibc_dep}/lib" else args << "-B#{@opt}/glibc/lib" end end args += rpath_flags("#{wl}-rpath=", rpath_paths) args += ["#{wl}--dynamic-linker=#{dynamic_linker_path}"] if dynamic_linker_path - # Use -rpath-link to make sure linker uses glibc@2.13 rather than the system glibc for indirect + # Use -rpath-link to make sure linker uses glibc@2.13 or glibc@2.17 rather than the system glibc for indirect # dependencies because -L will only handle direct dependencies. - args << "#{wl}-rpath-link=#{@opt}/glibc@2.13/lib" if @deps.include?("glibc@2.13") + args << "#{wl}-rpath-link=#{@opt}/#{versioned_glibc_dep}/lib" if versioned_glibc_dep args end