1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-21 09:57:18 +03:00

[Mach-O] Fix ASAN issue

This commit is contained in:
Rui Ueyama 2021-10-25 20:14:32 +09:00
parent a86ad2771a
commit 5817265e91
2 changed files with 20 additions and 8 deletions

View File

@ -820,14 +820,7 @@ void UnwindEncoder::finish(Context &ctx) {
// Allocate a buffer that is more than large enough to hold the
// entire section.
i64 size = sizeof(UnwindSectionHeader) +
personalities.size() * 4 +
num_lsda * sizeof(UnwindLsdaEntry) +
pages.size() * (sizeof(UnwindFirstLevelPage) + 1) +
pages.size() * sizeof(UnwindSecondLevelPage) +
records.size() * 8;
buf.resize(size);
buf.resize(4096 * 1024);
// Write the section header.
UnwindSectionHeader &hdr = *(UnwindSectionHeader *)buf.data();

19
test/macho/headerpad.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
set -e
cd $(dirname $0)
mold=`pwd`/../../ld64.mold
echo -n "Testing $(basename -s .sh $0) ... "
t=$(pwd)/../../out/test/macho/$(basename -s .sh $0)
mkdir -p $t
cat <<EOF | cc -o $t/a.o -c -xc -
int main() {}
EOF
clang -fuse-ld=$mold -o $t/exe $t/a.o -Wl,-headerpad,0
otool -l $t/exe | grep -A5 'sectname __text' | grep -q 'addr 0x0000000100000580'
clang -fuse-ld=$mold -o $t/exe $t/a.o -Wl,-headerpad,0x10000
otool -l $t/exe | grep -A5 'sectname __text' | grep -q 'addr 0x0000000100010580'
echo OK