Files
chromebrew/packages/glibc.rb
SupeChicken666 3ee0c82139 glibc-standalone: Rename to glibc, add a LD_PRELOAD library with useful features (#11911)
* crew: Add a LD_PRELOAD library for hijacking linker/library path

Signed-off-by: SupeChicken666 <me@supechicken666.dev>

* Add `glibc_{build,dev.lib}` to deprecated package list

Signed-off-by: SupeChicken666 <me@supechicken666.dev>

* Bump version

Signed-off-by: SupeChicken666 <me@supechicken666.dev>

* Minor changes

Signed-off-by: SupeChicken666 <me@supechicken666.dev>

* Move static libraries to CREW_LIB_PREFIX

Signed-off-by: SupeChicken666 <me@supechicken666.dev>

* Remove glibc_build from const.rb

Signed-off-by: SupeChicken666 <me@supechicken666.dev>

* Make rubocop happy

Signed-off-by: SupeChicken666 <me@supechicken666.dev>

* Fix arm build and add binaries.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* cleanup

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Adjust x86_64 unit tests to use the Nocturne M90 container image and armv7l unit tests to use the fievel M91 container image since we are using the same glibc for everything now.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Adjust build containers to use the oldest glibc based containers.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Add i686 builds.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Add x86_64 build.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Set LD_PRELOAD before running any command

Signed-off-by: SupeChicken666 <me@supechicken666.dev>

* Use File.join

Signed-off-by: SupeChicken666 <me@supechicken666.dev>

* Use File.join

Signed-off-by: SupeChicken666 <me@supechicken666.dev>

* adjust unit tests.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Fix arm CREW_GLIBC_INTERPRETER

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Update Rhythmbox

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Update Rhythmbox

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* lint

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Do not install crew_sudo in container.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Bump version

Signed-off-by: SupeChicken666 <me@supechicken666.dev>

---------

Signed-off-by: SupeChicken666 <me@supechicken666.dev>
Signed-off-by: Satadru Pramanik <satadru@gmail.com>
Co-authored-by: Satadru Pramanik <satadru@gmail.com>
2025-05-20 10:21:15 +00:00

133 lines
4.5 KiB
Ruby

require 'package'
class Glibc < 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-4'
license 'LGPL-2.1+, BSD, HPND, ISC, inner-net, rc, and PCRE'
compatibility 'all'
source_url "https://ftpmirror.gnu.org/glibc/glibc-#{version.partition('-')[0]}.tar.xz"
source_sha256 'a5a26b22f545d6b7d7b3dd828e11e428f24f4fac43c934fb071b6a7d0828e901'
binary_compression 'tar.zst'
binary_sha256({
aarch64: '609104350dd5e50382472f4409d57ceab099d65839adf891b77621adf447f1f1',
armv7l: '609104350dd5e50382472f4409d57ceab099d65839adf891b77621adf447f1f1',
i686: '4b7a2d8025430f183b85d982924a9764b31c485e4c8938753858465853ba25d3',
x86_64: '5d5da0128e3054020c507d883d5f27c0b8a978263b799f068c845393b5fffe17'
})
depends_on 'gawk' => :build
depends_on 'libidn2' => :build
depends_on 'texinfo' => :build
depends_on 'libxcrypt' # Latest glibc removed libcrypt.so, add this for backward compatibility
conflicts_ok
no_env_options
no_shrink
print_source_bashrc
def self.patch
system "git clone --depth=1 https://github.com/chromebrew/crew-package-glibc -b #{version}"
system 'filefix'
Dir.glob('crew-package-glibc/patches/*.patch') do |patch|
puts "Applying #{patch}...".yellow
system 'patch', '-p1', '-i', patch
end
end
def self.build
cc_macro_list = %W[
-DCREW_PREFIX=\\"#{CREW_PREFIX}\\"
-DCREW_GLIBC_PREFIX=\\"#{CREW_GLIBC_PREFIX}\\"
-DCREW_GLIBC_INTERPRETER=\\"#{CREW_GLIBC_INTERPRETER}\\"
-DSYSTEM_GLIBC_INTERPRETER=\\"/#{ARCH_LIB}/#{File.basename(CREW_GLIBC_INTERPRETER)}\\"
]
build_env = {
CFLAGS: "-O3 -pipe -fPIC -fno-lto #{cc_macro_list.join(' ')}",
CXXFLAGS: "-O3 -pipe -fPIC -fno-lto #{cc_macro_list.join(' ')}",
LDFLAGS: '-fno-lto'
}
config_opts = %W[
--prefix=#{CREW_PREFIX}
--libdir=#{CREW_LIB_PREFIX}
--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=3.2
--enable-shared
--disable-nscd
--disable-multilib
--disable-profile
--disable-sanity-checks
--disable-werror
--without-cvs
--without-selinux
]
config_opts << '--enable-cet' unless ARCH == 'i686'
FileUtils.mkdir_p %w[builddir]
Dir.chdir('builddir') do
File.write 'configparms', <<~EOF
slibdir=#{CREW_GLIBC_PREFIX}
rtlddir=#{CREW_GLIBC_PREFIX}
sbindir=#{CREW_PREFIX}/bin
rootsbindir=#{CREW_PREFIX}/bin
EOF
system build_env.transform_keys(&:to_s), '../configure', *config_opts, no_preload_hacks: true
system "make PARALLELMFLAGS='-j #{CREW_NPROC}'", no_preload_hacks: true
end
arch_flag = case ARCH
when 'x86_64'
'-m64'
when 'i686'
'-m32'
else
'-mfloat-abi=hard -mfpu=vfpv3-d16 -march=armv7-a+fp'
end
# Link with ChromeOS's glibc libraries to ensure compatibility
system <<~CMD, chdir: 'crew-package-glibc/crew-preload', no_preload_hacks: true
cc -B #{CREW_GLIBC_PREFIX} #{CREW_COMMON_FLAGS} #{arch_flag} -fuse-ld=mold \
#{cc_macro_list.join(' ')} ../prebuilt/#{ARCH.sub('aarch64', 'armv7l')}/lib{c,dl}-*.so \
-shared -fvisibility=hidden -Wl,-soname,crew-preload.so \
main.c hooks.c -o ../crew-preload.so
CMD
end
def self.install
FileUtils.mkdir_p %W[#{CREW_DEST_PREFIX}/etc/env.d #{CREW_DEST_PREFIX}/etc/ld.so.conf.d #{CREW_DEST_LIB_PREFIX}]
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-preload.so', File.join(CREW_DEST_LIB_PREFIX, 'crew-preload.so'), mode: 0o755
end
def self.postinstall
# update search cache for ld.so
system "#{CREW_PREFIX}/bin/ldconfig", %i[out err] => File::NULL
end
end