llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

non-optimal linkage for function local constant

Open echristo opened this issue 15 years ago • 10 comments

Bugzilla Link 10414
Resolution FIXED
Resolved on Aug 25, 2011 16:46
Version trunk
OS All
CC @lattner,@efriedma-quic

Extended Description

From 2005-02-27-MarkGlobalConstant.c from the llvm-gcc test suite:

void bar();
void foo() {
// CHECK: private unnamed_addr constant
char Blah[] = "asdlfkajsdlfkajsd;lfkajds;lfkjasd;flkajsd;lkfja;sdlkfjasd";
bar(Blah);
}

Blah is showing up as internal instead of private. I'm reasonably sure it can't be accessed outside the module so should be private.

echristo avatar Jul 20 '11 01:07 echristo

Fixed here:

[yendi:llvm/tools/clang] echristo% git svn dcommit Committing to https://llvm.org/svn/llvm-project/cfe/trunk ... M lib/CodeGen/CGDecl.cpp M test/CodeGen/2005-02-27-MarkGlobalConstant.c M test/CodeGen/decl.c M test/CodeGen/string-literal-short-wstring.c M test/CodeGen/string-literal.c Committed r138418 M test/CodeGen/string-literal-short-wstring.c M test/CodeGen/decl.c M test/CodeGen/2005-02-27-MarkGlobalConstant.c M test/CodeGen/string-literal.c M lib/CodeGen/CGDecl.cpp r138418 = 54b0e63fe7e792ec5beb4f9384a7943760c04d84 (refs/remotes/origin/master)

echristo avatar Aug 25 '11 23:08 echristo

as for as I know, linker_private puts the symbol in a symbol table in the .o so that the linker knows about it but lets the linker remove the symbol from any outputs it produces.

llvmbot avatar Aug 11 '11 17:08 llvmbot

What's the difference between private and linker_private? I've got to say that I find all these obscure linkage types pretty confusing. It would be great to have some examples of the use of each different linkage type in the LangRef.

PS: Dragonegg produces private linkage for the testcase.

llvmbot avatar Aug 11 '11 09:08 llvmbot

Yes, this should be fixed. It should be straight-forward enough, just have the frontend generate the right thing, using the same logic as string constants.

lattner avatar Aug 11 '11 08:08 lattner

you might need linker_private instead of private. See r127622/r127594.

llvmbot avatar Jul 20 '11 06:07 llvmbot

I'm getting that. :)

echristo avatar Jul 20 '11 04:07 echristo

; ModuleID = 'foo.c' target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" target triple = "x86_64-apple-darwin11.0.0"

@​foo.Blah = internal constant [58 x i8] c"asdlfkajsdlfkajsd;lfkajds;lfkjasd;flkajsd;lkfja;sdlkfjasd\00", align 16

define void @​foo() nounwind ssp { %Blah = alloca [58 x i8], align 16 %1 = bitcast [58 x i8]* %Blah to i8* call void @​llvm.memcpy.p0i8.p0i8.i64(i8* %1, i8* getelementptr inbounds ([58 x i8]* @​foo.Blah, i32 0, i32 0), i64 58, i32 16, i1 false) %2 = getelementptr inbounds [58 x i8]* %Blah, i32 0, i32 0 call void (...)* @​bar(i8* %2) ret void }

declare void @​llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind

declare void @​bar(...)

echristo avatar Jul 20 '11 04:07 echristo

Blah is a local symbol, it doesn't have linkage. Are you talking about the constant string that we probably memcpy from? What exact IR are you getting?

lattner avatar Jul 20 '11 03:07 lattner

Yes, same applies though. :)

echristo avatar Jul 20 '11 02:07 echristo

Private vs. internal is more a question of whether something shows up in the symbol table rather than whether it's actually visible... but in this case, yes, private makes sense.

efriedma-quic avatar Jul 20 '11 02:07 efriedma-quic