public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
To: Andi Kleen <andi@firstfloor.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Ian Lance Taylor <iant@google.com>,
	gcc-help@gcc.gnu.org
Cc: linux-kernel@vger.kernel.org, rostedt@goodmis.org,
	Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
Subject: Userspace Tracepoints, -fPIC -m32 question
Date: Mon, 9 Nov 2009 18:38:42 -0500	[thread overview]
Message-ID: <20091109233842.GA4683@Krystal> (raw)

Hi,

I've been looking into the problem explained below for a while, and have
a hard time figuring out if it is actually possible to pass a C pointer
as gcc inline assembly immediate operand in a way that works with -fPIC
on 32-bit i386. It works fine for x86_64 (both with and w/o -fPIC) and
with 32-bit i386 w/o fPIC.

The problem on 32-bit i386 with fPIC is that the assembly generated
should contain a GOTOFF relocation because the address seems to be
treated as a global symbol. e.g., using a "m" (var) operand turns the
code presented in the forwarded message (below) into:

        .long var.1195@GOTOFF(%ecx), (1f)

Ideas and comments would be very welcome.

Thanks,

Mathieu

----- Forwarded message from Pierre-Marc Fournier <pierre-marc.fournier@polymtl.ca> -----

Date: Mon, 09 Nov 2009 16:23:10 -0500
To: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20090701)
From: Pierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Subject: Questions about position-independent  code

Hi Mathieu,

Perhaps you can help with an issue I have concerning
position-independent code on x86. Or maybe you know someone who could help.

Consider the code below. It compiles perfectly well on x86-64 with or
without -fPIC.

However, on x86-32, it compiles only when the -fPIC option is not
specified. Otherwise, gcc gives the following error:

immprob.c: In function 'func':
immprob.c:15: warning: asm operand 0 probably doesn't match constraints
immprob.c:15: error: impossible constraint in 'asm'


My questions:
- Is it important to generated PIC code for libraries on x86-32? It
seems to work perfectly well to make them as non-PIC. Libtool on my
system does however put the -fPIC flag to gcc when building libraries on
x86-32.

- Assuming it is important to make PIC libraries on x86-32, can I get
the address of "var" to be but statically in the __my_section section on
this architecture?

Thanks

pmf

---

#if x86_64
#define _ASM_PTR ".quad "
#else
#define _ASM_PTR ".long "
#endif

struct mystruct {
	int myint;
};

int func()
{
        static struct mystruct var __attribute__((section("mysec2")))
		= { 0 };

        asm (".section __my_section,\"aw\",@progbits\n\t"
             _ASM_PTR "%c[addr], (1f)\n\t"
             ".previous\n\t"
             "1:\n\t"
             :: [addr] "i" (&var)
        );

        return 0;
}

	

----- End forwarded message -----

-- 
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68

                 reply	other threads:[~2009-11-09 23:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20091109233842.GA4683@Krystal \
    --to=mathieu.desnoyers@polymtl.ca \
    --cc=andi@firstfloor.org \
    --cc=gcc-help@gcc.gnu.org \
    --cc=hpa@zytor.com \
    --cc=iant@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.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