[PATCH 2/3] Use the alias attribute with GNU compiler only

Michael Haubenwallner michael.haubenwallner at ssi-schaefer.com
Thu Aug 29 17:06:03 UTC 2019


Hi Guillem,

On 8/28/19 12:30 PM, Guillem Jover wrote:
> Hi!
> 
> It seems I completely forgot about the weak alias problem from your
> previous patchset, sorry about that!

Never mind!

> 
> On Thu, 2019-08-22 at 16:55:43 +0200, Michael Haubenwallner wrote:
>> +#ifdef __GNUC__
> 
> At least clang does also support this too. But…

Ah, ok (no clang here).

> 
>> +#  define __strong_alias(newsym, sym, argsdecl, argspass) \
>>  	__typeof__ (sym) newsym __attribute__ ((alias (#sym)));
>>  
>> +#else /* !__GNUC__ */
>> +
>> +/*
>> + * There is the undocumented MSVC linker flag "/alternatename" for some
>> + * kind of weak aliasing, but that works for 32bit (x86) MSVC only.
>> + * So for compilers other than GCC we just provide real functions.
>> + */
>> +#  define __strong_alias(newsym, sym, argsdecl, argspass) \
>> +    void newsym argsdecl { sym argspass; }
> 
> … in any case, I've now pushed most of the patches (thanks!),

Thanks - one nit for src/Makefile.am:
The new local-link.h currently is removed during make 'clean' or 'distclean'.
Moving from libmd_la_helper_sources to libmd_la_SOURCES would fix that.

> and I've
> been checking around and I might have found a way to use a cleaner
> macro with:
> 
>   <https://docs.microsoft.com/en-us/cpp/preprocessor/comment-c-cpp?view=vs-2019>
>   <https://docs.microsoft.com/en-us/cpp/build/reference/linker-options?view=vs-2019>
>   <https://docs.microsoft.com/en-us/cpp/build/reference/export-exports-a-function?view=vs-2019>

Nice, didn't know before that /EXPORT does allow for alternative names.

> 
> And even though from the following:
> 
>   <https://docs.microsoft.com/en-us/cpp/build/reference/decorated-names?view=vs-2019>
> 
> it might seem like only decorated names are to be used this way, from
> this one:
> 
>   <https://docs.microsoft.com/en-us/cpp/build/reference/exports?view=vs-2019>
> 
> I'd expect any alias is possible. So, could you give the attached patch
> a go?

Indeed, this allows for any alias - but only for *users* of the *DLL*!
These aliases are neither available inside the DLL, nor for static linking.

So inside the DLL we have to use the real implementations, and when creating the
static library I still don't see any option other than providing real functions.

But still, having the aliases for users of the DLL is a great deal!

Attached two patches do allow me to compile and 'make check' with MSVC version
from 2010 to 2019, both x86 and x64 each, with Cygwin as build environment.

Thanks!
/haubi/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Do-not-clean-local-link.h.patch
Type: text/x-patch
Size: 726 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/libbsd/attachments/20190829/bcddb7d2/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Provide-strong-aliases-in-DLL-built-with-MSVC.patch
Type: text/x-patch
Size: 3513 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/libbsd/attachments/20190829/bcddb7d2/attachment-0001.bin>


More information about the libbsd mailing list