[cfe-dev] different gcc/clang behavior for Internal visibility

Y Song via cfe-dev cfe-dev at lists.llvm.org
Mon May 10 12:30:08 PDT 2021


Hi,

The bpf linker project tries to explore to use INTERNAL visibility as in
   https://lore.kernel.org/bpf/20210507054119.270888-1-andrii@kernel.org/

But we found clang actually changed user "internal" visibility to "hidden".
For example, I have the following example,

$ cat t.c
int __attribute__((visibility("internal"))) foo() { return 0; }
$ clang -c t.c && llvm-readelf -s t.o | grep foo
     3: 0000000000000000     8 FUNC    GLOBAL HIDDEN      2 foo
$ gcc -c t.c && llvm-readelf -s t.o | grep foo
     8: 0000000000000000    11 FUNC    GLOBAL INTERNAL    1 foo
$

Looks like this is caused by clang Attr.td,

diff --git a/clang/include/clang/Basic/Attr.td
b/clang/include/clang/Basic/Attr.td
index 5e04f32187cd..4559a1bcfe42 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2776,7 +2776,7 @@ def Visibility : InheritableAttr {
   let Spellings = [GCC<"visibility">];
   let Args = [EnumArgument<"Visibility", "VisibilityType",
                            ["default", "hidden", "internal", "protected"],
-                           ["Default", "Hidden", "Hidden", "Protected"]>];
+                           ["Default", "Hidden", "Internal", "Protected"]>];
   let MeaningfulToClassTemplateDefinition = 1;
   let Documentation = [Undocumented];
 }
@@ -2786,7 +2786,7 @@ def TypeVisibility : InheritableAttr {
   let Spellings = [Clang<"type_visibility">];
   let Args = [EnumArgument<"Visibility", "VisibilityType",
                            ["default", "hidden", "internal", "protected"],
-                           ["Default", "Hidden", "Hidden", "Protected"]>];
+                           ["Default", "Hidden", "Internal", "Protected"]>];
 //  let Subjects = [Tag, ObjCInterface, Namespace];
   let Documentation = [Undocumented];
 }

One of early commits,

commit 570024a8d9b4a4aa4a35f077a0a65003dc7b71fe
Author: Eli Friedman <eli.friedman at gmail.com>
Date:   Thu Aug 5 06:57:20 2010 +0000

    Implement #pragma GCC visibility.

    llvm-svn: 110315

I see

+    else if (VisType->isStr("internal"))
+      type = VisibilityAttr::HiddenVisibility; // FIXME

Do we have any plan to support Internal visibility?

Thanks,

Yonghong


More information about the cfe-dev mailing list