public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* aarch64 inline asm / -fPIC problem
@ 2020-08-27 21:23 Joe Buehler
  2020-08-28 13:45 ` Joe Buehler
  2020-08-29 15:45 ` Andrew Haley
  0 siblings, 2 replies; 7+ messages in thread
From: Joe Buehler @ 2020-08-27 21:23 UTC (permalink / raw)
  To: gcc-help

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: aarch64 inline asm / -fPIC problem
  2020-08-27 21:23 aarch64 inline asm / -fPIC problem Joe Buehler
@ 2020-08-28 13:45 ` Joe Buehler
  2020-08-28 15:17   ` Joe Buehler
  2020-08-29 15:45 ` Andrew Haley
  1 sibling, 1 reply; 7+ messages in thread
From: Joe Buehler @ 2020-08-28 13:45 UTC (permalink / raw)
  Cc: gcc-help

I looked at the gcc 7.3.0 source and got a hint.  Interestingly,
changing the constraint from "i" to "X" fixes the problem.  Seems like a
gcc bug to me.

Joe Buehler


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: aarch64 inline asm / -fPIC problem
  2020-08-28 13:45 ` Joe Buehler
@ 2020-08-28 15:17   ` Joe Buehler
  0 siblings, 0 replies; 7+ messages in thread
From: Joe Buehler @ 2020-08-28 15:17 UTC (permalink / raw)
  Cc: gcc-help

There are still some issues with this, "X" does not always work when I
compile real code.  Sometimes it does, sometimes it doesn't.

Joe Buehler


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: aarch64 inline asm / -fPIC problem
  2020-08-27 21:23 aarch64 inline asm / -fPIC problem Joe Buehler
  2020-08-28 13:45 ` Joe Buehler
@ 2020-08-29 15:45 ` Andrew Haley
  2020-09-02 18:25   ` aph@redhat.com Joe Buehler
  2020-09-02 18:26   ` aarch64 inline asm / -fPIC problem Joe Buehler
  1 sibling, 2 replies; 7+ messages in thread
From: Andrew Haley @ 2020-08-29 15:45 UTC (permalink / raw)
  To: Joe Buehler, gcc-help

On 27/08/2020 22:23, Joe Buehler via Gcc-help wrote:

    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

I'd use the "S" constraint.

> 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?)

"%%"

-- 
Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: aph@redhat.com
  2020-08-29 15:45 ` Andrew Haley
@ 2020-09-02 18:25   ` Joe Buehler
  2020-09-03 10:18     ` aph@redhat.com Andrew Haley
  2020-09-02 18:26   ` aarch64 inline asm / -fPIC problem Joe Buehler
  1 sibling, 1 reply; 7+ messages in thread
From: Joe Buehler @ 2020-09-02 18:25 UTC (permalink / raw)
  To: Andrew Haley; +Cc: gcc-help

Andrew Haley wrote:
> On 27/08/2020 22:23, Joe Buehler via Gcc-help wrote:
> 
>     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
> 
> I'd use the "S" constraint.

Thanks that worked.

> 
>> 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?)
> 
> "%%"
> 

The problem is that I have literal printf format strings in a multiplatform code base.  I need something like a gcc builtin to do the % doubling.

#define X(fmt) asm ("lines " __builtin_escape(fmt) " more lines")

Joe Buehler

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: aarch64 inline asm / -fPIC problem
  2020-08-29 15:45 ` Andrew Haley
  2020-09-02 18:25   ` aph@redhat.com Joe Buehler
@ 2020-09-02 18:26   ` Joe Buehler
  1 sibling, 0 replies; 7+ messages in thread
From: Joe Buehler @ 2020-09-02 18:26 UTC (permalink / raw)
  To: Andrew Haley; +Cc: gcc-help

Andrew Haley wrote:
> On 27/08/2020 22:23, Joe Buehler via Gcc-help wrote:
> 
>     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
> 
> I'd use the "S" constraint.

Thanks that worked.

> 
>> 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?)
> 
> "%%"
> 

The problem is that I have literal printf format strings in a multiplatform code base.  I need something like a gcc builtin to do the % doubling.

#define X(fmt) asm ("lines " __builtin_escape(fmt) " more lines")

Joe Buehler

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: aph@redhat.com
  2020-09-02 18:25   ` aph@redhat.com Joe Buehler
@ 2020-09-03 10:18     ` Andrew Haley
  0 siblings, 0 replies; 7+ messages in thread
From: Andrew Haley @ 2020-09-03 10:18 UTC (permalink / raw)
  To: Joe Buehler; +Cc: gcc-help

On 02/09/2020 19:25, Joe Buehler wrote:
> Andrew Haley wrote:
>> On 27/08/2020 22:23, Joe Buehler via Gcc-help wrote:
>>
>>     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
>>
>> I'd use the "S" constraint.
>
> Thanks that worked.
>
>>> 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?)
>>
>> "%%"
>
> The problem is that I have literal printf format strings in a
> multiplatform code base.  I need something like a gcc builtin to do
> the % doubling.
>
> #define X(fmt) asm ("lines " __builtin_escape(fmt) " more lines")

I'm not sure I really understand the problem. You only need the "%%"
if the "%" characters are in the actual asm string, not the parameter
passed, which can be any string. If you're assuming that it's possible
to create inline asm code portable across non-GCC compilers, then that
hasn't ever been so.

Having said that, I'm fairly sure that __builtin_escape() could be
written in C++. If you were feeling brave!

-- 
Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-09-03 10:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-27 21:23 aarch64 inline asm / -fPIC problem Joe Buehler
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

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).