mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Sagar Tiwari <fctorial@gmail.com>
Cc: musl@lists.openwall.com
Subject: Re: [musl] printf segfaults on recent musl versions
Date: Mon, 11 Jan 2021 13:13:44 -0500	[thread overview]
Message-ID: <20210111181344.GB23432@brightrain.aerifal.cx> (raw)
In-Reply-To: <CABitn4PwPynB3P9bxUgdTKQg5R4wsXjEXYRswoN8oz9hAtrtwA@mail.gmail.com>

On Mon, Jan 11, 2021 at 10:31:21PM +0530, Sagar Tiwari wrote:
> Hi,
> 
> Apologies if this isn't a support forum for musl. I couldn't find any
> such portal online.
> 
> I'm trying to compile a program with musl libc. Dynamically linked
> version of this program works fine, but the statically linked version
> segfaults whenever `printf` is invoked. This is how a debugging
> session looks like:
> 
> <pre>
> $ gdb out/sm
> GNU gdb (GDB) 9.2
> Copyright (C) 2020 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
> This is free software: you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.
> Type "show copying" and "show warranty" for details.
> This GDB was configured as "x86_64-unknown-linux-gnu".
> Type "show configuration" for configuration details.
> For bug reporting instructions, please see:
> <http://www.gnu.org/software/gdb/bugs/>.
> Find the GDB manual and other documentation resources online at:
>     <http://www.gnu.org/software/gdb/documentation/>.
> 
> For help, type "help".
> Type "apropos word" to search for commands related to "word"...
> Reading symbols from out/sm...
> (gdb) b printf
> Breakpoint 1 at 0x100ac: file src/stdio/printf.c, line 5.
> (gdb) r
> Starting program: /home/fctorial/src/pgs/c/out/sm
> 
> Breakpoint 1, printf (fmt=0x1004f <msg1> "hello world from printf\n")
> at src/stdio/printf.c:5
> 5       {
> (gdb) n
> 
> Program received signal SIGSEGV, Segmentation fault.
> 0x000000000001010a in printf (fmt=0x1004f <msg1> "hello world from
> printf\n") at src/stdio/printf.c:5
> 5       {
> (gdb) quit
> A debugging session is active.
> 
>         Inferior 1 [process 25984] will be killed.
> 
> Quit anyway? (y or n) EOF [assumed Y]
> 
> </pre>
> 
> This issue appears when linking with recent musl versions (within an
> year). 1.0.0 doesn't have this issue. I can call other functions like
> 'rand', 'strlen' without any issue. `printf` and `puts` are
> segfaulting.

Can you elaborate on how you compiled/linked (using musl-gcc wrapper?
mcm-built or distro-provided toolchain or one you built yourself?
etc.)

Judging from the very low address in gdb output, my guess is that you
have a broken toolchain that's trying to link static pie without using
the right link options or start files.

Rich

  reply	other threads:[~2021-01-11 18:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-11 17:01 Sagar Tiwari
2021-01-11 18:13 ` Rich Felker [this message]
2021-01-11 19:16   ` Sagar Tiwari
2021-01-11 19:24     ` Rich Felker
     [not found]       ` <CABitn4OQEwVRugNHSHLDjTiMLdyh+KZBO6qSMorC8=CUSv5smg@mail.gmail.com>
2021-01-12  3:29         ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210111181344.GB23432@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=fctorial@gmail.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).