This is an archive of the discontinued LLVM Phabricator instance.

Order File Instrumentation: dump the data in compiler-rt (Make it work for Linux/Windows etc)
Needs ReviewPublic

Authored by manmanren on Mar 5 2019, 2:17 PM.

Details

Summary

The diff D57530 was accepted and I landed it as r355343. It works fine for Darwin, but caused build breakages for Linux/Windows etc.
This diff adds support for these platforms.

Diff Detail

Event Timeline

manmanren created this revision.Mar 5 2019, 2:17 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMar 5 2019, 2:17 PM
Herald added subscribers: Restricted Project, llvm-commits, jdoerfert, dberris. · View Herald Transcript
manmanren marked 3 inline comments as done.Mar 5 2019, 2:22 PM
manmanren added inline comments.
lib/profile/InstrProfilingPlatformLinux.c
67

I am getting undefined reference to `start_llvm_orderfile'. Not quite know where we define these symbols for PROF_CNTS etc.

lib/profile/InstrProfilingPlatformOther.c
88

Not sure what I should do for PlatformOther :[

lib/profile/InstrProfilingPlatformWindows.c
32

The windows implementation seems to be working at r355357 (http://lab.llvm.org:8011/builders/sanitizer-windows/builds/42814).

davidxl added inline comments.Mar 5 2019, 2:36 PM
lib/profile/InstrProfilingPlatformLinux.c
67

The cnt, data symbols are created in the related sections. Those symbols are created during instrumentation lowering -- see lib/Transforms/Instrumentation/InstrProfiling.cc

lib/profile/InstrProfilingPlatformOther.c
88

For these platforms, you need to add interface to register symbols in orderFile section, and this new interface just track the start and end of the section. The register functions are called during startup. See also lowering pass that generates call to register functions.

manmanren marked 2 inline comments as done.Mar 6 2019, 1:33 PM
manmanren added inline comments.
lib/profile/InstrProfilingPlatformLinux.c
67

I can't find INSTR_PROF_SECT_START or "__start_" in InstrProfiling.cpp. Can you provide a bit more info? Thanks!

lib/profile/InstrProfilingPlatformOther.c
88

Is __llvm_profile_register_function the one? Should we add a new function for orderFile section?

davidxl added inline comments.Mar 6 2019, 1:47 PM
lib/profile/InstrProfilingPlatformLinux.c
67

The start_xxx and stop_xxx symbols are automatically generated by the linker to reference to the start end stop address of section named 'xxx'. Compiler just need to put things into 'xxx':

CounterPtr->setSection(

getInstrProfSectionName(IPSK_cnts, TT.getObjectFormat()));
lib/profile/InstrProfilingPlatformOther.c
88

yes, there is also __llvm_profile_register_names_function for name sections.

emit the registration call in void InstrProfiling::emitRegistration() {..}

manmanren marked an inline comment as done.Mar 7 2019, 8:33 PM

Thanks!

Manman

lib/profile/InstrProfilingPlatformLinux.c
67

In InstrOrderFile.cpp, we have this already:

OrderFileBuffer->setSection(
    getInstrProfSectionName(IPSK_orderfile, TT.getObjectFormat()));

This actually works locally on my Linux machine.

The buildbot error message was
/home/buildbots/ppc64be-clang-multistage-test/clang-ppc64be-multistage/stage2/lib/clang/9.0.0/lib/linux/libclang_rt.profile-powerpc64.a(InstrProfilingPlatformLinux.c.o): In function `llvm_profile_begin_orderfile':
InstrProfilingPlatformLinux.c:(.text.
llvm_profile_begin_orderfile+0x2): undefined reference to `start_llvm_orderfile'
InstrProfilingPlatformLinux.c:(.text.llvm_profile_begin_orderfile+0x6): undefined reference to `start___llvm_orderfile'
/bin/ld: /home/buildbots/ppc64be-clang-multistage-test/clang-ppc64be-multistage/stage2/projects/compiler-rt/test/profile/Profile-powerpc64/Posix/Output/instrprof-dlopen.test.tmp.d/func.shared: hidden symbol `start_llvm_orderfile' isn't defined
/bin/ld: final link failed: Bad value
clang-9: error: linker command failed with exit code 1 (use -v to see invocation)

davidxl added inline comments.Mar 7 2019, 8:51 PM
lib/profile/InstrProfilingPlatformLinux.c
41

When the runtime is linked in but no instrumentation is done, you will need to add a dummy data for order file section here.