This is an archive of the discontinued LLVM Phabricator instance.

[InstrProfiling] Use nobits as __llvm_prf_cnts section type in ELF
AcceptedPublic

Authored by phosek on Feb 19 2021, 9:48 PM.

Details

Summary

This can reduce the binary size because counters will no longer occupy
space in the binary, instead they will be allocated by dynamic linker.

Diff Detail

Event Timeline

phosek created this revision.Feb 19 2021, 9:48 PM
phosek requested review of this revision.Feb 19 2021, 9:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 19 2021, 9:48 PM
davidxl accepted this revision.Feb 20 2021, 9:40 AM

lgtm

This revision is now accepted and ready to land.Feb 20 2021, 9:40 AM

I'm looking into https://crbug.com/1180779 where a bunch of profile tests are failing with

Malformed instrumentation profile data
 error: No profiles could be merged.

This is the only commit that looks related in the regression range.

I also found https://lab.llvm.org/buildbot/#/builders/93/builds/1897 which has similar failures.

Is it possible for this change to cause these failures? Perhaps the host has an old static/dynamic linker that doesn't support something this requires?

Hello,

Power PC is also experiencing the same error,

Malformed instrumentation profile data
 error: No profiles could be merged.

I built a branch of main with this change reverted and the error goes away. Would it be possible to have this reverted for now until a proper solution has been created? Thanks!

Hello,

Power PC is also experiencing the same error,

Malformed instrumentation profile data
 error: No profiles could be merged.

I built a branch of main with this change reverted and the error goes away. Would it be possible to have this reverted for now until a proper solution has been created? Thanks!

I've managed to reproduce this locally in a Docker container. It's a bug in the older binutils bfd ld, the __start_ and __stop_ have incorrect addresses, it's working correctly in gold and also in newer binutils versions. I'll send a change to conditionally enable this feature with -fbinutils-version=, I'm just trying to identify what version of binutils this was fixed in.

Kazu has seen this error

error: SHT_NOBITS section '__llvm_prf_cnts' cannot have non-zero
initializers

This is with lld.

David

Do you know what's their setup or how to reproduce it?

Hello,

Power PC is also experiencing the same error,

Malformed instrumentation profile data
 error: No profiles could be merged.

I built a branch of main with this change reverted and the error goes away. Would it be possible to have this reverted for now until a proper solution has been created? Thanks!

I've managed to reproduce this locally in a Docker container. It's a bug in the older binutils bfd ld, the __start_ and __stop_ have incorrect addresses, it's working correctly in gold and also in newer binutils versions. I'll send a change to conditionally enable this feature with -fbinutils-version=, I'm just trying to identify what version of binutils this was fixed in.

I have bisected this to binutils 2.28 and I have sent D97336 to conditionalize the use of nobits to binutils >=2.28.

Hello,

Power PC is also experiencing the same error,

Malformed instrumentation profile data
 error: No profiles could be merged.

I built a branch of main with this change reverted and the error goes away. Would it be possible to have this reverted for now until a proper solution has been created? Thanks!

I've managed to reproduce this locally in a Docker container. It's a bug in the older binutils bfd ld, the __start_ and __stop_ have incorrect addresses, it's working correctly in gold and also in newer binutils versions. I'll send a change to conditionally enable this feature with -fbinutils-version=, I'm just trying to identify what version of binutils this was fixed in.

I have bisected this to binutils 2.28 and I have sent D97336 to conditionalize the use of nobits to binutils >=2.28.

Awesome, thank you for the prompt response! I appreciate it.

Kazu has seen this error

error: SHT_NOBITS section '__llvm_prf_cnts' cannot have non-zero
initializers

This is with lld.

David

I'm also seeing this in a bootstrapped PGO build.

$ ./tools/clang/scripts/build.py --llvm-force-head-revision --without-android --without-fuchsia --pgo --bootstrap
https://source.chromium.org/chromium/chromium/src/+/master:tools/clang/scripts/build.py?q=f:tools%2Fclang%2Fscripts%2Fbuild.py&ss=chromium

It appears using LLD after profile generation in the final optimized Clang build. e.g.

[72/3520] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/ELFAttributeParser.cpp.o
<unknown>:0: error: SHT_NOBITS section '__llvm_prf_cnts' cannot have non-zero initializers

Sorry, it's actually while building the instrumented compiler, not the final optimized compiler.

phosek added a comment.EditedFeb 23 2021, 4:20 PM

I'm still debugging this, but it looks like counters for global constructors (_GLOBAL__sub_I_ symbols) aren't marked as zeroinitializer which looks like a bug to me.

phosek reopened this revision.Feb 24 2021, 12:48 AM

The problem seems to be that Global Value Optimizer may evaluate and eliminate global initializer, and propagate the value to the counter symbol which is no longer zero initialized in that case. This is working as intended. Given that, we may have to change the logic to first ensure that the section content is all zeros before choosing the nobits type. I have reverted this change for now while I work on the implementation.

This revision is now accepted and ready to land.Feb 24 2021, 12:48 AM