From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by sourceware.org (Postfix) with ESMTPS id DCBE93857C58 for ; Wed, 27 Oct 2021 13:11:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DCBE93857C58 Received: by mail-qv1-xf2d.google.com with SMTP id h11so1656293qvk.4 for ; Wed, 27 Oct 2021 06:11:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=egf3ejHU0Ktgyn1FEb+5TvETfkVkxSGGv+g7zKoUBwo=; b=zRoP70Hn1aesgfoMkdJb/0J3PKSAKuGWQ6czY5Cevt38vTNGq6PA1m+4wH9IdHdqA4 nJgnVJvzkEggD9L17QSECbySNH/dlaqQqJeciP8/m80WlgL8E0MNd8O4JdDbE9uyB9WK prPikTyjUS4u2JVf2cR35BeNllnt/83RyydZ2b1xSjS3zr6gz1et6VD7rKTxwK20N2vn LM71gyXs03rn9JwQHjixiJy/soMZ8oUGpHPsao2yRxneCMHJRdvAtwV27F+EJUCFkd2P 4KPsAHu4wSz9YSrDdR4YUPx5g5TAdwIjMC/Nv3qa2oZ+0vvwySEKFy8oE19hK9lT70yn Z70g== X-Gm-Message-State: AOAM5301fcNJ1gc87EmeYaR6W4AAa7+ajQhaQ9n9BgLpa1riGzPAhGYZ WWWicnQG1g0EnWloe4N7olUXLnWLkRAmMA== X-Google-Smtp-Source: ABdhPJxj3Q2WzShChxgBgnmtnUfJBcwmNkHra6S+5vMSAK09ca4WYHfPwEFs4IGqp4VimPoWk3WppA== X-Received: by 2002:a05:6214:5c8:: with SMTP id t8mr26051024qvz.61.1635340302182; Wed, 27 Oct 2021 06:11:42 -0700 (PDT) Received: from ?IPV6:2804:431:c7cb:6672:6176:d3d6:1b13:4aed? ([2804:431:c7cb:6672:6176:d3d6:1b13:4aed]) by smtp.gmail.com with ESMTPSA id p187sm12269913qkd.101.2021.10.27.06.11.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Oct 2021 06:11:41 -0700 (PDT) Message-ID: Date: Wed, 27 Oct 2021 10:11:39 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.1.2 Subject: Re: [PATCH 0/3] Improve lld support and current status Content-Language: en-US To: Fangrui Song Cc: libc-alpha@sourceware.org, "H.J. Lu" , Tulio Magno Quites Machado Filho References: <20211026200346.3371750-1-adhemerval.zanella@linaro.org> <20211026203327.6b2o5k4cmkuzzm6j@google.com> From: Adhemerval Zanella In-Reply-To: <20211026203327.6b2o5k4cmkuzzm6j@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Oct 2021 13:11:45 -0000 On 26/10/2021 17:33, Fangrui Song wrote: >> The arm, sparcv9, mips, and riscv fail to build due different issues. On >> arm the loader fails to build: >> >>  ld.so fails with >>  ld.lld: error: relocation R_ARM_GOTOFF32 cannot be used against symbol >>  _dl_argv; recompile with -fPIC >>  >>> defined in >>  >>> /home/azanella/Projects/glibc/build/arm-linux-gnueabihf-lld/elf/librtld.os >>  >>> referenced by rtld.c:164 >>  >>>               /home/azanella/Projects/glibc/build/arm-linux-gnueabihf-lld/elf/librtld.os:(.text+0xA8) > > R_ARM_GOTOFF32 = S + A - GOT_ORG  . > Such a relocation referencing a preemptible symbol cannot be used. > > Filed GNU ld bug: https://sourceware.org/bugzilla/show_bug.cgi?id=28501 > > _dl_argv needs to be made non-preemptible. There are many ways: --dynamic-list, -Bsymbolic, hidden visibility. I think it is something else, the symbols is defined as hidden (output of preprocessor): extern __typeof (_dl_argv) _dl_argv __asm__ ("" "__GI__dl_argv") __attribute__ ((visibility ("hidden"))); However, hidden is set only the internal symbol: $ arm-glibc-linux-gnueabi-readelf -Ws elf/librtld.os | grep _dl_argv 1378: 00000000 4 OBJECT GLOBAL DEFAULT 6 _dl_argv 1470: 00000000 4 OBJECT GLOBAL HIDDEN 6 __GI__dl_argv And on rtld.c assembly we have the directive to use the internal definition: .set _dl_argv,__GI__dl_argv So why lld is not binding the usage to internal to the local hidden alias? > >> On sparcv9, lld handles --relax option different than ld.bfd: it throws >> an error instead of silent ignoring it: >> >>  $ sparc64-glibc-linux-gnu-gcc -mcpu=niagara -fuse-ld=lld -Bclang+llvm-13.0.0-x86_64-linux-gnu-ubuntu-20.04/bin >>    -g -O2 -fPIC -shared -fno-stack-protector -o conftest.so conftest.c -nostdlib -nostartfiles -Wl,-z,combreloc >>  ld.lld: error: unknown argument '-relax' > > LLD's sparcv9 port is for retrocomputing fans:) and is far from usable > (see https://lld.llvm.org/ "production quality"). > The GOT/PLT support has quite a few issues (https://reviews.llvm.org/D102985). Right, but lld is still showing a different ld.bfd semantic that might trigger other issues where on platforms where neither --relax nor -no-relax it supported ld.bfd accepts both argument but ignore it [1]. At least on sparc, gcc does pass --relax and expects that static linker just ignore if it is no supported. [1] https://sourceware.org/binutils/docs-2.37/ld.html > >> And even when -mno-relax is explicit add, lld does not support some relocations >> generated by GCC: >> >>  $ sparc64-glibc-linux-gnu-readelf -Wr elf/librtld.os | grep _dl_skip_args >>  | head -n2 >>  00000000000000a0  0000012200000052 R_SPARC_GOTDATA_OP_HIX22 >>  0000000000000058 _dl_skip_args + 0 >>  00000000000000a4  0000012200000053 R_SPARC_GOTDATA_OP_LOX10 >>  0000000000000058 _dl_skip_args + 0 >> >> The mips/mipsel also fails to build the loader: >> >>  ld.lld: error: can't create dynamic relocation R_MIPS_32 against local >>  symbol in readonly segment; recompile object files with -fPIC or pass >>  '-Wl,-z,notext' to allow text relocations in the output >>  >>> defined in >>  >>> /home/azanella/Projects/glibc/build/mips-linux-gnu-lld/elf/librtld.os >>  >>> referenced by /home/azanella/toolchain/src/gcc/libgcc/libgcc2.c >>  >>>               /home/azanella/Projects/glibc/build/mips-linux-gnu-lld/elf/librtld.os:(.eh_frame+0x1C) >> >>  ld.lld: error: can't create dynamic relocation R_MIPS_32 against local >>  symbol in readonly segment; recompile object files with -fPIC or pass >>  '-Wl,-z,notext' to allow text relocations in the output >>  >>> defined in >>  >>> /home/azanella/Projects/glibc/build/mips-linux-gnu-lld/elf/librtld.os >>  >>> referenced by /home/azanella/toolchain/src/gcc/libgcc/libgcc2.c >>  >>>               /home/azanella/Projects/glibc/build/mips-linux-gnu-lld/elf/librtld.os:(.eh_frame+0x54) > > lld.llvm.org says "MIPS seems decent too." and I personally know really > little about MIPS. > > However, I think this is likely a genuine issue somewhere in sysdeps/mips/ . > Relocation processing is rigid and consistent in LLD. > GNU ld may miss some error checking for some relocation types. > >> Similar to mips64/mips64el: >> >>  ld.lld: warning: ../sysdeps/unix/sysv/linux/setitimer.c:(function >>  _dl_runtime_resolve: .text+0x18954): found R_MIPS_JALR relocation >>  against non-function symbol . This is invalid and most likely a compiler >>  bug. >>  ld.lld: error: can't create dynamic relocation R_MIPS_64 against local >>  symbol in readonly segment; recompile object files with -fPIC or pass >>  '-Wl,-z,notext' to allow text relocations in the output >>  >>> defined in >>  >>> /home/azanella/Projects/glibc/build/mips64-linux-gnu-lld/elf/librtld.os >>  >>> referenced by ../sysdeps/unix/sysv/linux/setitimer.c >>  >>>               /home/azanella/Projects/glibc/build/mips64-linux-gnu-lld/elf/librtld.os:(.eh_frame+0x20) > > I took a look at LLD's R_MIPS_JALR code and I am inclined to trust it > reporting a genuine issue. I give you that loader code is tricky, but it does not really explain why lld is failing to link the eh_frame. It *might* due some internal assembly routines, but at least from logs it does not seem so. > >> The riscv32/riscv64 fails to the loader, but it is due missing support >> to relaxation: >> >>  ld.lld: error: >>  /home/azanella/Projects/glibc/glibc-git/elf/rtld.c:2584:(.text+0xEC84): >>  relocation R_RISCV_ALIGN requires unimplemented linker relaxation; >>  recompile with -mno-relax >>  ld.lld: error: >>  /home/azanella/Projects/glibc/glibc-git/elf/rtld.c:2589:(.text+0x13DEC): >>  relocation R_RISCV_ALIGN requires unimplemented linker relaxation; >>  recompile with -mno-relax >>  ld.lld: error: >>  /home/azanella/Projects/glibc/glibc-git/elf/rtld.c:2589:(.text+0x13DEE): >>  relocation R_RISCV_ALIGN requires unimplemented linker relaxation; >>  recompile with -mno-rela > > LLD does not implement RISC-V linker relaxation. > R_RISCV_ALIGN has weird linker unfriendly semantics: > simply ignoring the relocation type can break semantics > (https://github.com/riscv-non-isa/riscv-elf-psabi-doc/issues/183). > >> Adding -mno-relax to sysdep-CFLAGS seems to be ineffective. > > So sysdep-CFLAGS is not a catch-all option affecting all C compiles... In fact it is, the problem was the autogenerated syscalls built from the assembly. I could avoid the R_RISCV_ALIGN with: diff --git a/sysdeps/riscv/Makefile b/sysdeps/riscv/Makefile index 20a9968106..28dbd89cb0 100644 --- a/sysdeps/riscv/Makefile +++ b/sysdeps/riscv/Makefile @@ -5,3 +5,9 @@ endif # RISC-V's assembler also needs to know about PIC as it changes the definition # of some assembler macros. ASFLAGS-.os += $(pic-ccflag) + +# lld does not implement R_RISCV_ALIGN relaxation optimization. +ifeq (yes,$(with-lld)) +ASFLAGS-.os += -Wa,-mno-relax +sysdep-CFLAGS += -mno-relax +endif However it does fail later for the libc.so with: ld.lld: warning: attempt to reassign symbol 'fcntl' of version 'GLIBC_2.27' to version 'GLIBC_2.28' ld.lld: warning: attempt to reassign symbol '__sched_get_priority_min' of version 'GLIBC_2.27' to version 'GLIBC_PRIVATE' ld.lld: warning: attempt to reassign symbol '__sched_get_priority_max' of version 'GLIBC_2.27' to version 'GLIBC_PRIVATE' ld.lld: error: relocation R_RISCV_RVC_JUMP cannot be used against symbol __sigsetjmp; recompile with -fPIC >>> defined in /home/azanella/Projects/glibc/build/riscv64-linux-gnu-rv64imafdc-lp64d-lld/libc_pic.os.clean >>> referenced by iconv.c:62 (/home/azanella/Projects/glibc/glibc-git/iconv/iconv.c:62) >>> /home/azanella/Projects/glibc/build/riscv64-linux-gnu-rv64imafdc-lp64d-lld/libc_pic.os.clean:(__GI__setjmp) ld.lld: error: relocation R_RISCV_JAL cannot be used against symbol exit; recompile with -fPIC >>> defined in /home/azanella/Projects/glibc/build/riscv64-linux-gnu-rv64imafdc-lp64d-lld/libc_pic.os.clean >>> referenced by gconv_open.c:89 (/home/azanella/Projects/glibc/glibc-git/iconv/gconv_open.c:89) >>> /home/azanella/Projects/glibc/build/riscv64-linux-gnu-rv64imafdc-lp64d-lld/libc_pic.os.clean:(__start_context) collect2: error: ld returned 1 exit status