From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp101.ord1d.emailsrvr.com (smtp101.ord1d.emailsrvr.com [184.106.54.101]) by sourceware.org (Postfix) with ESMTPS id 596BB384B822 for ; Sat, 23 Jan 2021 17:49:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 596BB384B822 X-Auth-ID: tom@honermann.net Received: by smtp21.relay.ord1d.emailsrvr.com (Authenticated sender: tom-AT-honermann.net) with ESMTPSA id 674B56012F; Sat, 23 Jan 2021 12:49:31 -0500 (EST) Subject: Re: Building gcc for C and C++ with a custom glibc To: "H.J. Lu" Cc: GCC Development References: From: Tom Honermann Message-ID: Date: Sat, 23 Jan 2021 12:49:29 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Classification-ID: add607b5-6f22-4780-8ae6-8e6fd8349510-1-1 X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, HTML_MESSAGE, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLACK autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 23 Jan 2021 17:49:34 -0000 On 1/17/21 4:08 PM, H.J. Lu wrote: > On Sun, Jan 17, 2021 at 1:06 PM Tom Honermann via Gcc wrote: >> Hi all. I've been trying to build a custom gcc (trunk) with a custom >> glibc (trunk) with support for C and C++ on x86_64 Linux and have so far >> been unsuccessful at identifying a sequence of configure/make >> invocations that completes successfully. I'm not trying to build a >> cross compiler. >> >> The scenario I'm trying to satisfy is testing some changes to gcc, and >> additional changes to libstdc++ that have new autoconf and header >> dependencies on the presence of new functions in existing glibc headers. >> >> The glibc installation I'm trying to use was built with: >> >> mkdir glibc-build >> cd glibc-build >> ../glibc/configure \ >> CC=gcc \ >> CXX=g++ \ >> --prefix /.../glibc >> make && make install >> >> For gcc, I've tried numerous variants of the following: >> >> mkdir gcc-build >> cd gcc-build >> ../gcc/configure \ >> CC=gcc \ >> CXX=g++ \ >> --prefix /.../gcc \ >> --disable-multilib \ >> --enable-languages=c,c++ \ >> --enable-checking=release \ >> --disable-bootstrap \ >> --disable-lto >> >> Things I've tried include setting CFLAGS, CXXFLAGS, and LDFLAGS to >> specify additional glibc paths, to specify alternate paths (via >> -nostdinc/-nostdinc++), setting LIBRARY_PATH and CPATH, passing >> --with-sysroot, passing --with-headers and --with-libs, passing >> --with-native-system-header-dir, some of those in conjunction with >> removing --disable-bootstrap, and wrapping gcc in a script that attempts >> to substitute certain include paths. >> >> The problem I'm having is that, in every attempt, the glibc headers and >> libraries from under /usr end up getting used instead of the custom >> glibc ones at some point leading to build failures. >> >> Does anyone have a recipe available for doing this? > Try scripts/build-many-glibcs.py in glibc source. > Thank you for the suggestion.  I studied the script and tried using it, but it also encountered errors during the 2nd stage gcc build.  I didn't delve into those errors. This is what ended up working for me: mkdir -p "$BINUTILS_BUILD_DIR" cd "$BINUTILS_BUILD_DIR" "../$BINUTILS_SOURCE_DIR/configure" \   CC=gcc \   CXX=g++ \   --prefix "$INSTALL_DIR" \   --with-sysroot="$INSTALL_DIR" \   --disable-multilib \ ; make -j 4 && make install cd - cd "$LINUX_SOURCE_DIR" make INSTALL_HDR_PATH="$INSTALL_DIR" headers_install cd - mkdir -p "$GLIBC_BUILD_DIR" cd "$GLIBC_BUILD_DIR" "../$GLIBC_SOURCE_DIR/configure" \   CC=gcc \   CXX=g++ \   --prefix "$INSTALL_DIR" \   --disable-multilib \   --with-headers="$INSTALL_DIR/include" \ ; make -j 4 && make install cd - # Fixup paths in libc.so and libm.so.  I wasn't able to find a combination of # 'configure --prefix' and 'make prefix=... DESTIDIR=...' that did the right thing. cp "$INSTALL_DIR/lib/libc.so" "$INSTALL_DIR/lib/libc.so.orig" sed -e "s%$INSTALL_DIR%%g" "$INSTALL_DIR/lib/libc.so.orig" > "$INSTALL_DIR/lib/libc.so" rm -f "$INSTALL_DIR/lib/libc.so.orig" cp "$INSTALL_DIR/lib/libm.so" "$INSTALL_DIR/lib/libm.so.orig" sed -e "s%$INSTALL_DIR%%g" "$INSTALL_DIR/lib/libm.so.orig" > "$INSTALL_DIR/lib/libm.so" rm -f "$INSTALL_DIR/lib/libm.so.orig" mkdir -p "$GCC_BUILD_DIR" cd "$GCC_BUILD_DIR" "../$GCC_SOURCE_DIR/configure" \   CC=gcc \   CXX=g++ \   --prefix "$INSTALL_DIR" \   --with-sysroot="$INSTALL_DIR" \   --with-native-system-header-dir="/include" \   --enable-languages=c,c++ \   --disable-bootstrap \   --disable-multilib \   --enable-checking=release \   --disable-lto \ ; make -j 4 && make install cd - Tom.