This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt] Build all alias in builtin as private external on Darwin
ClosedPublic

Authored by steven_wu on Jan 28 2020, 1:11 PM.

Details

Summary

For builtin compiler-rt, it is built with visibility hidden by default
to avoid the client exporting symbols from libclang static library. The
compiler option -fvisibility=hidden doesn't work on the aliases in c files
because they are created with inline assembly. On Darwin platform,
thoses aliases are exported by default if they are reference by the client.

Fix the issue by adding ".private_extern" to all the aliases if the
library is built with visibility hidden.

rdar://problem/58960296

Diff Detail

Event Timeline

steven_wu created this revision.Jan 28 2020, 1:11 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJan 28 2020, 1:11 PM
Herald added subscribers: Restricted Project, ributzka, jkorous, dberris. · View Herald Transcript

Should there be a COMPILER_RT_ALIAS and COMPILER_RT_HIDDEN_ALIAS macro? Does this change effect the libcompiler_rt.dylib in the OS. In the dylib, I suspect the aliases should be global.

@steven_wu I'm having difficultly understanding the description.

For builtin compiler-rt, it is built with visibility hidden by default
to avoid the client exporting symbols from libclang static library.

You mean to avoid exporting symbols from the libclang_rt to the client, right?

The compiler option doesn't work on the alias which is created with inline assembly.

What is "The compiler option"? You mean the default visibility compiler option, right?

On Darwin platform, thoses aliases are exported by default if
they are reference by the client.
Fix the issue by adding ".private_extern" to all the aliases on Darwin

It is really not obvious what "the issue" is here? Are you saying that the "On Darwin platform, thoses aliases are exported by default if they are reference by the client." behaviour is what is happening right now and that this behaviour is incorrect?

Should there be a COMPILER_RT_ALIAS and COMPILER_RT_HIDDEN_ALIAS macro? Does this change effect the libcompiler_rt.dylib in the OS. In the dylib, I suspect the aliases should be global.

compiler_rt is unconditionally built with -fvisibility=hidden. There is no reason to have none private extern symbols in the static library for Darwin. Maybe it can be a problem for building libcompiler_rt.dylib. I guess I can condition the macro based on -DVISIBILITY_HIDDEN

@steven_wu I'm having difficultly understanding the description.

For builtin compiler-rt, it is built with visibility hidden by default
to avoid the client exporting symbols from libclang static library.

You mean to avoid exporting symbols from the libclang_rt to the client, right?

yes.

The compiler option doesn't work on the alias which is created with inline assembly.

What is "The compiler option"? You mean the default visibility compiler option, right?

-fvisibility=hidden

On Darwin platform, thoses aliases are exported by default if
they are reference by the client.
Fix the issue by adding ".private_extern" to all the aliases on Darwin

It is really not obvious what "the issue" is here? Are you saying that the "On Darwin platform, thoses aliases are exported by default if they are reference by the client." behaviour is what is happening right now and that this behaviour is incorrect?

Right now, the aliases are exported symbols by default from the client on darwin if you don't use an export list. That is not the correct behavior.

steven_wu updated this revision to Diff 240987.Jan 28 2020, 2:05 PM

Conditionalize the .private_extern based on VISIBILITY_HIDDEN macro

@steven_wu Please fix the description and commit message to address my questions. I don't think the original is clear enough.

@steven_wu I'm having difficultly understanding the description.

For builtin compiler-rt, it is built with visibility hidden by default
to avoid the client exporting symbols from libclang static library.

You mean to avoid exporting symbols from the libclang_rt to the client, right?

yes.

The compiler option doesn't work on the alias which is created with inline assembly.

What is "The compiler option"? You mean the default visibility compiler option, right?

-fvisibility=hidden

On Darwin platform, thoses aliases are exported by default if
they are reference by the client.
Fix the issue by adding ".private_extern" to all the aliases on Darwin

It is really not obvious what "the issue" is here? Are you saying that the "On Darwin platform, thoses aliases are exported by default if they are reference by the client." behaviour is what is happening right now and that this behaviour is incorrect?

Right now, the aliases are exported symbols by default from the client on darwin if you don't use an export list. That is not the correct behavior.

@steven_wu

The aliases are exported by the client because the object files from the compiler runtime get pulled into client binary at link time. Correct?

It was updated locally on my side but I guess it won't reflected here. Updating.

steven_wu edited the summary of this revision. (Show Details)Jan 28 2020, 4:25 PM

@steven_wu Thanks for fixing the text.

I can't comment on the use of .private_extern because I'm not familiar with it. Using the VISIBILITY_HIDDEN macro which seems to be defined by darwin_add_builtin_libraries() seems reasonable. I don't know about the OS builtin libraries though. Any thoughts @kledzik ?

delcypher accepted this revision.Feb 23 2020, 5:52 PM

Seems okay but I think you should check with @kledzik before landing.

This revision is now accepted and ready to land.Feb 23 2020, 5:52 PM
This revision was automatically updated to reflect the committed changes.