[llvm-branch-commits] [llvm] a6c14fb - [profile] Fix profile merging with binary IDs

2021-08-12 Thread Tom Stellard via llvm-branch-commits

Author: Petr Hosek
Date: 2021-08-12T22:46:22-07:00
New Revision: a6c14fba70e170a279f7e77f068368f09d8c5eaf

URL: 
https://github.com/llvm/llvm-project/commit/a6c14fba70e170a279f7e77f068368f09d8c5eaf
DIFF: 
https://github.com/llvm/llvm-project/commit/a6c14fba70e170a279f7e77f068368f09d8c5eaf.diff

LOG: [profile] Fix profile merging with binary IDs

This fixes support for merging profiles which broke as a consequence
of e50a38840dc3db5813f74b1cd2e10e6d984d0e67. The issue was missing
adjustment in merge logic to account for the binary IDs which are
now included in the raw profile just after header.

In addition, this change also:
* Includes the version in module signature that's used for merging
to avoid accidental attempts to merge incompatible profiles.
* Moves the binary IDs size field after version field in the header
as was suggested in the review.

Differential Revision: https://reviews.llvm.org/D107143

(cherry picked from commit 83302c84890e5e6cb74c7d6c9f8eaaa56db0077c)

Added: 


Modified: 
compiler-rt/include/profile/InstrProfData.inc
compiler-rt/lib/profile/InstrProfilingBuffer.c
compiler-rt/lib/profile/InstrProfilingMerge.c
compiler-rt/test/profile/Linux/binary-id.c
llvm/include/llvm/ProfileData/InstrProf.h
llvm/include/llvm/ProfileData/InstrProfData.inc
llvm/lib/ProfileData/InstrProfReader.cpp
llvm/test/tools/llvm-profdata/Inputs/c-general.profraw
llvm/test/tools/llvm-profdata/Inputs/compressed.profraw
llvm/test/tools/llvm-profdata/malformed-ptr-to-counter-array.test
llvm/test/tools/llvm-profdata/raw-32-bits-be.test
llvm/test/tools/llvm-profdata/raw-32-bits-le.test
llvm/test/tools/llvm-profdata/raw-64-bits-be.test
llvm/test/tools/llvm-profdata/raw-64-bits-le.test
llvm/test/tools/llvm-profdata/raw-two-profiles.test

Removed: 




