__attribute__((alias(foo))) and the hardening flags

Jerry James loganjerry at gmail.com
Fri Mar 13 14:59:27 UTC 2015


On Thu, Mar 12, 2015 at 7:09 PM, Kevin Kofler <kevin.kofler at chello.at> wrote:
> Don't use __attribute__((alias(foo_gmp))), use asm("foo_gmp"), as per:
> https://gcc.gnu.org/onlinedocs/gcc-4.9.2/gcc/Asm-Labels.html

We need both names available, the "_gmp"-suffixed version for
polymake, and the standard version for everything else.  The asm trick
doesn't seem to accomplish that.  Here is the contents of test.c:

extern int foo_gmp (int x) asm ("foo");

int foo_gmp (int x) {
  return x + 1;
}

extern int bar (int x) __attribute__((alias("bar_gmp")));

int bar_gmp (int x) {
  return x - 1;
}

Compile with something like "gcc -c test.c", then run "readelf -a
test.o".  You'll see the symbol table looks like this:

Symbol table '.symtab' contains 17 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS test.c
     2: 0000000000000000     0 SECTION LOCAL  DEFAULT    1
     3: 0000000000000000     0 SECTION LOCAL  DEFAULT    2
     4: 0000000000000000     0 SECTION LOCAL  DEFAULT    3
     5: 0000000000000000     0 SECTION LOCAL  DEFAULT    4
     6: 0000000000000000     0 SECTION LOCAL  DEFAULT    5
     7: 0000000000000000     0 SECTION LOCAL  DEFAULT    7
     8: 0000000000000000     0 SECTION LOCAL  DEFAULT    8
     9: 0000000000000000     0 SECTION LOCAL  DEFAULT   10
    10: 0000000000000000     0 SECTION LOCAL  DEFAULT   12
    11: 0000000000000000     0 SECTION LOCAL  DEFAULT   14
    12: 0000000000000000     0 SECTION LOCAL  DEFAULT   15
    13: 0000000000000000     0 SECTION LOCAL  DEFAULT   13
    14: 0000000000000000     4 FUNC    GLOBAL DEFAULT    1 foo
    15: 0000000000000010     4 FUNC    GLOBAL DEFAULT    1 bar_gmp
    16: 0000000000000010     4 FUNC    GLOBAL DEFAULT    1 bar

So the asm approach changes the name that is emitted, rather than
aliasing it.  Thanks for the suggestion, though.
-- 
Jerry James
http://www.jamezone.org/


More information about the devel mailing list