[COFF] Don't emit .gfids sections when CFG is off
authorReid Kleckner <rnk@google.com>
Wed, 24 Apr 2019 20:38:37 +0000 (20:38 +0000)
committerReid Kleckner <rnk@google.com>
Wed, 24 Apr 2019 20:38:37 +0000 (20:38 +0000)
Put them on the list of GuardFidChunks instead of the main Chunks list,
even with CFG is off. It will be ignored if CFG is disabled.

llvm-svn: 359137

lld/COFF/InputFiles.cpp
lld/test/COFF/gfids-icf.s

index 2fa2f03..7de4c25 100644 (file)
@@ -208,9 +208,9 @@ SectionChunk *ObjFile::readSection(uint32_t SectionNumber,
   // linked in the regular manner.
   if (C->isCodeView())
     DebugChunks.push_back(C);
-  else if (Config->GuardCF != GuardCFLevel::Off && Name == ".gfids$y")
+  else if (Name == ".gfids$y")
     GuardFidChunks.push_back(C);
-  else if (Config->GuardCF != GuardCFLevel::Off && Name == ".gljmp$y")
+  else if (Name == ".gljmp$y")
     GuardLJmpChunks.push_back(C);
   else if (Name == ".sxdata")
     SXDataChunks.push_back(C);
index b0b4d70..5edbbc7 100644 (file)
 # CHECK-NEXT:   0x14000{{.*}}
 # CHECK-NEXT: ]
 
+# There should be no .gfids section in the output exectuable when we link with
+# -guard:cf or with no -guard:cf/nolongjmp flag.
+# RUN: llvm-readobj -sections %t.exe | FileCheck %s --check-prefix NOGFIDSEC
+# RUN: lld-link %t.obj -out:%t.exe -opt:icf -entry:main
+# RUN: llvm-readobj -sections %t.exe | FileCheck %s --check-prefix NOGFIDSEC
+
+# NOGFIDSEC: Sections [
+# NOGFIDSEC: Section {
+# NOGFIDSEC: Name: .text
+# NOGFIDSEC-NOT: Name: .gfids
 
 # Indicate that gfids are present.
         .def     @feat.00; .scl    3; .type   0; .endef