Skip to content

[Input] Fix segfault when sysroot file is missing during reproduce tarball replay#1305

Open
Deepak Shirke (deepakshirkem) wants to merge 1 commit into
qualcomm:mainfrom
deepakshirkem:fix/sysroot-script-crash-818
Open

[Input] Fix segfault when sysroot file is missing during reproduce tarball replay#1305
Deepak Shirke (deepakshirkem) wants to merge 1 commit into
qualcomm:mainfrom
deepakshirkem:fix/sysroot-script-crash-818

Conversation

@deepakshirkem

@deepakshirkem Deepak Shirke (deepakshirkem) commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

ELD crashes with a segfault when replaying a reproduce tarball where a file referenced by a linker script is missing from the tarball or the mapping.ini contains an incorrect mapping pointing to a non-existent file.

The root cause is that Input::resolvePathMappingFile() calls createMemoryArea(), which returns nullptr when the file does not exist. However, the function still calls setMemArea(nullptr) and returns true, allowing a null MemArea to propagate downstream. This eventually reaches readAndProcessInput(), where it is dereferenced
by ScriptLexer, resulting in a crash.

A new test MissingMappingFileInput has been added to reproduce and verify the fix.

Fixes #1335
Related to #818
cc quic-areg Parth (@parth-07) Shankar Easwaran (@quic-seaswara)

@deepakshirkem Deepak Shirke (deepakshirkem) changed the title Input: fix null dereference in resolvePathMappingFile when mapped fil… [Input] Fix segfault when sysroot file is missing during reproduce tarball replay Jun 19, 2026

@parth-07 Parth (parth-07) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why is the PR modifying an already exiting test and how is it fixing anything by not modifying the source-code at all.

@deepakshirkem

Copy link
Copy Markdown
Contributor Author

Hi Parth (@parth-07), The PR has been update. It now includes the fix in Input.cpp and a correct test. Please review when you get a chance!

@deepakshirkem

Copy link
Copy Markdown
Contributor Author

Parth (@parth-07) ping.

RUN: %tar %gnutaropts -xvf %t.tar -C %t.reproduce --strip-components=1
RUN: rm -rf %t.reproduce/SharedLibrary
RUN: rm -rf %t.dir/lib64/lib1.so
RUN: cd %t.reproduce && %not %link --no-threads @%t.response 2>&1 | %filecheck %s

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need --no-threads here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need --no-threads here?

was used to match the original link command in the reproduce tarball's response.txt will update the test to use %link with %linkopts instead,

@@ -0,0 +1,26 @@
#UNSUPPORTED: windows, reproduce_fail

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this test unsupported for windows and reproduce_fail?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After checking existing reproduce tests (Reproduce.test, ArchiveFile.test, Namespec.test), all use the same #UNSUPPORTED: windows, reproduce_fail pattern since our test uses --reproduce flag and Unix-specific commands, so this is correct.

RUN: %tar %gnutaropts -xvf %t.tar -C %t.reproduce --strip-components=1
RUN: rm -rf %t.reproduce/SharedLibrary
RUN: rm -rf %t.dir/lib64/lib1.so
RUN: cd %t.reproduce && %not %link --no-threads @%t.response 2>&1 | %filecheck %s

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix for #818 is not avoiding the crash and reporting an error message. It should instead be making reproducer work correctly for the case when the shared library should be found under the sysroot.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this makes sense to me. Thank-You

Comment thread lib/Input/Input.cpp
if (!InputMem)
InputMem = createMemoryArea(FileName, PConfig.getDiagEngine());
if (!InputMem)
return false; // File does not exist;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix is correct for the case when the reproduce tarball is tampered, but it is a wrong fix for #818. In the issue, there is no tampering of the reproduce tarball. The core issue is not that the linker is crashing, but that the linker is incorrectly handling the sysroot during reproduce tarball.

Can you create a separate issue for the link crashing when the files has been removed from the reproduce tarball/setup (or when the mapping.ini file contains incorrect mapping) and then link this PR with that issue?

…e does not exist

When replaying a reproduce tarball, ELD crashes with a segfault if a
linker script references a file that is not present in the sysroot.

The crash occurs in Input::resolvePathMappingFile() where
createMemoryArea() returns nullptr when the file does not exist, but
the function continues to call setMemArea(nullptr) and returns true,
incorrectly signaling success to the caller. This allows a null MemArea
Input to reach readAndProcessInput(), which eventually dereferences the
null pointer inside ScriptLexer causing a segfault.

Fixes qualcomm#1335

Signed-off-by: deepakshirkem <deepakshirke509@gmail.com>
@deepakshirkem

Deepak Shirke (deepakshirkem) commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Parth (@parth-07) Please review one more time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ELD crashes when input file is missing from reproduce tarball or mapping file contains incorrect mapping

2 participants