----- Original Message -----
> From: "Jan Stancek" <[email protected]>
> To: [email protected]
> Cc: [email protected]
> Sent: Thursday, 21 August, 2014 4:45:10 PM
> Subject: Re: [LTP] [PATCH/RFC] profil01: don't use address of function

> > If we are in doubt, we should add a configure check and use it only when
> > available. And probably to default to &test_profil in all cases but
> > ppc64 BE which is known to fail.
> 
> I'm trying one other idea:
> 
> +static inline void *get_pc(void)
> +{
> +       extern void *profil01_label;
> +
> +       asm("profil01_label:");
> +       return &profil01_label;
> +}
> 

Both ways seem to work fine at least since gcc-4.1, and very first clang
released in LLVM 2.6 [1]:

# cat getpc.c 
#include <stdio.h>

static inline void *get_pc(void)
{
        extern void *profil01_label;

        asm("profil01_label:");
        return &profil01_label;
}

static void __attribute__ ((noinline)) *get_pc_gcc(void)
{
        return __builtin_return_address(0);
}

int main()
{
        printf("%p %p %p\n", get_pc(), get_pc_gcc(), &main);
}

# ./clang/llvm+clang-2.6-x86_64-linux/bin/clang -O2 getpc.c
# ./a.out 
0x400534 0x400539 0x400530

Regards,
Jan

[1] http://llvm.org/releases/2.6/docs/ReleaseNotes.html

------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to