Skip to content

Commit

Permalink
Import patchelf fixes
Browse files Browse the repository at this point in the history
This prevents a symbol with multiple unhidden verisons, and fixes .Net
runtime library loading issue.

Fixes #5
  • Loading branch information
shankerwangmiao committed Jan 14, 2024
1 parent 87e712c commit ac32bbf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
21 changes: 11 additions & 10 deletions autobuild/patches/patchelf/0001-add-remap-symvers.patch
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
From 93eab40fdbaca0de3df82908ea2bf2ffb1f594f7 Mon Sep 17 00:00:00 2001
From c40257c9b5a241c80a30fb423b6b80a95a355c3e Mon Sep 17 00:00:00 2001
From: Miao Wang <[email protected]>
Date: Fri, 12 Jan 2024 16:56:07 +0800
Subject: [PATCH] add remap-symvers

---
src/elf.h | 2 +
src/patchelf.cc | 338 +++++++++++++++++++++++++++++++++++++++++++++++-
src/patchelf.cc | 339 +++++++++++++++++++++++++++++++++++++++++++++++-
src/patchelf.h | 6 +-
3 files changed, 341 insertions(+), 5 deletions(-)
3 files changed, 342 insertions(+), 5 deletions(-)

diff --git a/src/elf.h b/src/elf.h
index 920e689..669fd2d 100644
Expand All @@ -23,7 +23,7 @@ index 920e689..669fd2d 100644
/* The ELF file header. This appears at the start of every ELF file. */

diff --git a/src/patchelf.cc b/src/patchelf.cc
index 82b4b46..9cf23e4 100644
index 82b4b46..0b5f5d6 100644
--- a/src/patchelf.cc
+++ b/src/patchelf.cc
@@ -1234,8 +1234,14 @@ void ElfFile<ElfFileParamNames>::rewriteHeaders(Elf_Addr phdrAddress)
Expand Down Expand Up @@ -97,7 +97,7 @@ index 82b4b46..9cf23e4 100644
std::fill(ht.m_buckets.begin(), ht.m_buckets.end(), 0);
std::fill(ht.m_chain.begin(), ht.m_chain.end(), 0);

@@ -2320,6 +2343,268 @@ void ElfFile<ElfFileParamNames>::modifyExecstack(ExecstackMode op)
@@ -2320,6 +2343,269 @@ void ElfFile<ElfFileParamNames>::modifyExecstack(ExecstackMode op)
printf("execstack: %c\n", result);
}

Expand Down Expand Up @@ -337,7 +337,8 @@ index 82b4b46..9cf23e4 100644
+ auto sym = it->second;
+ debug("Adding %s@%s to dynsym list\n", it->first.c_str(), mapTo.c_str());
+ newDynsymSpan[i] = dynsyms[sym];
+ wri(newVersymSpan[i], map_to_ndx);
+ bool is_hidden = rdi(newVersymSpan[sym]) & VERSYM_HIDDEN;
+ wri(newVersymSpan[i], map_to_ndx | (is_hidden ? VERSYM_HIDDEN : 0));
+ wri(newVersymSpan[sym], rdi(newVersymSpan[sym]) | VERSYM_HIDDEN);
+ i += 1;
+ }
Expand Down Expand Up @@ -366,7 +367,7 @@ index 82b4b46..9cf23e4 100644
template<ElfFileParams>
template<class StrIdxCallback>
void ElfFile<ElfFileParamNames>::forAllStringReferences(const Elf_Shdr& strTabHdr, StrIdxCallback&& fn)
@@ -2384,6 +2669,10 @@ static bool noDefaultLib = false;
@@ -2384,6 +2670,10 @@ static bool noDefaultLib = false;
static bool printExecstack = false;
static bool clearExecstack = false;
static bool setExecstack = false;
Expand All @@ -377,7 +378,7 @@ index 82b4b46..9cf23e4 100644

template<class ElfFile>
static void patchElf2(ElfFile && elfFile, const FileContents & fileContents, const std::string & fileName)
@@ -2441,6 +2730,9 @@ static void patchElf2(ElfFile && elfFile, const FileContents & fileContents, con
@@ -2441,6 +2731,9 @@ static void patchElf2(ElfFile && elfFile, const FileContents & fileContents, con
if (renameDynamicSymbols)
elfFile.renameDynamicSymbols(symbolsToRename);

Expand All @@ -387,7 +388,7 @@ index 82b4b46..9cf23e4 100644
if (elfFile.isChanged()){
writeFile(fileName, elfFile.fileContents);
} else if (alwaysWrite) {
@@ -2505,6 +2797,8 @@ static void showHelp(const std::string & progName)
@@ -2505,6 +2798,8 @@ static void showHelp(const std::string & progName)
[--clear-execstack]\n\
[--set-execstack]\n\
[--rename-dynamic-symbols NAME_MAP_FILE]\tRenames dynamic symbols. The map file should contain two symbols (old_name new_name) per line\n\
Expand All @@ -396,7 +397,7 @@ index 82b4b46..9cf23e4 100644
[--output FILE]\n\
[--debug]\n\
[--version]\n\
@@ -2661,6 +2955,44 @@ static int mainWrapped(int argc, char * * argv)
@@ -2661,6 +2956,44 @@ static int mainWrapped(int argc, char * * argv)
symbolsToRename[*symbolsToRenameKeys.insert(from).first] = to;
}
}
Expand Down
2 changes: 1 addition & 1 deletion spec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# AUTOGENERATED FILE from spec.main using genspec
VER=0.1.1
REL=0~pre1
REL=0~pre2
_mirror="http://pkg.loongnix.cn/loongnix"

### For pkgs from outside loongnix repo
Expand Down
2 changes: 1 addition & 1 deletion spec.main
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VER=0.1.1
REL=0~pre1
REL=0~pre2
_mirror="http://pkg.loongnix.cn/loongnix"

### For pkgs from outside loongnix repo
Expand Down

0 comments on commit ac32bbf

Please sign in to comment.