From d62c847b77db57fed3272af197b7c7c86af3f09f Mon Sep 17 00:00:00 2001 From: SupeChicken666 Date: Fri, 2 May 2025 19:24:00 +0800 Subject: [PATCH] crew: Set dynamic linker path in linker (#11817) * crew: Set dynamic linker path in linker Signed-off-by: SupeChicken666 Fix constant order Signed-off-by: SupeChicken666 Suggested changes Signed-off-by: SupeChicken666 Merge CREW_LDFLAGS and CREW_LINKER_FLAGS Signed-off-by: SupeChicken666 Adjust argument order Signed-off-by: SupeChicken666 Fix CREW_GLIBC_PREFIX, add LIBRARY_PATH for gcc Signed-off-by: SupeChicken666 Add some patches from Chromium OS Signed-off-by: SupeChicken666 Bump version Signed-off-by: SupeChicken666 Add install-locales line Signed-off-by: SupeChicken666 Add comments Signed-off-by: SupeChicken666 Remove LD_LIBRARY_PATH from CREW_ENV_OPTIONS Signed-off-by: SupeChicken666 Add `CREW_GLIBC_PREFIX` to linker search path Signed-off-by: SupeChicken666 Set minimum kernel version to 3.2 for all architectures Signed-off-by: SupeChicken666 Pass CERW_PREFIX with macro Signed-off-by: SupeChicken666 Fix asprintf usage Signed-off-by: SupeChicken666 Fix macro usage Signed-off-by: SupeChicken666 Move all patches into a separate repo Signed-off-by: SupeChicken666 * Add finishing touches :) Signed-off-by: SupeChicken666 Set compiler search path also Signed-off-by: SupeChicken666 Fix installation path Signed-off-by: SupeChicken666 Rebuilt binaries with same version Signed-off-by: SupeChicken666 * lint Signed-off-by: Satadru Pramanik * bump version Signed-off-by: Satadru Pramanik * Fix already initialized constant error. Signed-off-by: Satadru Pramanik * Merge changes from #11828 Signed-off-by: SupeChicken666 * crew: Run `upx -d` and `patchelf` on existing/to-be-installed packages Signed-off-by: SupeChicken666 * Fix syntax Signed-off-by: SupeChicken666 Silence output Signed-off-by: SupeChicken666 * Suggested changes Signed-off-by: SupeChicken666 Re-add `2> /dev/null` to upx commands Signed-off-by: SupeChicken666 Fix `patchelf` usage Signed-off-by: SupeChicken666 Correct function name Signed-off-by: SupeChicken666 Fix CI build test Signed-off-by: SupeChicken666 Make rubocop happy Signed-off-by: SupeChicken666 * Update search cache for on postinstall Signed-off-by: SupeChicken666 * Add a config file for ld.so Signed-off-by: SupeChicken666 * Suggested changes Signed-off-by: SupeChicken666 * Add built packages for linux/386 to set_dynamic_linker * Add built packages for linux/amd64 to set_dynamic_linker * Add built packages for linux/arm/v7 to set_dynamic_linker * Update install.sh Signed-off-by: SupeChicken666 * Fix rubocop Signed-off-by: SupeChicken666 --------- Signed-off-by: SupeChicken666 Signed-off-by: Satadru Pramanik Co-authored-by: Satadru Pramanik Co-authored-by: supechicken --- bin/crew | 125 ++--------- commands/remove.rb | 3 +- install.sh | 56 +++-- lib/const.rb | 38 ++-- lib/fixup.rb | 34 +-- manifest/armv7l/g/glibc_standalone.filelist | 3 + .../armv7l/h/hello_world_chromebrew.filelist | 1 + manifest/i686/g/glibc_standalone.filelist | 3 + .../i686/h/hello_world_chromebrew.filelist | 1 + manifest/x86_64/g/glibc_standalone.filelist | 3 + .../x86_64/h/hello_world_chromebrew.filelist | 1 + packages/bsdgames.rb | 2 +- packages/busybox.rb | 2 +- packages/core.rb | 3 +- packages/docker.rb | 6 +- packages/glibc_standalone.rb | 202 +++++------------- packages/hello_world_chromebrew.rb | 15 +- packages/perl.rb | 2 +- packages/pipewire.rb | 2 +- packages/samurai.rb | 2 +- 20 files changed, 156 insertions(+), 348 deletions(-) create mode 100644 manifest/armv7l/h/hello_world_chromebrew.filelist create mode 100644 manifest/i686/h/hello_world_chromebrew.filelist create mode 100644 manifest/x86_64/h/hello_world_chromebrew.filelist diff --git a/bin/crew b/bin/crew index f45ca2255..fd90a01e9 100755 --- a/bin/crew +++ b/bin/crew @@ -883,71 +883,31 @@ def prepare_package(destdir) File.write('dlist', "#{directorylist.join("\n")}\n") strip_dir destdir - - # use upx on executables - # shrink_dir destdir end end -def patchelf_set_need_paths(dir) - return if @pkg.no_patchelf? || @pkg.no_compile_needed? +def fix_interpreter_path(dir) + # Do not set interpreter for non-musl, as this can break apps if there + # is an issue with the crew glibc. + return if @pkg.is_musl? - puts 'Patchelf is currently disabled during builds due to problems with upx.'.yellow - return - - # Disable unreachable code check, as this is a temporary situation - # rubocop:disable Lint/UnreachableCode Dir.chdir dir do - puts 'Running patchelf'.lightblue - abort('No Patchelf found!').lightred unless File.file?("#{CREW_PREFIX}/bin/patchelf") + puts 'Running patchelf and upx'.lightblue + abort('No Patchelf found!').lightred unless File.file?("#{CREW_PREFIX}/bin/patchelf") && File.file?("#{CREW_PREFIX}/bin/upx") execfiles = `find . -executable -type f ! \\( -name '*.a' \\) | xargs -P#{CREW_NPROC} -n1 sh -c '[ "$(head -c4 ${1})" = "\x7FELF" ] && echo ${1}' --`.chomp return if execfiles.empty? - patchelf_lib_prefix = @pkg.is_musl? ? "#{CREW_MUSL_PREFIX}/lib" : CREW_LIB_PREFIX - puts "patchelf_lib_prefix is #{patchelf_lib_prefix}" if CREW_VERBOSE - patchelf_interpreter = @pkg.is_musl? ? "#{CREW_MUSL_PREFIX}/lib/libc.so" : 'CREW_LIB_PREFIX/libc.so.6' - puts "patchelf_interpreter is #{patchelf_interpreter}" if CREW_VERBOSE - - puts 'Running patchelf to patch binaries for library paths'.lightblue + puts 'Running patchelf to patch binary interpreter paths'.lightblue execfiles.each_line(chomp: true) do |execfiletopatch| execfiletopatch = Dir.pwd + execfiletopatch.delete_prefix('.') neededlibs = `patchelf --print-needed #{execfiletopatch}` next if neededlibs.to_s.empty? - neededlibs.each_line(chomp: true) do |neededlibspatch| - next if neededlibspatch.include?(patchelf_lib_prefix.to_s) - - # Avoid segfaults from not using system versions of these files. - patchelf_veto_files = %w[ - libdl.so - ld-linux.so.2 - ld-linux-x86-64.so.2 - ld-linux-armhf.so.3 - libc.so.6 - ] - next if !@pkg.is_musl? && patchelf_veto_files.any? { |i| neededlibspatch.include? i } - - neededlib_basename = File.basename(neededlibspatch) - neededlibspatchednamepath = "#{patchelf_lib_prefix}/" + neededlib_basename - # The first check here can be changed to just check the dest_dir - # hierarchy for neededlib_basename if the intent is to allow - # using a different CREW_PREFIX during package installs. - if File.file?(neededlibspatchednamepath) || File.file?(Dir.pwd + neededlibspatchednamepath) - puts "patchelf --replace-needed #{neededlibspatch} #{neededlibspatchednamepath} #{execfiletopatch}" if CREW_VERBOSE - system "patchelf --replace-needed #{neededlibspatch} #{neededlibspatchednamepath} #{execfiletopatch}" - else - puts "#{execfiletopatch} needed library #{neededlib_basename} not found in #{patchelf_lib_prefix} or #{Dir.pwd + neededlibspatchednamepath}.".lightred - end - end - # Do not set interpreter for non-musl, as this can break apps if there - # is an issue with the crew glibc. - next unless @pkg.is_musl? - - puts 'Running patchelf to patch binary interpreter paths'.lightblue - system "patchelf --set-interpreter #{patchelf_interpreter} #{execfiletopatch}" + system "upx -qq -d #{execfiletopatch} 2> /dev/null" + system "patchelf --set-interpreter #{CREW_GLIBC_INTERPRETER} #{execfiletopatch} 2> /dev/null" + system "patchelf --remove-rpath #{execfiletopatch} 2> /dev/null" end end - # rubocop:enable Lint/UnreachableCode end def strip_find_files(find_cmd, strip_option = '') @@ -985,69 +945,6 @@ def shrink_dir(dir) puts 'Using rdfind to convert duplicate files to hard links.' system "#{CREW_PREFIX}/bin/rdfind -removeidentinode true -makesymlinks false -makehardlinks true -makeresultsfile false ." end - # Issues with non-x86_64 in compressing libraries, so just compress - # non-libraries. Also note that one needs to use "upx -d" on a - # compressed file to use ldd. - # sommelier also isn't happy when sommelier and xwayland are compressed - # so don't compress those packages. - if File.executable?("#{CREW_PREFIX}/bin/upx") - # 1. Find executable binaries but also check for hard linked - # files by making sure we have a unique set of - # inodes for the binaries found. - # 2. Copy to a temp file. - # 3. Compress using upx. (Uncompressble files are ignored.) - # 4. Check compression by expanding the compressed file with - # upx. - # 5. If the expansion doesn't error out then it is ok to copy - # over the original. (This also lets us only avoid compressing - # hard linked files multiple times.) - execfiles = `find . -executable -type f ! \\( -name '*.so*' -o -name '*.a' \\) | xargs -P8 -n1 sh -c '[ "$(head -c4 ${1})" = "\x7FELF" ] && echo ${1}' --`.chomp - - unless execfiles.empty? - puts 'Using upx to shrink binaries.' - # Copying in the ThreadPoolExecutor loop fails non-deterministically - execfiles.each_line(chomp: true) do |execfilecp| - execfilecp.slice! '.' - next if execfilecp.empty? - - execfilecp = File.join(dir, execfilecp) - next unless File.file?(execfilecp) - - FileUtils.cp execfilecp, "#{execfilecp}-crewupxtmp" - end - require_gem 'concurrent-ruby' - pool = Concurrent::ThreadPoolExecutor.new( - min_threads: 1, - max_threads: CREW_NPROC, - max_queue: 0, # unbounded work queue - fallback_policy: :caller_runs - ) - execfiles.each_line(chomp: true) do |execfile| - pool.post do - execfile.slice! '.' - execfile = File.join(dir, execfile) - puts "Attempting to compress #{execfile} ...".orange - # Make tmp file for compression - unless system "upx --lzma #{execfile}-crewupxtmp" - puts "Compression of #{execfile} failed...".orange if CREW_VERBOSE - FileUtils.rm_f "#{execfile}-crewupxtmp" - end - if File.file?("#{execfile}-crewupxtmp") - puts "Testing compressed #{execfile}...".lightblue if CREW_VERBOSE - if system 'upx', '-t', "#{execfile}-crewupxtmp" - puts "#{execfile} successfully compressed...".lightgreen - FileUtils.cp "#{execfile}-crewupxtmp", execfile - end - end - FileUtils.rm_f "#{execfile}-crewupxtmp" - end - end - pool.shutdown - pool.wait_for_termination - # Make sure temporary compression copies are deleted. - FileUtils.rm Dir['**/*-crewupxtmp'] - end - end end end end @@ -1108,6 +1005,8 @@ def install_package(pkgdir) end end + fix_interpreter_path(".#{CREW_PREFIX}") + install_files(".#{CREW_PREFIX}") if Dir.exist?(".#{CREW_PREFIX}") install_files(".#{HOME}", HOME) if Dir.exist?(".#{HOME}") end diff --git a/commands/remove.rb b/commands/remove.rb index 76670195e..7f16301a0 100644 --- a/commands/remove.rb +++ b/commands/remove.rb @@ -58,7 +58,8 @@ class Command if File.file?(filelist_path) filelist = File.readlines(filelist_path, chomp: true) overlap_files = ConvenienceFunctions.determine_conflicts(pkg.name, filelist_path, verbose: verbose) - essential_files = CREW_ESSENTIAL_PACKAGES.flat_map { |f| File.readlines(File.join(CREW_META_PATH, "#{f}.filelist"), chomp: true)} + # essential_files should only contain filelists for packages already installed. + essential_files = CREW_ESSENTIAL_PACKAGES.flat_map { |f| File.readlines(File.join(CREW_META_PATH, "#{f}.filelist"), chomp: true) if File.file?(File.join(CREW_META_PATH, "#{f}.filelist")) } overlap_essential_files = filelist & essential_files files_to_remove = filelist - overlap_files.values.flatten - overlap_essential_files diff --git a/install.sh b/install.sh index 8ab7811da..1ca635db0 100755 --- a/install.sh +++ b/install.sh @@ -31,7 +31,8 @@ lsbval() { } # Print a message before exit on error -trap "echo_error 'An error occured during the installation :/'" ERR +set_trap() { trap "echo_error 'An error occured during the installation :/'" ERR; } +set_trap # Check if the script is being run as root. if [ "${EUID}" == "0" ]; then @@ -129,9 +130,6 @@ if [[ "$ARCH" == "x86_64" ]]; then LIB_SUFFIX='64' fi -# Package version string may include LIBC_VERSION. -LIBC_VERSION=$(/lib"$LIB_SUFFIX"/libc.so.6 2>/dev/null | awk 'match($0, /Gentoo ([^-]+)/) {print substr($0, RSTART+7, RLENGTH-7)}') - # Warn users of the AMD segfault issue and allow them to work around it. # The easiest way to distinguish StoneyRidge platorms is to check for the FMA4 # instruction, as it was first introduced in Bulldozer and later dropped in Zen. @@ -193,32 +191,16 @@ echo_out 'Set up the local package repo...' # Download the chromebrew repository. curl_wrapper -L --progress-bar https://github.com/"${OWNER}"/"${REPO}"/tarball/"${BRANCH}" | tar -xz --strip-components=1 -C "${CREW_LIB_PATH}" -BOOTSTRAP_PACKAGES='lz4 zlib xzutils zstd zlib_ng crew_mvdir ruby git ca_certificates libyaml openssl' +BOOTSTRAP_PACKAGES='glibc_standalone libxcrypt upx patchelf lz4 zlib xzutils zstd zlib_ng crew_mvdir ruby git ca_certificates libyaml openssl gmp' # Older i686 systems. [[ "${ARCH}" == "i686" ]] && BOOTSTRAP_PACKAGES+=' gcc_lib' if [[ -n "${CHROMEOS_RELEASE_CHROME_MILESTONE}" ]]; then # shellcheck disable=SC2231 - for i in /lib$LIB_SUFFIX/libc.so* - do - sudo cp "$i" "$CREW_PREFIX/lib$LIB_SUFFIX/" - libcname=$(basename "$i") - sudo chown chronos "$CREW_PREFIX/lib$LIB_SUFFIX/${libcname}" - sudo chmod 644 "$CREW_PREFIX/lib$LIB_SUFFIX/${libcname}" - done if (( "${CHROMEOS_RELEASE_CHROME_MILESTONE}" > "112" )); then # Recent Arm systems have a cut down system. [[ "${ARCH}" == "armv7l" ]] && BOOTSTRAP_PACKAGES+=' bzip2 ncurses readline pcre2 gcc_lib' - if (( "${CHROMEOS_RELEASE_CHROME_MILESTONE}" < "123" )); then - # Append the correct packages for systems running M122 and lower. - BOOTSTRAP_PACKAGES+=' glibc_lib235 gmp' - elif (( "${CHROMEOS_RELEASE_CHROME_MILESTONE}" > "122" )); then - # Append the correct packages for systems running M123 onwards. - # X86_64 requires patchelf patching of the system libc.so.6. - [[ "$ARCH" == "x86_64" ]] && BOOTSTRAP_PACKAGES+=' patchelf' - BOOTSTRAP_PACKAGES+=' glibc_lib237 gmp' - fi fi fi @@ -323,8 +305,28 @@ function extract_install () { fi fi - echo_intra "Installing ${1} ..." + echo_intra "Installing ${1}..." tar cpf - ./*/* | (cd /; tar xp --keep-directory-symlink -m -f -) + + if [[ "${1}" == 'glibc_standalone' ]]; then + # set LD_AUDIT to ignore libC.so.6 requests + export LD_AUDIT="${CREW_PREFIX}/opt/glibc-libs/crew-audit.so" + + # update ld.so cache + ldconfig + else + # decompress and switch to glibc_standalone for existing binaries + if command -v upx &> /dev/null; then + echo_intra "Running upx on ${1}..." + grep "/usr/local/\(bin\|lib\|lib${LIB_SUFFIX}\)" < filelist | xargs -P "$(nproc)" -n1 upx -qq -d 2> /dev/null || true + fi + + if command -v patchelf &> /dev/null; then + echo_intra "Running patchelf on ${1}..." + grep '/usr/local/bin' < filelist | xargs -P "$(nproc)" -n1 patchelf --set-interpreter "${CREW_PREFIX}/bin/ld.so" 2> /dev/null || true + fi + fi + mv ./dlist "${CREW_META_PATH}/${1}.directorylist" mv ./filelist "${CREW_META_PATH}/${1}.filelist" } @@ -393,14 +395,6 @@ ln -sfv "../lib/crew/bin/crew" "${CREW_PREFIX}/bin/" echo "export CREW_PREFIX=${CREW_PREFIX}" >> "${CREW_PREFIX}/etc/env.d/profile" -if (( "${CHROMEOS_RELEASE_CHROME_MILESTONE}" > "122" )) && [[ "$ARCH" == "x86_64" ]]; then - echo_info "This Milestone (M${CHROMEOS_RELEASE_CHROME_MILESTONE}) needs to have libc.so.6 patched for the Chromebrew Glibc." - cp "/lib${LIB_SUFFIX}/libc.so.6" /tmp/libc.so.6.tmp - patchelf --add-needed libC.so.6 /tmp/libc.so.6.tmp - env -u LD_LIBRARY_PATH cp /tmp/libc.so.6.tmp "${CREW_PREFIX}/lib${LIB_SUFFIX}/libc.so.6" - rm /tmp/libc.so.6.tmp -fi - echo_info 'Updating RubyGems...' gem sources -u gem update --no-update-sources -N --system @@ -428,7 +422,7 @@ install_ruby_gem ${BOOTSTRAP_GEMS} echo_info "Installing crew_profile_base...\n" yes | crew install crew_profile_base # shellcheck disable=SC1090 -ARCH="$ARCH" source ~/.bashrc +trap - ERR && source ~/.bashrc && set_trap echo_info "Installing core Chromebrew packages...\n" yes | crew install core diff --git a/lib/const.rb b/lib/const.rb index 052d467eb..2d72a2e23 100644 --- a/lib/const.rb +++ b/lib/const.rb @@ -3,7 +3,7 @@ require 'etc' OLD_CREW_VERSION ||= defined?(CREW_VERSION) ? CREW_VERSION : '1.0' -CREW_VERSION ||= '1.59.5' unless defined?(CREW_VERSION) && CREW_VERSION == OLD_CREW_VERSION +CREW_VERSION ||= '1.59.6' unless defined?(CREW_VERSION) && CREW_VERSION == OLD_CREW_VERSION # Kernel architecture. KERN_ARCH ||= Etc.uname[:machine] @@ -44,7 +44,7 @@ end # These are packages that crew needs to run-- only packages that the bin/crew needs should be required here. # lz4, for example, is required for zstd to have lz4 support, but this is not required to run bin/crew. # The LIBC_VERSION ternary is to reflect the change from glibc_build to glibc_lib as the source of essential libraries starting at glibc 2.35. -CREW_ESSENTIAL_PACKAGES ||= %W[gcc_lib #{LIBC_VERSION.to_f > 2.34 ? "glibc_lib#{LIBC_VERSION.delete('.')}" : "glibc_build#{LIBC_VERSION.delete('.')}"} gmp ruby zlib zlib_ng zstd] +CREW_ESSENTIAL_PACKAGES ||= %W[gcc_lib #{LIBC_VERSION.to_f > 2.34 ? "glibc_lib#{LIBC_VERSION.delete('.')}" : "glibc_build#{LIBC_VERSION.delete('.')}"} glibc_standalone gmp ruby zlib zlib_ng zstd] CREW_IN_CONTAINER ||= File.exist?('/.dockerenv') || ENV.fetch('CREW_IN_CONTAINER', false) unless defined?(CREW_IN_CONTAINER) @@ -76,17 +76,21 @@ CREW_CONFIG_PATH ||= File.join(CREW_PREFIX, 'etc/crew') CREW_META_PATH ||= File.join(CREW_CONFIG_PATH, 'meta') CREW_BREW_DIR ||= File.join(CREW_PREFIX, 'tmp/crew') CREW_DEST_DIR ||= File.join(CREW_BREW_DIR, 'dest') -CREW_WINE_PREFIX ||= File.join(CREW_LIB_PREFIX, 'wine') CREW_DEST_PREFIX ||= File.join(CREW_DEST_DIR, CREW_PREFIX) CREW_DEST_LIB_PREFIX ||= File.join(CREW_DEST_DIR, CREW_LIB_PREFIX) -CREW_DEST_WINE_PREFIX ||= File.join(CREW_DEST_PREFIX, CREW_WINE_PREFIX) CREW_DEST_MAN_PREFIX ||= File.join(CREW_DEST_DIR, CREW_MAN_PREFIX) +CREW_WINE_PREFIX ||= File.join(CREW_LIB_PREFIX, 'wine') +CREW_DEST_WINE_PREFIX ||= File.join(CREW_DEST_PREFIX, CREW_WINE_PREFIX) # Local constants for contributors. CREW_LOCAL_REPO_ROOT ||= `git rev-parse --show-toplevel 2> /dev/null`.chomp CREW_LOCAL_BUILD_DIR ||= "#{CREW_LOCAL_REPO_ROOT}/release/#{ARCH}" CREW_GITLAB_PKG_REPO ||= 'https://gitlab.com/api/v4/projects/26210301/packages' +# Glibc related constants +CREW_GLIBC_PREFIX ||= File.join(CREW_PREFIX, 'opt/glibc-libs') +CREW_GLIBC_INTERPRETER ||= File.symlink?("#{CREW_PREFIX}/bin/ld.so") ? File.realpath("#{CREW_PREFIX}/bin/ld.so") : nil unless defined?(CREW_GLIBC_INTERPRETER) + # Put musl build dir under CREW_PREFIX/share/musl to avoid FHS incompatibility CREW_MUSL_PREFIX ||= File.join(CREW_PREFIX, '/share/musl/') CREW_DEST_MUSL_PREFIX ||= File.join(CREW_DEST_DIR, CREW_MUSL_PREFIX) @@ -141,7 +145,7 @@ USER ||= Etc.getlogin unless defined?(USER) unless defined?(CHROMEOS_RELEASE) CHROMEOS_RELEASE = if File.exist?('/etc/lsb-release') - File.read('/etc/lsb-release')[/CHROMEOS_RELEASE_CHROME_MILESTONE||=(.+)/, 1] + File.read('/etc/lsb-release')[/CHROMEOS_RELEASE_CHROME_MILESTONE=(.+)/, 1] else # newer version of Chrome OS exports info to env by default ENV.fetch('CHROMEOS_RELEASE_CHROME_MILESTONE', nil) @@ -202,15 +206,15 @@ when 'x86_64' end CREW_LINKER ||= ENV.fetch('CREW_LINKER', 'mold') unless defined?(CREW_LINKER) -CREW_GLIBC_OVERRIDE_LINKER_FLAGS ||= ARCH == 'x86_64' && LIBC_VERSION.to_f >= 2.35 ? " #{File.join(CREW_LIB_PREFIX, 'libC.so.6')} " : '' -CREW_LINKER_FLAGS ||= ENV.fetch('CREW_LINKER_FLAGS', CREW_GLIBC_OVERRIDE_LINKER_FLAGS) unless defined?(CREW_LINKER_FLAGS) +CREW_LINKER_FLAGS ||= ENV.fetch('CREW_LINKER_FLAGS', '-flto=auto') unless defined?(CREW_LINKER_FLAGS) CREW_CORE_FLAGS ||= "-O3 -pipe -ffat-lto-objects -fPIC #{CREW_ARCH_FLAGS} -fuse-ld=#{CREW_LINKER} #{CREW_LINKER_FLAGS}" -CREW_COMMON_FLAGS ||= "#{CREW_CORE_FLAGS} -flto=auto" -CREW_COMMON_FNO_LTO_FLAGS ||= "#{CREW_CORE_FLAGS} -fno-lto" -CREW_LDFLAGS ||= "-flto=auto #{CREW_LINKER_FLAGS}" +CREW_COMMON_FLAGS ||= "#{CREW_CORE_FLAGS} -B#{CREW_GLIBC_PREFIX} -flto=auto" +CREW_COMMON_FNO_LTO_FLAGS ||= "#{CREW_CORE_FLAGS} -B#{CREW_GLIBC_PREFIX} -fno-lto" CREW_FNO_LTO_LDFLAGS ||= '-fno-lto' +CREW_LINKER_FLAGS << " -Wl,--dynamic-linker,#{CREW_GLIBC_INTERPRETER} -B#{CREW_GLIBC_PREFIX} -L#{CREW_GLIBC_PREFIX}" if CREW_GLIBC_INTERPRETER + CREW_ENV_OPTIONS_HASH ||= if CREW_DISABLE_ENV_OPTIONS { 'CREW_DISABLE_ENV_OPTIONS' => '1' } @@ -220,8 +224,8 @@ CREW_ENV_OPTIONS_HASH ||= 'CXXFLAGS' => CREW_COMMON_FLAGS, 'FCFLAGS' => CREW_COMMON_FLAGS, 'FFLAGS' => CREW_COMMON_FLAGS, - 'LD_LIBRARY_PATH' => CREW_LIB_PREFIX, - 'LDFLAGS' => CREW_LDFLAGS + 'LIBRARY_PATH' => "#{CREW_GLIBC_PREFIX}:#{CREW_LIB_PREFIX}", + 'LDFLAGS' => CREW_LINKER_FLAGS } end @@ -258,8 +262,10 @@ CREW_MESON_OPTIONS ||= <<~OPT.chomp -Db_lto=true \ -Dstrip=true \ -Db_pie=true \ + -Dc_args='#{CREW_CORE_FLAGS}' \ + -Dc_link_args='#{CREW_LINKER_FLAGS}' \ -Dcpp_args='#{CREW_CORE_FLAGS}' \ - -Dc_args='#{CREW_CORE_FLAGS}' + -Dcpp_link_args='#{CREW_LINKER_FLAGS}' OPT # Use ninja or samurai @@ -273,10 +279,10 @@ CREW_CMAKE_OPTIONS ||= <<~OPT.chomp -DCMAKE_LIBRARY_PATH=#{CREW_LIB_PREFIX} \ -DCMAKE_C_FLAGS='#{CREW_COMMON_FLAGS.gsub(/-fuse-ld=.{2,4}\s/, '')}' \ -DCMAKE_CXX_FLAGS='#{CREW_COMMON_FLAGS.gsub(/-fuse-ld=.{2,4}\s/, '')}' \ - -DCMAKE_EXE_LINKER_FLAGS='#{CREW_LDFLAGS}' \ + -DCMAKE_EXE_LINKER_FLAGS='#{CREW_LINKER_FLAGS}' \ -DCMAKE_LINKER_TYPE=#{CREW_LINKER.upcase} \ - -DCMAKE_SHARED_LINKER_FLAGS='#{CREW_LDFLAGS}' \ - -DCMAKE_MODULE_LINKER_FLAGS='#{CREW_LDFLAGS}' \ + -DCMAKE_SHARED_LINKER_FLAGS='#{CREW_LINKER_FLAGS}' \ + -DCMAKE_MODULE_LINKER_FLAGS='#{CREW_LINKER_FLAGS}' \ -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=TRUE \ -DCMAKE_BUILD_TYPE=Release OPT diff --git a/lib/fixup.rb b/lib/fixup.rb index 1675ab793..ab59766b4 100644 --- a/lib/fixup.rb +++ b/lib/fixup.rb @@ -254,30 +254,18 @@ unless installed_pkgs_to_deprecate.empty? refresh_crew_json end -# Handle broken system glibc affecting gcc_lib on newer x86_64 ChromeOS milestones. -if (ARCH == 'x86_64') && (Gem::Version.new(LIBC_VERSION.to_s) >= Gem::Version.new('2.36')) - abort("patchelf is needed. Please run: 'crew update && crew install patchelf && crew update'") unless File.file?(File.join(CREW_PREFIX, 'bin/patchelf')) - # Link the system libc.so.6 to also require our renamed libC.so.6 - # which provides the float128 functions strtof128, strfromf128, - # and __strtof128_nan. - # This creates tons of the following warnings when g++ is invoked with - # g++ #{File.join(CREW_LIB_PREFIX, 'libC.so.6')}, but I'm not sure how - # to get around that. - # /usr/local/lib64/libC.so.6: linker input file unused because linking not done errors - libc_patch_libraries = %w[libstdc++.so.6] - libc_patch_libraries.delete_if { |lib| !File.file?(File.join(CREW_LIB_PREFIX, lib)) } - libc_patch_libraries.delete_if { |lib| Kernel.system "patchelf --print-needed #{File.join(CREW_LIB_PREFIX, lib)} | grep -q libC.so.6" } +if File.exist?("#{CREW_PREFIX}/bin/upx") && File.exist?("#{CREW_PREFIX}/bin/patchelf") + # Decompress all upx-compressed libraries + puts 'Decompressing binaries with upx...'.yellow + system "find #{CREW_PREFIX}/bin -type f -executable -print | xargs -P#{CREW_NPROC} -n1 upx -qq -d 2> /dev/null" + system "find #{CREW_LIB_PREFIX} -type f -executable -print | xargs -P#{CREW_NPROC} -n1 upx -qq -d 2> /dev/null" - return if libc_patch_libraries.empty? - - if File.file?(File.join(CREW_LIB_PREFIX, 'libC.so.6')) - Dir.chdir(CREW_LIB_PREFIX) do - libc_patch_libraries.each do |lib| - Kernel.system "patchelf --add-needed libC.so.6 #{lib}" and Kernel.system "patchelf --remove-needed libc.so.6 #{lib}" - puts "#{lib} patched for use with Chromebrew's glibc.".lightgreen - end - end - end + # Switch to glibc_standalone if installed + puts 'Switching to glibc_standalone for all installed executables...'.yellow + system "find #{CREW_PREFIX}/bin -type f -executable -print | xargs -P#{CREW_NPROC} -n1 patchelf --set-interpreter #{CREW_GLIBC_INTERPRETER} 2> /dev/null" + system "find #{CREW_PREFIX}/bin -type f -executable -print | xargs -P#{CREW_NPROC} -n1 patchelf --remove-rpath 2> /dev/null" +else + abort 'Please install upx and patchelf first by running \'crew install upx patchelf\'.'.lightred end # Reload @device with the appropriate symbolized or nonsymbolized json load before we exit fixup. diff --git a/manifest/armv7l/g/glibc_standalone.filelist b/manifest/armv7l/g/glibc_standalone.filelist index fbe1d2610..42be78123 100644 --- a/manifest/armv7l/g/glibc_standalone.filelist +++ b/manifest/armv7l/g/glibc_standalone.filelist @@ -19,7 +19,9 @@ /usr/local/bin/xtrace /usr/local/bin/zdump /usr/local/bin/zic +/usr/local/etc/env.d/10-glibc /usr/local/etc/ld.so.cache +/usr/local/etc/ld.so.conf /usr/local/etc/rpc /usr/local/include/a.out.h /usr/local/include/aio.h @@ -500,6 +502,7 @@ /usr/local/opt/glibc-libs/Mcrt1.o /usr/local/opt/glibc-libs/Scrt1.o /usr/local/opt/glibc-libs/audit/sotruss-lib.so +/usr/local/opt/glibc-libs/crew-audit.so /usr/local/opt/glibc-libs/crt1.o /usr/local/opt/glibc-libs/crti.o /usr/local/opt/glibc-libs/crtn.o diff --git a/manifest/armv7l/h/hello_world_chromebrew.filelist b/manifest/armv7l/h/hello_world_chromebrew.filelist new file mode 100644 index 000000000..f867932a9 --- /dev/null +++ b/manifest/armv7l/h/hello_world_chromebrew.filelist @@ -0,0 +1 @@ +/usr/local/bin/hello_chromebrew diff --git a/manifest/i686/g/glibc_standalone.filelist b/manifest/i686/g/glibc_standalone.filelist index 750a8729d..ce03f0883 100644 --- a/manifest/i686/g/glibc_standalone.filelist +++ b/manifest/i686/g/glibc_standalone.filelist @@ -19,7 +19,9 @@ /usr/local/bin/xtrace /usr/local/bin/zdump /usr/local/bin/zic +/usr/local/etc/env.d/10-glibc /usr/local/etc/ld.so.cache +/usr/local/etc/ld.so.conf /usr/local/etc/rpc /usr/local/include/a.out.h /usr/local/include/aio.h @@ -508,6 +510,7 @@ /usr/local/opt/glibc-libs/Mcrt1.o /usr/local/opt/glibc-libs/Scrt1.o /usr/local/opt/glibc-libs/audit/sotruss-lib.so +/usr/local/opt/glibc-libs/crew-audit.so /usr/local/opt/glibc-libs/crt1.o /usr/local/opt/glibc-libs/crti.o /usr/local/opt/glibc-libs/crtn.o diff --git a/manifest/i686/h/hello_world_chromebrew.filelist b/manifest/i686/h/hello_world_chromebrew.filelist new file mode 100644 index 000000000..f867932a9 --- /dev/null +++ b/manifest/i686/h/hello_world_chromebrew.filelist @@ -0,0 +1 @@ +/usr/local/bin/hello_chromebrew diff --git a/manifest/x86_64/g/glibc_standalone.filelist b/manifest/x86_64/g/glibc_standalone.filelist index 284773a59..a33841a63 100644 --- a/manifest/x86_64/g/glibc_standalone.filelist +++ b/manifest/x86_64/g/glibc_standalone.filelist @@ -19,7 +19,9 @@ /usr/local/bin/xtrace /usr/local/bin/zdump /usr/local/bin/zic +/usr/local/etc/env.d/10-glibc /usr/local/etc/ld.so.cache +/usr/local/etc/ld.so.conf /usr/local/etc/rpc /usr/local/include/a.out.h /usr/local/include/aio.h @@ -505,6 +507,7 @@ /usr/local/opt/glibc-libs/Mcrt1.o /usr/local/opt/glibc-libs/Scrt1.o /usr/local/opt/glibc-libs/audit/sotruss-lib.so +/usr/local/opt/glibc-libs/crew-audit.so /usr/local/opt/glibc-libs/crt1.o /usr/local/opt/glibc-libs/crti.o /usr/local/opt/glibc-libs/crtn.o diff --git a/manifest/x86_64/h/hello_world_chromebrew.filelist b/manifest/x86_64/h/hello_world_chromebrew.filelist new file mode 100644 index 000000000..f867932a9 --- /dev/null +++ b/manifest/x86_64/h/hello_world_chromebrew.filelist @@ -0,0 +1 @@ +/usr/local/bin/hello_chromebrew diff --git a/packages/bsdgames.rb b/packages/bsdgames.rb index 4efb18843..c73a8f01c 100644 --- a/packages/bsdgames.rb +++ b/packages/bsdgames.rb @@ -69,7 +69,7 @@ class Bsdgames < Autotools bsd_games_cfg_ncurses_includes='#{`pkg-config --cflags-only-I ncurses`.chomp}' bsd_games_cfg_ncurses_lib='#{`pkg-config --libs-only-l ncurses`.chomp}' bsd_games_cfg_non_interactive=y - bsd_games_cfg_other_ldflags='\"#{CREW_LDFLAGS}\"' + bsd_games_cfg_other_ldflags='\"#{CREW_LINKER_FLAGS}\"' bsd_games_cfg_pager='#{CREW_PREFIX}/bin/#{ENV.fetch('PAGER', nil)}' bsd_games_cfg_sbindir='#{CREW_PREFIX}/sbin' bsd_games_cfg_sharedir='#{CREW_PREFIX}/share/bsdgames' diff --git a/packages/busybox.rb b/packages/busybox.rb index bcae82859..9f0c7166e 100644 --- a/packages/busybox.rb +++ b/packages/busybox.rb @@ -74,7 +74,7 @@ class Busybox < Package CONFIG_CROSS_COMPILER_PREFIX="" CONFIG_SYSROOT="" CONFIG_EXTRA_CFLAGS="#{CREW_COMMON_FLAGS}" - CONFIG_EXTRA_LDFLAGS="#{CREW_LDFLAGS}" + CONFIG_EXTRA_LDFLAGS="#{CREW_LINKER_FLAGS}" CONFIG_EXTRA_LDLIBS="pthread" # CONFIG_USE_PORTABLE_CODE is not set # CONFIG_STACK_OPTIMIZATION_386 is not set diff --git a/packages/core.rb b/packages/core.rb index 3716adbc9..aa800b44a 100644 --- a/packages/core.rb +++ b/packages/core.rb @@ -3,7 +3,7 @@ require 'package' class Core < Package description 'Core Chromebrew Packages.' homepage 'https://github.com/chromebrew/chromebrew' - version '3.6' + version '3.7' license 'GPL-3+' compatibility 'all' @@ -31,6 +31,7 @@ class Core < Package depends_on 'git' depends_on 'git_mestrelion_tools' depends_on 'glibc_lib' + depends_on 'glibc_standalone' depends_on 'gmp' depends_on 'gnutls' depends_on 'groff' diff --git a/packages/docker.rb b/packages/docker.rb index 99c0e9417..94f6fb120 100644 --- a/packages/docker.rb +++ b/packages/docker.rb @@ -56,7 +56,7 @@ class Docker < Package CGO_CPPFLAGS='#{CREW_COMMON_FLAGS.gsub('=auto', '')}' \ CGO_CFLAGS='#{CREW_COMMON_FLAGS.gsub('=auto', '')}' \ CGO_CXXFLAGS='#{CREW_COMMON_FLAGS.gsub('=auto', '')}' \ - CGO_LDFLAGS='#{CREW_LDFLAGS.gsub('=auto', '')}' \ + CGO_LDFLAGS='#{CREW_LINKER_FLAGS.gsub('=auto', '')}' \ LDFLAGS='' \ GOFLAGS='-buildmode=pie -trimpath -mod=readonly -modcacherw -ldflags=-linkmode=external' \ GO111MODULE=off \ @@ -66,7 +66,7 @@ class Docker < Package CGO_CPPFLAGS='#{CREW_COMMON_FLAGS.gsub('=auto', '')}' \ CGO_CFLAGS='#{CREW_COMMON_FLAGS.gsub('=auto', '')}' \ CGO_CXXFLAGS='#{CREW_COMMON_FLAGS.gsub('=auto', '')}' \ - CGO_LDFLAGS='#{CREW_LDFLAGS.gsub('=auto', '')}' \ + CGO_LDFLAGS='#{CREW_LINKER_FLAGS.gsub('=auto', '')}' \ LDFLAGS='' \ GOFLAGS='-buildmode=pie -trimpath -mod=readonly -modcacherw -ldflags=-linkmode=external' \ GO111MODULE=off \ @@ -98,7 +98,7 @@ class Docker < Package CGO_CPPFLAGS='#{CREW_COMMON_FLAGS.gsub('=auto', '')}' \ CGO_CFLAGS='#{CREW_COMMON_FLAGS.gsub('=auto', '')}' \ CGO_CXXFLAGS='#{CREW_COMMON_FLAGS.gsub('=auto', '')}' \ - CGO_LDFLAGS='#{CREW_LDFLAGS.gsub('=auto', '')}' \ + CGO_LDFLAGS='#{CREW_LINKER_FLAGS.gsub('=auto', '')}' \ LDFLAGS='' \ GOFLAGS='-buildmode=pie -trimpath -mod=readonly -modcacherw -ldflags=-linkmode=external' \ GO111MODULE=off \ diff --git a/packages/glibc_standalone.rb b/packages/glibc_standalone.rb index c909708ef..f0a915b39 100644 --- a/packages/glibc_standalone.rb +++ b/packages/glibc_standalone.rb @@ -3,18 +3,18 @@ require 'package' class Glibc_standalone < Package description 'The GNU C Library project provides the core libraries for GNU/Linux systems.' homepage 'https://www.gnu.org/software/libc/' - version '2.41-1' + version '2.41-2' license 'LGPL-2.1+, BSD, HPND, ISC, inner-net, rc, and PCRE' compatibility 'all' - source_url "https://ftpmirror.gnu.org/glibc/glibc-#{version.split('-').first}.tar.xz" + source_url "https://ftpmirror.gnu.org/glibc/glibc-#{version.partition('-')[0]}.tar.xz" source_sha256 'a5a26b22f545d6b7d7b3dd828e11e428f24f4fac43c934fb071b6a7d0828e901' binary_compression 'tar.zst' binary_sha256({ - aarch64: 'e19d852da8d4ead346d62003f9e5f15076ed5fae5bcd12dc9bd8f7f2602bc1b2', - armv7l: 'e19d852da8d4ead346d62003f9e5f15076ed5fae5bcd12dc9bd8f7f2602bc1b2', - i686: '5b3a5e7256520a0435604b53f93a743d58ea07bea950fe3ee5f371c296f640f1', - x86_64: '44220b48699ab3fb677d16c0b5172fac151c47edfa48015f170633a5a1dd18ed' + aarch64: 'd9cd380aa98e25f76771ba117e2cc3a74bdbd45b83b0b3d4952d574ac68fd5bc', + armv7l: 'd9cd380aa98e25f76771ba117e2cc3a74bdbd45b83b0b3d4952d574ac68fd5bc', + i686: '3ff57cdd0ba6a768a4099f35e3087390bf07fda1e80c54a26789c0882de7e455', + x86_64: '0cfe260873f0a53ac7074705b82b2a80b3e03b0916b7ff7cd2b6683b4431efdc' }) depends_on 'gawk' => :build @@ -29,162 +29,44 @@ class Glibc_standalone < Package conflicts_ok no_env_options no_shrink + print_source_bashrc def self.patch - File.write 'hardcode-library-path.patch', <<~EOF - diff -Nur a/elf/dl-support.c b/elf/dl-support.c - --- a/elf/dl-support.c 2025-04-23 01:58:17.265974714 +0800 - +++ b/elf/dl-support.c 2025-04-23 14:38:27.373033131 +0800 - @@ -296,7 +296,7 @@ - - /* Initialize the data structures for the search paths for shared - objects. */ - - _dl_init_paths (getenv ("LD_LIBRARY_PATH"), "LD_LIBRARY_PATH", - + _dl_init_paths ("#{CREW_PREFIX}/opt/glibc-libs:#{CREW_LIB_PREFIX}:/#{ARCH_LIB}", "LD_LIBRARY_PATH", - \t\t /* No glibc-hwcaps selection support in statically - \t\t linked binaries. */ - \t\t NULL, NULL); - diff -Nur a/elf/rtld.c b/elf/rtld.c - --- a/elf/rtld.c 2025-04-23 04:04:02.230377659 +0800 - +++ b/elf/rtld.c 2025-04-23 14:37:52.298031258 +0800 - @@ -2647,7 +2647,7 @@ - \t /* The library search path. */ - \t if (memcmp (envline, "LIBRARY_PATH", 12) == 0) - \t { - -\t state->library_path = &envline[13]; - +\t state->library_path = "#{CREW_PREFIX}/opt/glibc-libs:#{CREW_LIB_PREFIX}:/#{ARCH_LIB}"; - \t state->library_path_source = "LD_LIBRARY_PATH"; - \t break; - \t } - EOF - + system "git clone --depth=1 https://github.com/chromebrew/crew-package-glibc -b #{version}" system 'filefix' - system 'patch', '-p1', '-i', 'hardcode-library-path.patch' - # See https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/refs/heads/release-R136-16238.B/sys-libs/glibc/files/local/glibc-2.39/0009-Revert-Add-GLIBC_ABI_DT_RELR-for-DT_RELR-support.patch?pli=1%2F - File.write '0009-Revert-Add-GLIBC_ABI_DT_RELR-for-DT_RELR-support.patch', <<~GLIBC_ABI_DT_RELR_PATCH_EOF - diff --git a/elf/dl-version.c b/elf/dl-version.c - index 8966d612cc79..7fb5cb16d47b 100644 - --- a/elf/dl-version.c - +++ b/elf/dl-version.c - @@ -359,30 +359,6 @@ _dl_check_map_versions (struct link_map *map, int verbose, int trace_mode) - \t} - } - - - /* When there is a DT_VERNEED entry with libc.so on DT_NEEDED, issue - - an error if there is a DT_RELR entry without GLIBC_ABI_DT_RELR - - dependency. */ - - if (dyn != NULL - - && map->l_info[DT_NEEDED] != NULL - - && map->l_info[DT_RELR] != NULL - - && __glibc_unlikely (!map->l_dt_relr_ref)) - - { - - const char *strtab = (const void *) D_PTR (map, l_info[DT_STRTAB]); - - const ElfW(Dyn) *d; - - for (d = map->l_ld; d->d_tag != DT_NULL; ++d) - -\tif (d->d_tag == DT_NEEDED) - -\t { - -\t const char *name = strtab + d->d_un.d_val; - -\t if (strncmp (name, "libc.so.", 8) == 0) - -\t { - -\t\t_dl_exception_create - -\t\t (&exception, DSO_FILENAME (map->l_name), - -\t\t N_("DT_RELR without GLIBC_ABI_DT_RELR dependency")); - -\t\tgoto call_error; - -\t } - -\t } - - } - - - return result; - } - - -- - 2.41.0 - GLIBC_ABI_DT_RELR_PATCH_EOF - system 'patch', '-p1', '-i', '0009-Revert-Add-GLIBC_ABI_DT_RELR-for-DT_RELR-support.patch' - - # See https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/refs/heads/release-R136-16238.B/sys-libs/glibc/files/local/glibc-2.39/0002-libc-Speed-up-large-memcpy-on-Cortex-A7-A15.patch - File.write '0002-libc-Speed-up-large-memcpy-on-Cortex-A7-A15.patch', <<~LIBC_SPEED_UP_PATCH_EOF - From e5b7f5d719e8fd03de363bc5bb5c28f1429e56bd Mon Sep 17 00:00:00 2001 - From: Yunlian Jiang - Date: Fri, 1 Aug 2014 15:19:34 -0700 - Subject: [PATCH 2/3] libc: Speed up large memcpy() on Cortex-A7/A15 - - Details please see crbug://331427 - - Experimentally it's been found that the "unaligned" memcpy() is - actually faster for sufficiently large memory copies. It appears that - the changeover point is a little different for different processors, - though. For A15 there's a lot more run-to-run variance for - medium-sized memcpy() but the changeover appears to be at ~16K. For - A7 (and maybe A9) the changeover seems to be a little further out. - We think the variance in A15 memcpy() is is due to different physical - addresses for the chunks of memory given to us by the kernel. It is - certain that the "aligned" code works faster at 4K and less and that - the "unaligned" code works faster with very large chunks of memory. - Since we care most about A15 performance and the A7 performance is not - that much worse (and actually better for SDRAM transfers), we'll pick - the number that's best for the A15. - Tests on snow (A15 only): - * Large (12M) aligned copies go from ~2350 MiB/s to ~2900 MiB/s. - * Medium (96K) aligned copies go from ~5900 MiB/s to ~6300 MiB/s. - * Medium (16K) aligned copies seem to be better but there's a lot of - noise (old=8151.8, 8736.6, 8168.7; new=9364.9, 9829.5, 9639.0) - * Small (4K, 8K) algined copies are unchanged. - For A7-only on pit: - * Large (12M) aligned copies go from 440 MiB/s to 930 MiB/s. - * Medium (96K) aligned copies regress from ~2650 MiB/s to ~2400 MiB/s. - * Medium (16K) aligned copies regress from ~3000 MiB/s to ~2800 MiB/s. - * Small (4K, 8K) aligned copies are unchanged. - See punybench changes at - for how this - was tested. For A15 changes I ran 3 times and averaged (there wasn't - lots of variance except for 16K). For A7 changes I ran 2 times. - [Adrian: forward-ported to glibc 2.32] - --- - sysdeps/arm/armv7/multiarch/memcpy_impl.S | 4 ++++ - 1 file changed, 4 insertions(+) - - diff --git a/sysdeps/arm/armv7/multiarch/memcpy_impl.S b/sysdeps/arm/armv7/multiarch/memcpy_impl.S - index dc701827..ac171cde 100644 - --- a/sysdeps/arm/armv7/multiarch/memcpy_impl.S - +++ b/sysdeps/arm/armv7/multiarch/memcpy_impl.S - @@ -327,6 +327,10 @@ ENTRY(memcpy) - \tcmp\ttmp1, tmp2 - \tbne\t.Lcpy_notaligned - - +\t/* Use the non-aligned code for >=16K; faster on A7/A15 (A9 too?) */ - +\tcmp\tcount, #0x4000 - +\tbge\t.Lcpy_notaligned - + - #ifdef USE_VFP - \t/* Magic dust alert! Force VFP on Cortex-A9. Experiments show - \t that the FP pipeline is much better at streaming loads and - -- - 2.49.0 - LIBC_SPEED_UP_PATCH_EOF - system 'patch', '-p1', '-i', '0002-libc-Speed-up-large-memcpy-on-Cortex-A7-A15.patch' + Dir.glob('crew-package-glibc/patches/*.patch') do |patch| + puts "Applying #{patch}...".yellow + system 'patch', '-p1', '-i', patch + end end def self.build - glibc_libdir = File.join(CREW_PREFIX, 'opt/glibc-libs') + cc_macro_list = %W[ + -DCREW_AUDIT=\\"#{CREW_GLIBC_PREFIX}/crew-audit.so\\" + -DCREW_PREFIX=\\"#{CREW_PREFIX}\\" + -DCREW_GLIBC_PREFIX=\\"#{CREW_GLIBC_PREFIX}\\" + -DCREW_GLIBC_VERSION=\\"#{version.partition('-')[0]}\\" + -DCREW_LD_LIBRARY_PATH=\\"#{CREW_GLIBC_PREFIX}:#{ENV.fetch('LD_LIBRARY_PATH', nil)}\\" + ] build_env = { - CFLAGS: '-O3 -pipe -fPIC -fno-lto -fuse-ld=lld', - CXXFLAGS: '-O3 -pipe -fPIC -fno-lto -fuse-ld=lld', + CFLAGS: "-O3 -pipe -fPIC -fno-lto -fuse-ld=lld #{cc_macro_list.join(' ')}", + CXXFLAGS: "-O3 -pipe -fPIC -fno-lto -fuse-ld=lld #{cc_macro_list.join(' ')}", + LDFLAGS: '-fno-lto -fuse-ld=lld', LD: 'ld.lld' # use lld here as mold will segfault } config_opts = %W[ --prefix=#{CREW_PREFIX} - --libdir=#{glibc_libdir} + --libdir=#{CREW_GLIBC_PREFIX} --libexecdir=#{CREW_PREFIX}/libexec - --mandir=#{CREW_PREFIX}/man + --mandir=#{CREW_MAN_PREFIX} --with-headers=#{CREW_PREFIX}/include --with-bugurl=https://github.com/chromebrew/chromebrew/issues/new --enable-bind-now --enable-fortify-source - --enable-kernel=#{ARCH.eql?('i686') ? '3.2' : '4.4'} + --enable-kernel=3.2 --disable-nscd --disable-profile --disable-sanity-checks @@ -198,8 +80,8 @@ class Glibc_standalone < Package FileUtils.mkdir_p 'builddir' Dir.chdir('builddir') do File.write 'configparms', <<~EOF - slibdir=#{glibc_libdir} - rtlddir=#{glibc_libdir} + slibdir=#{CREW_GLIBC_PREFIX} + rtlddir=#{CREW_GLIBC_PREFIX} sbindir=#{CREW_PREFIX}/bin rootsbindir=#{CREW_PREFIX}/bin EOF @@ -207,10 +89,36 @@ class Glibc_standalone < Package system build_env.transform_keys(&:to_s), '../configure', *config_opts system "make PARALLELMFLAGS='-j #{CREW_NPROC}'" end + + # compile crew-audit with system's glibc version, as we want it to work on system's glibc also + system "cc #{CREW_COMMON_FLAGS.sub(/-L[^\s]+/, '')} #{cc_macro_list.join(' ')} -shared crew-audit.c -o crew-audit.so", chdir: 'crew-package-glibc' end def self.install - system 'make', "DESTDIR=#{CREW_DEST_DIR}", 'install', chdir: 'builddir' - system "make -j1 DESTDIR=#{CREW_DEST_DIR} localedata/install-locales || make -j1 DESTDIR=#{CREW_DEST_DIR} localedata/install-locales", chdir: 'builddir' + FileUtils.mkdir_p %W[#{CREW_DEST_PREFIX}/etc/env.d #{CREW_DEST_PREFIX}/etc/ld.so.conf.d] + + system "make DESTDIR=#{CREW_DEST_DIR} install", chdir: 'builddir' + system "make DESTDIR=#{CREW_DEST_DIR} localedata/install-locales", chdir: 'builddir' + + File.write "#{CREW_DEST_PREFIX}/etc/ld.so.conf", <<~EOF + # ld.so.conf autogenerated by Chromebrew + # DO NOT put your changes here. Instead, put them in + # #{CREW_PREFIX}/etc/ld.so.conf.d/ instead. + + include #{CREW_PREFIX}/etc/ld.so.conf.d/*.conf + #{CREW_GLIBC_PREFIX} + #{CREW_LIB_PREFIX} + include /etc/ld.so.conf + EOF + + # install crew-audit + FileUtils.install 'crew-package-glibc/crew-audit.so', File.join(CREW_DEST_DIR, CREW_GLIBC_PREFIX, 'crew-audit.so'), mode: 0o755 + File.write "#{CREW_DEST_PREFIX}/etc/env.d/10-glibc", "LD_AUDIT=#{File.join(CREW_GLIBC_PREFIX, 'crew-audit.so')}\n" + end + + def self.postinstall + # update search cache for ld.so + puts 'Updating ld.so cache...'.lightblue + system "#{CREW_PREFIX}/bin/ldconfig" end end diff --git a/packages/hello_world_chromebrew.rb b/packages/hello_world_chromebrew.rb index 573bfde86..64849ec57 100755 --- a/packages/hello_world_chromebrew.rb +++ b/packages/hello_world_chromebrew.rb @@ -3,7 +3,7 @@ require 'package' class Hello_world_chromebrew < Package description 'Chromebrew Package Build Test (for use in PR Actions)' homepage 'https://github.com/chromebrew/chromebrew' - version '1.1' + version '1.2' license 'MIT' # Package license (eg. GPL-3, MIT, etc.) compatibility 'all' # Package architecture compatibility (eg. aarch64, armv7l, i686, x86_64 or all) source_url 'https://github.com/chromebrew/chromebrew/raw/master/tools/hello_world_chromebrew.c' @@ -13,19 +13,18 @@ class Hello_world_chromebrew < Package # These are needed to successfully build and check for dependencies. binary_sha256({ - aarch64: '827f9794864aa76f4c99fd31f989077f1fa65771386f73db30a7681842f8736d', - armv7l: '827f9794864aa76f4c99fd31f989077f1fa65771386f73db30a7681842f8736d', - i686: 'ff0942c505b04982fed187bcda123adead37b3ac2dcfd7e2f0543ca179e81df6', - x86_64: '3081f1f25950c91f75db41095b644a2783987a3a7ef2832fc2b85bf138bb006f' + aarch64: 'd2fb648b2f41ea10f851fc66602a15e595866a7e0b6cd999969e038a3af74bc1', + armv7l: 'd2fb648b2f41ea10f851fc66602a15e595866a7e0b6cd999969e038a3af74bc1', + i686: '9303a26a1a3c9ad93edf874da13148ccd823e9c5f4739ca8675d141065eac9ab', + x86_64: '486eac7f7f9cbc5010d667c7bdd3991c4da6ef79040afc68775cbe7f0ee6a167' }) # Register dependencies (use the following line as a basis) - # + # Runtime dependencies: # depends_on '*' # R # Build dependencies: # depends_on '*' => :build - # # Function to perform patch operations prior to build from source. def self.patch @@ -37,7 +36,7 @@ class Hello_world_chromebrew < Package # Function to perform build from source. def self.build - system 'gcc -o hello hello_world_chromebrew.c' + system "gcc #{CREW_COMMON_FLAGS} #{CREW_LINKER_FLAGS} -o hello hello_world_chromebrew.c" end # Function to perform check from source build. diff --git a/packages/perl.rb b/packages/perl.rb index 0a8088559..d2716ddc4 100644 --- a/packages/perl.rb +++ b/packages/perl.rb @@ -40,7 +40,7 @@ class Perl < Package -Dvendorarch=#{CREW_LIB_PREFIX}/perl5/#{version}/vendor_perl \ -Dcc=#{CREW_TARGET}-gcc \ -Doptimize='#{CREW_COMMON_FLAGS}' \ - -Dlldlflags='-shared #{CREW_LDFLAGS}' -Dldflags='#{CREW_LDFLAGS}' \ + -Dlldlflags='-shared #{CREW_LINKER_FLAGS}' -Dldflags='#{CREW_LINKER_FLAGS}' \ -Dusethreads \ -Dinstallusrbinperl=n \ -Duseshrplib -Dman1dir=#{CREW_MAN_PREFIX}/man1 -Dman3dir=#{CREW_MAN_PREFIX}/man3" diff --git a/packages/pipewire.rb b/packages/pipewire.rb index ceef9d66d..dda92d2c6 100644 --- a/packages/pipewire.rb +++ b/packages/pipewire.rb @@ -67,7 +67,7 @@ class Pipewire < Meson system "#{CREW_PREFIX}/bin/update-ca-certificates --fresh --certsconf #{CREW_PREFIX}/etc/ca-certificates.conf" end - pre_meson_options "LDFLAGS='#{CREW_LDFLAGS} -pthread'" + pre_meson_options "LDFLAGS='#{CREW_LINKER_FLAGS} -pthread'" meson_options "-Dbluez5-backend-hsphfpd=disabled \ -Dbluez5-backend-ofono=disabled \ -Dbluez5=disabled \ diff --git a/packages/samurai.rb b/packages/samurai.rb index 15ad45b3b..19c5b25c3 100644 --- a/packages/samurai.rb +++ b/packages/samurai.rb @@ -24,7 +24,7 @@ class Samurai < Package end def self.build - system "make CFLAGS='#{CREW_COMMON_FLAGS}' LDFLAGS='#{CREW_LDFLAGS}'" + system "make CFLAGS='#{CREW_COMMON_FLAGS}' LDFLAGS='#{CREW_LINKER_FLAGS}'" end def self.install