| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
set -x |
| 4 |
|
| 5 |
make_flags="-j$(nproc) MAKEINFO=true" |
| 6 |
|
| 7 |
root_dir="$1" |
| 8 |
|
| 9 |
cd $root_dir/binutils-source |
| 10 |
|
| 11 |
patch -p1 <<'EOF' |
| 12 |
From 4476cc67e657d6b26cd453c555a611f1ab956660 Mon Sep 17 00:00:00 2001 |
| 13 |
From: "H.J. Lu" <[email protected]> |
| 14 |
Date: Thu, 30 Aug 2018 09:21:57 -0700 |
| 15 |
Subject: [PATCH] ld: Lookup section in output with the same name |
| 16 |
|
| 17 |
When there are more than one input sections with the same section name, |
| 18 |
SECNAME, linker picks the first one to define __start_SECNAME and |
| 19 |
__stop_SECNAME symbols. When the first input section is removed by |
| 20 |
comdat group, we need to check if there is still an output section |
| 21 |
with section name SECNAME. |
| 22 |
|
| 23 |
PR ld/23591 |
| 24 |
* ldlang.c (undef_start_stop): Lookup section in output with |
| 25 |
the same name. |
| 26 |
--- |
| 27 |
ld/ldlang.c | 18 ++++++++++++++++++ |
| 28 |
1 file changed, 18 insertions(+) |
| 29 |
|
| 30 |
diff --git a/ld/ldlang.c b/ld/ldlang.c |
| 31 |
index 8878ccd..d644b56 100644 |
| 32 |
--- a/ld/ldlang.c |
| 33 |
+++ b/ld/ldlang.c |
| 34 |
@@ -6097,6 +6097,24 @@ undef_start_stop (struct bfd_link_hash_entry *h) |
| 35 |
|| strcmp (h->u.def.section->name, |
| 36 |
h->u.def.section->output_section->name) != 0) |
| 37 |
{ |
| 38 |
+ asection *sec = bfd_get_section_by_name (link_info.output_bfd, |
| 39 |
+ h->u.def.section->name); |
| 40 |
+ if (sec != NULL) |
| 41 |
+ { |
| 42 |
+ /* When there are more than one input sections with the same |
| 43 |
+ section name, SECNAME, linker picks the first one to define |
| 44 |
+ __start_SECNAME and __stop_SECNAME symbols. When the first |
| 45 |
+ input section is removed by comdat group, we need to check |
| 46 |
+ if there is still an output section with section name |
| 47 |
+ SECNAME. */ |
| 48 |
+ asection *i; |
| 49 |
+ for (i = sec->map_head.s; i != NULL; i = i->map_head.s) |
| 50 |
+ if (strcmp (h->u.def.section->name, i->name) == 0) |
| 51 |
+ { |
| 52 |
+ h->u.def.section = i; |
| 53 |
+ return; |
| 54 |
+ } |
| 55 |
+ } |
| 56 |
h->type = bfd_link_hash_undefined; |
| 57 |
h->u.undef.abfd = NULL; |
| 58 |
} |
| 59 |
-- |
| 60 |
2.17.1 |
| 61 |
EOF |
| 62 |
|
| 63 |
cd .. |
| 64 |
|
| 65 |
TARGETS="aarch64-linux-gnu arm-linux-gnueabi i686-w64-mingw32" |
| 66 |
|
| 67 |
gcc_major=8 |
| 68 |
if [ -d $MOZ_FETCHES_DIR/sysroot ]; then |
| 69 |
# Don't silently use a non-existing directory for C++ headers. |
| 70 |
[ -d $MOZ_FETCHES_DIR/sysroot/usr/include/c++/$gcc_major ] || exit 1 |
| 71 |
export CFLAGS="-g -O2 --sysroot=$MOZ_FETCHES_DIR/sysroot" |
| 72 |
export CXXFLAGS="$CFLAGS -isystem $MOZ_FETCHES_DIR/sysroot/usr/include/c++/$gcc_major -isystem $MOZ_FETCHES_DIR/sysroot/usr/include/x86_64-linux-gnu/c++/$gcc_major" |
| 73 |
export LDFLAGS="-L$MOZ_FETCHES_DIR/sysroot/lib/x86_64-linux-gnu -L$MOZ_FETCHES_DIR/sysroot/usr/lib/x86_64-linux-gnu -L$MOZ_FETCHES_DIR/sysroot/usr/lib/gcc/x86_64-linux-gnu/8" |
| 74 |
fi |
| 75 |
|
| 76 |
|
| 77 |
# Build target-specific GNU as ; build them first so that the few documentation |
| 78 |
# files they install are overwritten by the full binutils build. |
| 79 |
|
| 80 |
for target in $TARGETS; do |
| 81 |
|
| 82 |
mkdir binutils-$target |
| 83 |
cd binutils-$target |
| 84 |
|
| 85 |
../binutils-source/configure --prefix /tools/binutils/ --disable-gold --disable-ld --disable-binutils --disable-gprof --disable-nls --target=$target $EXTRA_CONFIGURE_FLAGS || exit 1 |
| 86 |
make $make_flags || exit 1 |
| 87 |
make install $make_flags DESTDIR=$root_dir || exit 1 |
| 88 |
|
| 89 |
cd .. |
| 90 |
done |
| 91 |
|
| 92 |
# Build binutils |
| 93 |
mkdir binutils-objdir |
| 94 |
cd binutils-objdir |
| 95 |
|
| 96 |
# --enable-targets builds extra target support in ld. |
| 97 |
# Enabling aarch64 support brings in arm support, so we don't need to specify that too. |
| 98 |
../binutils-source/configure --prefix /tools/binutils/ --enable-gold --enable-plugins --disable-nls --enable-targets="$TARGETS" $EXTRA_CONFIGURE_FLAGS || exit 1 |
| 99 |
make $make_flags || exit 1 |
| 100 |
make install $make_flags DESTDIR=$root_dir || exit 1 |
| 101 |
|
| 102 |
cd .. |
| 103 |
|
| 104 |
# Make a package of the built binutils |
| 105 |
cd $root_dir/tools |
| 106 |
tar caf $root_dir/binutils.tar.zst binutils/ |