From 9baa8f7c2d74d0df2fa55206a87f628360243159 Mon Sep 17 00:00:00 2001 From: Martin Stransky Date: Thu, 29 Jun 2023 11:23:13 +0200 Subject: [PATCH] Enabled elf-hack for PGO builds --- D182447.diff | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++ firefox.spec | 10 +++-- pgo.patch | 42 ------------------- 3 files changed, 118 insertions(+), 45 deletions(-) create mode 100644 D182447.diff diff --git a/D182447.diff b/D182447.diff new file mode 100644 index 0000000..8163545 --- /dev/null +++ b/D182447.diff @@ -0,0 +1,111 @@ +diff --git a/build/unix/elfhack/elf.cpp b/build/unix/elfhack/elf.cpp +--- a/build/unix/elfhack/elf.cpp ++++ b/build/unix/elfhack/elf.cpp +@@ -347,11 +347,11 @@ + } + } + return sections[index]; + } + +-ElfSection* Elf::getSectionAt(unsigned int offset) { ++ElfSection* Elf::getSectionAt(Elf64_Off offset) { + for (int i = 1; i < ehdr->e_shnum; i++) { + ElfSection* section = getSection(i); + if ((section != nullptr) && (section->getFlags() & SHF_ALLOC) && + !(section->getFlags() & SHF_TLS) && (offset >= section->getAddr()) && + (offset < section->getAddr() + section->getSize())) +@@ -532,11 +532,11 @@ + info.section = shdr.sh_info ? parent->getSection(shdr.sh_info) : nullptr; + else + info.index = shdr.sh_info; + } + +-unsigned int ElfSection::getAddr() { ++Elf64_Addr ElfSection::getAddr() { + if (shdr.sh_addr != (Elf64_Addr)-1) return shdr.sh_addr; + + // It should be safe to adjust sh_addr for all allocated sections that + // are neither SHT_NOBITS nor SHT_PROGBITS + if ((previous != nullptr) && isRelocatable()) { +@@ -548,16 +548,16 @@ + return (shdr.sh_addr = addr); + } + return shdr.sh_addr; + } + +-unsigned int ElfSection::getOffset() { ++Elf64_Off ElfSection::getOffset() { + if (shdr.sh_offset != (Elf64_Off)-1) return shdr.sh_offset; + + if (previous == nullptr) return (shdr.sh_offset = 0); + +- unsigned int offset = previous->getOffset(); ++ Elf64_Off offset = previous->getOffset(); + + ElfSegment* ptload = getSegmentByType(PT_LOAD); + ElfSegment* prev_ptload = previous->getSegmentByType(PT_LOAD); + + if (ptload && (ptload == prev_ptload)) { +diff --git a/build/unix/elfhack/elfhack.cpp b/build/unix/elfhack/elfhack.cpp +--- a/build/unix/elfhack/elfhack.cpp ++++ b/build/unix/elfhack/elfhack.cpp +@@ -1258,12 +1258,12 @@ + second->getAddr() < first_executable->getAddr()) { + // The distance between both sections needs to be preserved because + // eh_frame_hdr contains relative offsets to eh_frame. Well, they could be + // relocated too, but it's not worth the effort for the few number of bytes + // this would save. +- unsigned int distance = second->getAddr() - first->getAddr(); +- unsigned int origAddr = eh_frame->getAddr(); ++ Elf64_Off distance = second->getAddr() - first->getAddr(); ++ Elf64_Addr origAddr = eh_frame->getAddr(); + ElfSection* previous = first->getPrevious(); + first->getShdr().sh_addr = (previous->getAddr() + previous->getSize() + + first->getAddrAlign() - 1) & + ~(first->getAddrAlign() - 1); + second->getShdr().sh_addr = +diff --git a/build/unix/elfhack/elfxx.h b/build/unix/elfhack/elfxx.h +--- a/build/unix/elfhack/elfxx.h ++++ b/build/unix/elfhack/elfxx.h +@@ -283,11 +283,11 @@ + ~Elf(); + + /* index == -1 is treated as index == ehdr.e_shstrndx */ + ElfSection* getSection(int index); + +- ElfSection* getSectionAt(unsigned int offset); ++ ElfSection* getSectionAt(Elf64_Off offset); + + ElfSegment* getSegmentByType(unsigned int type, ElfSegment* last = nullptr); + + ElfDynamic_Section* getDynSection(); + +@@ -332,12 +332,12 @@ + virtual ~ElfSection() { free(data); } + + const char* getName() { return name; } + unsigned int getType() { return shdr.sh_type; } + unsigned int getFlags() { return shdr.sh_flags; } +- unsigned int getAddr(); +- unsigned int getSize() { return shdr.sh_size; } ++ Elf64_Addr getAddr(); ++ Elf64_Off getSize() { return shdr.sh_size; } + unsigned int getAddrAlign() { return shdr.sh_addralign; } + unsigned int getEntSize() { return shdr.sh_entsize; } + const char* getData() { return data; } + ElfSection* getLink() { return link; } + SectionInfo getInfo() { return info; } +@@ -356,11 +356,11 @@ + shdr.sh_size = newsize; + markDirty(); + } + } + +- unsigned int getOffset(); ++ Elf64_Off getOffset(); + int getIndex(); + Elf_Shdr& getShdr(); + + ElfSection* getNext() { return next; } + ElfSection* getPrevious() { return previous; } + diff --git a/firefox.spec b/firefox.spec index 9064967..20fcac7 100644 --- a/firefox.spec +++ b/firefox.spec @@ -159,7 +159,7 @@ ExcludeArch: ppc64le Summary: Mozilla Firefox Web browser Name: firefox Version: 114.0.2 -Release: 2%{?pre_tag}%{?dist} +Release: 3%{?pre_tag}%{?dist} URL: https://www.mozilla.org/firefox/ License: MPLv1.1 or GPLv2+ or LGPLv2+ Source0: https://archive.mozilla.org/pub/firefox/releases/%{version}%{?pre_version}/source/firefox-%{version}%{?pre_version}.source.tar.xz @@ -233,6 +233,7 @@ Patch230: firefox-enable-vaapi.patch # Upstream patches Patch402: mozilla-1196777.patch Patch407: mozilla-1667096.patch +Patch408: D182447.diff # PGO/LTO patches Patch600: pgo.patch @@ -505,12 +506,13 @@ This package contains results of tests executed during build. %patch402 -p1 -b .1196777 %patch407 -p1 -b .1667096 +%patch408 -p1 -b .D182447 # PGO patches %if %{build_with_pgo} %if !%{build_with_clang} %patch600 -p1 -b .pgo -%patch602 -p1 -b .1516803 +#%patch602 -p1 -b .1516803 %endif %endif %patch603 -p1 -b .inline @@ -719,7 +721,6 @@ export GCOV_PREFIX_STRIP=$(( $(echo `pwd -P`|tr -c -d '/' |wc -c )+2 )) env | grep GCOV echo "ac_add_options --enable-lto" >> .mozconfig echo "ac_add_options MOZ_PGO=1" >> .mozconfig -echo "ac_add_options --disable-elf-hack" >> .mozconfig %endif # Require 2 GB of RAM per CPU core @@ -1055,6 +1056,9 @@ fi #--------------------------------------------------------------------- %changelog +* Thu Jun 29 2023 Martin Stransky - 114.0.2-3 +- Enable Elf-hack for PGO builds. + * Thu Jun 22 2023 Martin Stransky - 114.0.2-2 - Enable PGO/LTO again. diff --git a/pgo.patch b/pgo.patch index cae0648..3ac23da 100644 --- a/pgo.patch +++ b/pgo.patch @@ -1,26 +1,3 @@ -diff -up firefox-112.0/build/moz.configure/lto-pgo.configure.pgo firefox-112.0/build/moz.configure/lto-pgo.configure ---- firefox-112.0/build/moz.configure/lto-pgo.configure.pgo 2023-04-06 17:27:38.000000000 +0200 -+++ firefox-112.0/build/moz.configure/lto-pgo.configure 2023-04-06 21:27:32.537089073 +0200 -@@ -247,8 +247,8 @@ def lto( - cflags.append("-flto") - ldflags.append("-flto") - else: -- cflags.append("-flto=thin") -- ldflags.append("-flto=thin") -+ cflags.append("-flto") -+ ldflags.append("-flto") - - if target.os == "Android" and value == "cross": - # Work around https://github.com/rust-lang/rust/issues/90088 -@@ -264,7 +264,7 @@ def lto( - if value == "full": - cflags.append("-flto") - else: -- cflags.append("-flto=thin") -+ cflags.append("-flto") - # With clang-cl, -flto can only be used with -c or -fuse-ld=lld. - # AC_TRY_LINKs during configure don't have -c, so pass -fuse-ld=lld. - cflags.append("-fuse-ld=lld") diff -up firefox-112.0/build/pgo/profileserver.py.pgo firefox-112.0/build/pgo/profileserver.py --- firefox-112.0/build/pgo/profileserver.py.pgo 2023-04-06 17:27:40.000000000 +0200 +++ firefox-112.0/build/pgo/profileserver.py 2023-04-06 21:29:33.772294479 +0200 @@ -59,25 +36,6 @@ diff -up firefox-112.0/build/pgo/profileserver.py.pgo firefox-112.0/build/pgo/pr with TemporaryDirectory() as profilePath: # TODO: refactor this into mozprofile -diff -up firefox-112.0/build/unix/mozconfig.unix.pgo firefox-112.0/build/unix/mozconfig.unix ---- firefox-112.0/build/unix/mozconfig.unix.pgo 2023-04-06 21:27:32.537089073 +0200 -+++ firefox-112.0/build/unix/mozconfig.unix 2023-04-06 21:28:54.987949124 +0200 -@@ -4,6 +4,15 @@ if [ -n "$FORCE_GCC" ]; then - CC="$MOZ_FETCHES_DIR/gcc/bin/gcc" - CXX="$MOZ_FETCHES_DIR/gcc/bin/g++" - -+ if [ -n "$MOZ_PGO" ]; then -+ if [ -z "$USE_ARTIFACT" ]; then -+ ac_add_options --enable-lto -+ fi -+ export AR="$topsrcdir/gcc/bin/gcc-ar" -+ export NM="$topsrcdir/gcc/bin/gcc-nm" -+ export RANLIB="$topsrcdir/gcc/bin/gcc-ranlib" -+ fi -+ - # We want to make sure we use binutils and other binaries in the tooltool - # package. - mk_add_options "export PATH=$MOZ_FETCHES_DIR/gcc/bin:$MOZ_FETCHES_DIR/binutils/bin:$PATH" diff -up firefox-112.0/toolkit/components/terminator/nsTerminator.cpp.pgo firefox-112.0/toolkit/components/terminator/nsTerminator.cpp --- firefox-112.0/toolkit/components/terminator/nsTerminator.cpp.pgo 2023-04-06 17:27:57.000000000 +0200 +++ firefox-112.0/toolkit/components/terminator/nsTerminator.cpp 2023-04-06 21:27:32.538089108 +0200