diff --git a/lib/Input/Input.cpp b/lib/Input/Input.cpp index 98d0714a7..2fd57e557 100644 --- a/lib/Input/Input.cpp +++ b/lib/Input/Input.cpp @@ -69,6 +69,8 @@ bool Input::resolvePathMappingFile(const LinkerConfig &PConfig) { Input::getMemoryAreaForPath(FileName, PConfig.getDiagEngine()); if (!InputMem) InputMem = createMemoryArea(FileName, PConfig.getDiagEngine()); + if (!InputMem) + return false; // File does not exist; setMemArea(InputMem); // All queries to return the name of the Input return FileName for the main // driver. diff --git a/test/Common/standalone/EmptyInputFile/EmptyInputFile.test b/test/Common/standalone/EmptyInputFile/EmptyInputFile.test new file mode 100644 index 000000000..10257328d --- /dev/null +++ b/test/Common/standalone/EmptyInputFile/EmptyInputFile.test @@ -0,0 +1,17 @@ +#---EmptyInputFile.test----------- Executable -----------------# +#BEGIN_COMMENT +# Verify that ELD handles empty input files gracefully for: +# 1. Direct empty object file +# 2. Archive containing empty member +# 3. Thin archive containing empty member +#END_COMMENT +#START_TEST +RUN: %clang %clangopts -o %t1.o %p/Inputs/1.c -c +RUN: %touch %t1.empty.o +RUN: %ar rcs %t1.a %t1.o %t1.empty.o +RUN: %ar rcsT %t1.thin.a %t1.o %t1.empty.o +RUN: %link %emulation %linkopts %t1.empty.o 2>&1 | %filecheck %s --check-prefix=EMPTY --allow-empty +RUN: %link %emulation %linkopts %t1.a 2>&1 +RUN: %link %emulation %linkopts %t1.thin.a 2>&1 +#END_TEST +EMPTY: Input file {{.*}} has no contents diff --git a/test/Common/standalone/EmptyInputFile/Inputs/1.c b/test/Common/standalone/EmptyInputFile/Inputs/1.c new file mode 100644 index 000000000..76e819701 --- /dev/null +++ b/test/Common/standalone/EmptyInputFile/Inputs/1.c @@ -0,0 +1 @@ +int main() { return 0; } diff --git a/test/Common/standalone/EmptyInputFile/Inputs/script.t b/test/Common/standalone/EmptyInputFile/Inputs/script.t new file mode 100644 index 000000000..426e5d038 --- /dev/null +++ b/test/Common/standalone/EmptyInputFile/Inputs/script.t @@ -0,0 +1 @@ +GROUP(empty.o) diff --git a/test/Common/standalone/MissingMappingFileInput/Inputs/main.c b/test/Common/standalone/MissingMappingFileInput/Inputs/main.c new file mode 100644 index 000000000..76e819701 --- /dev/null +++ b/test/Common/standalone/MissingMappingFileInput/Inputs/main.c @@ -0,0 +1 @@ +int main() { return 0; } diff --git a/test/Common/standalone/MissingMappingFileInput/Inputs/mapping_missing.ini b/test/Common/standalone/MissingMappingFileInput/Inputs/mapping_missing.ini new file mode 100644 index 000000000..e8db69c99 --- /dev/null +++ b/test/Common/standalone/MissingMappingFileInput/Inputs/mapping_missing.ini @@ -0,0 +1,2 @@ +[Hash] +missing.t=DOESNOTEXIST diff --git a/test/Common/standalone/MissingMappingFileInput/Inputs/missing.t b/test/Common/standalone/MissingMappingFileInput/Inputs/missing.t new file mode 100644 index 000000000..9f44acdb1 --- /dev/null +++ b/test/Common/standalone/MissingMappingFileInput/Inputs/missing.t @@ -0,0 +1 @@ +GROUP(/lib64/libmissing.so) diff --git a/test/Common/standalone/MissingMappingFileInput/MissingMappingFileInput.test b/test/Common/standalone/MissingMappingFileInput/MissingMappingFileInput.test new file mode 100644 index 000000000..f30889cf1 --- /dev/null +++ b/test/Common/standalone/MissingMappingFileInput/MissingMappingFileInput.test @@ -0,0 +1,14 @@ +#---MissingMappingFileInput.test----------- Executable -----------------# +#BEGIN_COMMENT +# Verify that ELD handles gracefully when --mapping-file maps an input +# to a file that does not exist on disk. +# ELD should report a fatal error instead of crashing with a segfault. +#END_COMMENT +#START_TEST +RUN: %clang %clangopts -c %p/Inputs/main.c -o %t1.o +RUN: %not %link %linkopts %t1.o \ +RUN: -T %p/Inputs/missing.t \ +RUN: --mapping-file=%p/Inputs/mapping_missing.ini \ +RUN: 2>&1 | %filecheck %s +#END_TEST +CHECK: cannot read file