diff  --git a/compiler-rt/include/profile/InstrProfData.inc 
b/compiler-rt/include/profile/InstrProfData.inc
index 08a642469627..7d2097cfc297 100644
--- a/compiler-rt/include/profile/InstrProfData.inc
+++ b/compiler-rt/include/profile/InstrProfData.inc
@@ -129,6 +129,7 @@ INSTR_PROF_VALUE_NODE(PtrToNodeT, 
llvm::Type::getInt8PtrTy(Ctx), Next, \
 #endif
 INSTR_PROF_RAW_HEADER(uint64_t, Magic, __llvm_profile_get_magic())
 INSTR_PROF_RAW_HEADER(uint64_t, Version, __llvm_profile_get_version())
+INSTR_PROF_RAW_HEADER(uint64_t, BinaryIdsSize, __llvm_write_binary_ids(NULL))
 INSTR_PROF_RAW_HEADER(uint64_t, DataSize, DataSize)
 INSTR_PROF_RAW_HEADER(uint64_t, PaddingBytesBeforeCounters, 
PaddingBytesBeforeCounters)
 INSTR_PROF_RAW_HEADER(uint64_t, CountersSize, CountersSize)
@@ -137,7 +138,6 @@ INSTR_PROF_RAW_HEADER(uint64_t, NamesSize,  NamesSize)
 INSTR_PROF_RAW_HEADER(uint64_t, CountersDelta, (uintptr_t)CountersBegin)
 INSTR_PROF_RAW_HEADER(uint64_t, NamesDelta, (uintptr_t)NamesBegin)
 INSTR_PROF_RAW_HEADER(uint64_t, ValueKindLast, IPVK_Last)
-INSTR_PROF_RAW_HEADER(uint64_t, BinaryIdsSize, __llvm_write_binary_ids(NULL))
 #undef INSTR_PROF_RAW_HEADER
 /* INSTR_PROF_RAW_HEADER  end */
 
@@ -646,7 +646,7 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
 (uint64_t)'f' << 16 | (uint64_t)'R' << 8 | (uint64_t)129
 
 /* Raw profile format version (start from 1). */
-#define INSTR_PROF_RAW_VERSION 6
+#define INSTR_PROF_RAW_VERSION 7
 /* Indexed profile format version (start from 1). */
 #define INSTR_PROF_INDEX_VERSION 7
 /* Coverage mapping format version (start from 0). */

diff  --git a/compiler-rt/lib/profile/InstrProfilingBuffer.c 
b/compiler-rt/lib/profile/InstrProfilingBuffer.c
index 21fa7ba1ddd6..68b4f5cd6f52 100644
--- a/compiler-rt/lib/profile/InstrProfilingBuffer.c
+++ b/compiler-rt/lib/profile/InstrProfilingBuffer.c
@@ -116,7 +116,7 @@ uint64_t __llvm_profile_get_size_for_buffer_internal(
   DataSize, CountersSize, NamesSize, &PaddingBytesBeforeCounters,
   &PaddingBytesAfterCounters, &PaddingBytesAfterNames);
 
-  return sizeof(__llvm_profile_header) +
+  return sizeof(__llvm_profile_header) + __llvm_write_binary_ids(NULL) +
  (DataSize * sizeof(__llvm_profile_data)) + PaddingBytesBeforeCounters 
+
  (CountersSize * sizeof(uint64_t)) + PaddingBytesAfterCounters +
  NamesSize + PaddingBytesAfterNames;

diff  --git a/compiler-rt/lib/profile/InstrProfilingMerge.c 
b/compiler-rt/lib/profile/InstrProfilingMerge.c
index 913228513259..16ebc2f8b2a9 100644
--- a/compiler-rt/lib/profile/InstrProfilingMerge.c
+++ b/compiler-rt/lib/profile/InstrProfilingMerge.c
@@ -22,6 +22,7 @@ void (*VPMergeHook)(ValueProfData *, __llvm_profile_data *);
 COMPILER_RT_VISIBILITY
 uint64_t lprofGetLoadModuleSignature() {
   /* A very fast way to compute a module signature.  */
+  uint64_t Version = __llvm_profile_get_version();
   uint64_t CounterSize = (uint64_t)(__llvm_profile_end_counters() -
 __llvm_profile_begin_counters());
   uint64_t DataSize = __llvm_profile_ge

[llvm-branch-commits] [llvm] aac4fe3 - [ELF] Don't emit SHF_GNU_RETAIN on Solaris

2021-08-12 Thread Tom Stellard via llvm-branch-commits

Author: Rainer Orth
Date: 2021-08-12T22:51:57-07:00
New Revision: aac4fe380d16a957627af2d6e5110ee35ad7e7e7

URL: 
https://github.com/llvm/llvm-project/commit/aac4fe380d16a957627af2d6e5110ee35ad7e7e7
DIFF: 
https://github.com/llvm/llvm-project/commit/aac4fe380d16a957627af2d6e5110ee35ad7e7e7.diff

LOG: [ELF] Don't emit SHF_GNU_RETAIN on Solaris

The introduction of `SHF_GNU_RETAIN` has caused massive problems on Solaris.

Initially, as reported in Bug 49437, it caused dozens of testsuite failures
on both sparc and x86.  The objects were marked as `ELFOSABI_NONE`, but
`SHF_GNU_RETAIN` is a GNU extension. In the native Solaris ABI, that flag
(in the range for OS-specific values) is `SHF_SUNW_ABSENT` with a
completely different semantics, which confuses Solaris `ld` very much.

Later, the objects became (correctly) marked `ELFOSABI_GNU`, which Solaris
`ld` doesn't support, causing it to SEGV and break the build.  The linker
is currently being hardened to not accept non-native OS ABIs to avoid this.

The need for linker support is already documented in
`clang/include/clang/Basic/AttrDocs.td`, but not currently checked.

This patch avoids all this by not emitting `SHF_GNU_RETAIN` on Solaris at all.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and
`x86_64-pc-linux-gnu`.

Differential Revision: https://reviews.llvm.org/D107747

(cherry picked from commit 7bbbf2956181f375ab193321b37ea71c5fc44054)

Added: 


Modified: 
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Removed: 




diff  --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp 
b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index add34eccc1f3..de096f95afcb 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -677,8 +677,9 @@ calcUniqueIDUpdateFlagsAndSize(const GlobalObject *GO, 
StringRef SectionName,
   }
 
   if (Retain) {
-if (Ctx.getAsmInfo()->useIntegratedAssembler() ||
-Ctx.getAsmInfo()->binutilsIsAtLeast(2, 36))
+if ((Ctx.getAsmInfo()->useIntegratedAssembler() ||
+ Ctx.getAsmInfo()->binutilsIsAtLeast(2, 36)) &&
+!TM.getTargetTriple().isOSSolaris())
   Flags |= ELF::SHF_GNU_RETAIN;
 return NextUniqueID++;
   }
@@ -855,8 +856,10 @@ static MCSection *selectELFSectionForGlobal(
 EmitUniqueSection = true;
 Flags |= ELF::SHF_LINK_ORDER;
   }
-  if (Retain && (Ctx.getAsmInfo()->useIntegratedAssembler() ||
- Ctx.getAsmInfo()->binutilsIsAtLeast(2, 36))) {
+  if (Retain &&
+  (Ctx.getAsmInfo()->useIntegratedAssembler() ||
+   Ctx.getAsmInfo()->binutilsIsAtLeast(2, 36)) &&
+  !TM.getTargetTriple().isOSSolaris()) {
 EmitUniqueSection = true;
 Flags |= ELF::SHF_GNU_RETAIN;
   }



___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits