This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Possible bug with __attribute__((alias)) in gcc-3.3

Danny Smith wrote:

Nicholas wrote:

One problem is that you (or gcc) need to tell ld that 'foo' is function, not

I'll be the first to admit that I'm almost totally w/o a clue when it comes to assembly. I'm afraid the gas manual is not very helpful in my effort to alleviate this :-(.

Adding this to file foo.c (after the alias declaration):
__asm__ (".def _foo; .scl 2; .type 32; .endef\n");
would do that.

That fixes the testcase on mingw anyway.

Yes! Thanks, this helps a ton! I can confirm it works in native Cygwin, too.

I'm testing a patch now that would make gcc do that too (for aliased functions).

Cool deal, I look forward to trying it.

I only wish gas could better handle converting what I assume to be ELF syntax. This is often the case in other projects, for example from MySQL's strings-x86.s:

.globl bmove_allign
      .type  bmove_allign,@function
       <asm stuff>
       .size bmove_allign,.end-bmove_allign

Yes, this wish is pure laziness, but it would save time and make more asm code work OOTB if gas could deal with it.

However, in general,when you do dllexport with code written in straight
assembler, you will need to add a function directive like the one above
so that the linker does the right thing.

For the archives and in case anyone was curious, here's what I've devised (until your patch to gcc gets in) for {weak,strong}_alias macros:

#define weak_alias(name, aliasname) strong_alias(name, aliasname)

#define strong_alias(name, aliasname) \
 extern __typeof__(name) aliasname __attribute__((__alias__(#name))); \
 __asm__(".def \"_" #aliasname "\"; .scl 2; .type 32; .endef\n");

After your patch gets in, I'll drop the third line.

Again, I'm in uncharted territory, but... If you think it looks ok, I would like to add these compatibility macros to Cygwin's sys/cdefs.h. This is assuming that the values in .scl and .type remain static for PE-32bit. Feel free to add them to MingW, as well, if you want.

Why should we have them, one might ask? Frankly, because having to type out all that crap for each project takes too long and too much effort. I imagine this is why GNU & BSD put them in system headers in the first place. Bind is just one example of what happens when you don't have these macros. Just #define'ing the aliases in headers won't cut it because this will break some autoconf scripts or builds if the function is implicitly used by them (which I believe is the case for AC_CHECK_LIB).

(BTW, you've just reminded me of a  similar problem in libffi assembly code
that needs to be fixed.  Thanks )

No problem, glad to help ;-).


Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]