mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-28 09:31:03 +00:00
[asan] when creating string constants, set unnamed_attr and align 1 so that equal strings are merged by the linker. Observed up to 1% binary size reduction. Thanks to Anton Korobeynikov for the suggestion
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@177264 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5e8da1773c
commit
5111627ac1
@ -531,9 +531,12 @@ static size_t TypeSizeToSizeIndex(uint32_t TypeSize) {
|
||||
// Create a constant for Str so that we can pass it to the run-time lib.
|
||||
static GlobalVariable *createPrivateGlobalForString(Module &M, StringRef Str) {
|
||||
Constant *StrConst = ConstantDataArray::getString(M.getContext(), Str);
|
||||
return new GlobalVariable(M, StrConst->getType(), true,
|
||||
GlobalVariable *GV = new GlobalVariable(M, StrConst->getType(), true,
|
||||
GlobalValue::PrivateLinkage, StrConst,
|
||||
kAsanGenPrefix);
|
||||
GV->setUnnamedAddr(true); // Ok to merge these.
|
||||
GV->setAlignment(1); // Strings may not be merged w/o setting align 1.
|
||||
return GV;
|
||||
}
|
||||
|
||||
static bool GlobalWasGeneratedByAsan(GlobalVariable *G) {
|
||||
|
@ -14,6 +14,7 @@ entry:
|
||||
|
||||
declare void @_Z3fooPi(i32*)
|
||||
; We create one global string constant for the stack frame above.
|
||||
; It should have unnamed_addr and align 1.
|
||||
; Make sure we don't create any other global constants.
|
||||
; CHECK: = private constant
|
||||
; CHECK-NOT: = private constant
|
||||
; CHECK: = private unnamed_addr constant{{.*}}align 1
|
||||
; CHECK-NOT: = private unnamed_addr constant
|
||||
|
Loading…
x
Reference in New Issue
Block a user