[ELF] initializeSections: move SHT_LLVM_CALL_GRAPH_PROFILE check into SHF_EXCLUDE...
authorFangrui Song <i@maskray.me>
Mon, 13 Dec 2021 04:05:21 +0000 (20:05 -0800)
committerFangrui Song <i@maskray.me>
Mon, 13 Dec 2021 04:05:21 +0000 (20:05 -0800)
Avoid a comparison in the majority of cases.

lld/ELF/InputFiles.cpp

index 12ff5f1..90a4eb0 100644 (file)
@@ -555,13 +555,12 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats) {
       continue;
     const Elf_Shdr &sec = objSections[i];
 
-    if (sec.sh_type == ELF::SHT_LLVM_CALL_GRAPH_PROFILE)
-      cgProfileSectionIndex = i;
-
     // SHF_EXCLUDE'ed sections are discarded by the linker. However,
     // if -r is given, we'll let the final link discard such sections.
     // This is compatible with GNU.
     if ((sec.sh_flags & SHF_EXCLUDE) && !config->relocatable) {
+      if (sec.sh_type == SHT_LLVM_CALL_GRAPH_PROFILE)
+        cgProfileSectionIndex = i;
       if (sec.sh_type == SHT_LLVM_ADDRSIG) {
         // We ignore the address-significance table if we know that the object
         // file was created by objcopy or ld -r. This is because these tools