Re: Inline static data causes a section type conflict

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Feb 21, 2016 at 12:05 PM, Bernd Edlinger
<bernd.edlinger@xxxxxxxxxx> wrote:
> Hi,
>
> Maybe something like that works for you?
>
>
> cat test.cc
> #define _str(x) #x
> #define str(x) _str(x)
> #define PLACE_HERE(section,data)          \
>    asm(".pushsection " str(section) "\n\t" \
>        ".quad 999f \n\t"                   \
>        ".long " str(__LINE__) "\n\t"       \
>        ".long " str(data) "\n\t"           \
>        ".section .rodata\n\t"              \
>        "999: .string \"" __FILE__ "\"\n\t" \
>        ".popsection")
>
> const int* get_data()
> {
>    PLACE_HERE(.custom,123);
>    static const int data = 123;
>
>    return & data;
> }
>
> inline const int* inline_get_data()
> {
>    PLACE_HERE(.custom,123);
>    static const int inline_data = 123;
>
>    return & inline_data;
> }
>
> int main()
> {
>    (void) get_data();
>    (void) inline_get_data();
>    return 0;
> }
>
>
> Regards
> Bernd.

Hi Bernd,

This is very similar to the solution I currently have working fine.
I'd like to replace it, because:
 - I couldn't find a way to store __func__, which is a local char
array, unlike to __FILE__ and __LINE__.
 - constexpr functions cannot be used to transform __FILE__,
__PRETTY_FUNCTION__ and others.
 - If you need arguments for the asm block (Extended ASM), e.g: to
return the address of the stored value to avoid duplication, then
curly braces cannot be used, because of the asm dialect feature in
extended ASM blocks.
 - It is even less portable than the version in the original post.

Thanks,
Benedek



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux