diff --git a/llvm/lib/ObjCopy/ConfigManager.cpp b/llvm/lib/ObjCopy/ConfigManager.cpp index 6b7b4f116f58..7424865a2e5e 100644 --- a/llvm/lib/ObjCopy/ConfigManager.cpp +++ b/llvm/lib/ObjCopy/ConfigManager.cpp @@ -28,9 +28,8 @@ Expected ConfigManager::getCOFFConfig() const { !Common.SymbolsToLocalize.empty() || !Common.SymbolsToWeaken.empty() || !Common.SymbolsToKeepGlobal.empty() || !Common.SectionsToRename.empty() || !Common.SetSectionAlignment.empty() || !Common.SetSectionType.empty() || - Common.ExtractDWO || Common.PreserveDates || Common.StripDWO || - Common.StripNonAlloc || Common.StripSections || Common.Weaken || - Common.DecompressDebugSections || + Common.ExtractDWO || Common.StripDWO || Common.StripNonAlloc || + Common.StripSections || Common.Weaken || Common.DecompressDebugSections || Common.DiscardMode == DiscardType::Locals || !Common.SymbolsToAdd.empty() || Common.GapFill != 0 || Common.PadTo != 0 || Common.ChangeSectionLMAValAll != 0 || diff --git a/llvm/test/tools/llvm-objcopy/COFF/strip-preserve-mtime.test b/llvm/test/tools/llvm-objcopy/COFF/strip-preserve-mtime.test new file mode 100644 index 000000000000..91be6b40edc1 --- /dev/null +++ b/llvm/test/tools/llvm-objcopy/COFF/strip-preserve-mtime.test @@ -0,0 +1,50 @@ +## Note: ls -l prints the modified timestamp. + +# RUN: yaml2obj %s -o %t.exe + +## Preserve dates when stripping to an output file. +# RUN: cp %t.exe %t.1.exe +# RUN: touch -m -t 199705050555.55 %t.1.exe +# RUN: llvm-strip -p %t.1.exe -o %t-preserved.1.exe +# RUN: ls -l %t-preserved.1.exe | FileCheck %s --check-prefix=CHECK-PRESERVE-MTIME +## Check that the stripped output is in fact a valid object file and the timestamp in the PE header is preserved. +# RUN: llvm-readobj --headers %t-preserved.1.exe | FileCheck %s + +## Preserve dates available via objcopy interface as well. +# RUN: cp %t.exe %t.2.exe +# RUN: touch -m -t 199705050555.55 %t.2.exe +# RUN: llvm-objcopy -p %t.2.exe %t-preserved.2.exe +# RUN: ls -l %t-preserved.2.exe | FileCheck %s --check-prefix=CHECK-PRESERVE-MTIME +# RUN: llvm-readobj --headers %t-preserved.2.exe | FileCheck %s + +## Preserve dates when stripping in place. +# RUN: cp %t.exe %t.3.exe +# RUN: touch -m -t 199705050555.55 %t.3.exe +# RUN: llvm-strip -p %t.3.exe +# RUN: ls -l %t.3.exe | FileCheck %s --check-prefix=CHECK-PRESERVE-MTIME +# RUN: llvm-readobj --headers %t.3.exe | FileCheck %s + +## Without -p set, don't preserve dates. +# RUN: cp %t.exe %t.4.exe +# RUN: touch -m -t 199705050555.55 %t.4.exe +# RUN: llvm-strip %t.4.exe +# RUN: ls -l %t.4.exe | FileCheck %s --check-prefix=CHECK-NO-PRESERVE-MTIME +# RUN: llvm-readobj --headers %t.4.exe | FileCheck %s + +## Always preserve the timestamp in the PE header. +# CHECK: TimeDateStamp: 1970-01-01 00:00:00 (0x0) + +# CHECK-PRESERVE-MTIME: {{[[:space:]]1997}} +# CHECK-NO-PRESERVE-MTIME-NOT: {{[[:space:]]1997}} + +!COFF +OptionalHeader: + Subsystem: IMAGE_SUBSYSTEM_WINDOWS_CUI +header: + Machine: IMAGE_FILE_MACHINE_AMD64 +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + VirtualSize: 20 +symbols: [] +...