public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Joe Buehler <aspam@cox.net>
To: gcc-help@gcc.gnu.org
Subject: aarch64 inline asm / -fPIC problem
Date: Thu, 27 Aug 2020 17:23:56 -0400	[thread overview]
Message-ID: <5F48246C.6040402@cox.net> (raw)

My (compiler test) program:

    int
    main()
    {
        __asm__ volatile(".8byte %0\n\t" : : "i" ("message %s\n"));
        return 0;
    }

This compiles fine with gcc 4.3.3 MIPS using:

gcc -S -fPIC temp.c

It fails with gcc 7.3.0 aarch64.  Output is:

    temp.c: In function  main :
    temp.c:4:2: warning: asm operand 0 probably doesn t match constraints
      __asm__ volatile(".8byte %0\n\t" : : "i" ("message %s\n"));
      ^~~~~~~
    temp.c:4:2: error: impossible constraint in  asm

Removing the -fPIC it will compile fine.

The relevant section of the MIPS generated code looks like this:

        .rdata
        .align    2
    $LC0:
        .ascii    "message %s\012\000"
        .text
        .align    2
        .globl    main
        .ent    main
        .type    main, @function
    main:
        .set    nomips16
        .frame    $fp,8,$31        # vars= 0, regs= 1/0, args= 0, gp= 0
        .mask    0x40000000,-4
        .fmask    0x00000000,0
        addiu    $sp,$sp,-8
        sw    $fp,4($sp)
        move    $fp,$sp
    #APP
     # 4 "temp.c" 1
        .8byte $LC0

I am unable to code something similar manually using inline asm because
the string is a format string containing % characters, which inline asm
will of course try to interpret. (Does gcc provide anything to escape %
chars in a literal string?)

Any suggestions? 

Joe Buehler


             reply	other threads:[~2020-08-27 21:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-27 21:23 Joe Buehler [this message]
2020-08-28 13:45 ` Joe Buehler
2020-08-28 15:17   ` Joe Buehler
2020-08-29 15:45 ` Andrew Haley
2020-09-02 18:25   ` aph@redhat.com Joe Buehler
2020-09-03 10:18     ` aph@redhat.com Andrew Haley
2020-09-02 18:26   ` aarch64 inline asm / -fPIC problem Joe Buehler

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=5F48246C.6040402@cox.net \
    --to=aspam@cox.net \
    --cc=gcc-help@gcc.gnu.org \
    /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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).