From 1ac1afd3dc62b7d6f292dd1f9b142f1ef552b391 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Fri, 23 Jul 2021 12:09:32 -0400 Subject: [PATCH] extractor, utils: dedupe bitcode paths before linking --- shared/extractor.go | 3 +++ shared/utils.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/shared/extractor.go b/shared/extractor.go index 27ac672..adbf743 100644 --- a/shared/extractor.go +++ b/shared/extractor.go @@ -286,6 +286,9 @@ func handleExecutable(ea ExtractionArgs) (success bool) { sort.Strings(artifactPaths) } + // Deduplicate any files to link + dedupeStrings(&filesToLink) + // Write manifest if ea.WriteManifest { if !writeManifest(ea, filesToLink, artifactPaths) { diff --git a/shared/utils.go b/shared/utils.go index db2b56f..585bdc8 100644 --- a/shared/utils.go +++ b/shared/utils.go @@ -75,3 +75,17 @@ func runCmd(cmdExecName string, args []string) (output string, err error) { output = outb.String() return } + +// Deduplicate a potentially unsorted list of strings in-place without changing their order +func dedupeStrings(strings *[]string) { + seen := make(map[string]bool) + count := 0 + for _, s := range *strings { + if _, exists := seen[s]; !exists { + seen[s] = true + (*strings)[count] = s + count++ + } + } + *strings = (*strings)[:count] +}