arXiv:2610.22952cs.SEOct 2026

Manuscript Offprint

arXiv:2610.22952

MergeShuffle: Reconstruct Shared Libraries for Improved Performance and Security

Huaifeng Zhang, Ahmed Ali-Eldin

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Huaifeng Zhang

Chalmers University of Technology

Gothenburg, Sweden

huaifeng@chalmer.se

Ahmed Ali-Eldin

Chalmers University of Technology

Gothenburg, Sweden

ahmed.hassan@chalmers.se

Abstract—Debloating shared libraries has been an active research topic for years. Tools for shared library debloating rely on either static or dynamic analysis techniques to discover which parts of the shared library is used. Once these parts are found, these tools take one of two routes, either removing parts of the library that are not used, requiring reconstruction of the library; or they simply overwriting the unused functions. However, recently a broad study [13] on debloating tools has shown that some of these tools either increase the static binary size, or are generally less effective for complex workloads.

In this paper, we argue that shared-library debloaters' performance can be improved by proper reconstruction of the shared-libraries once the used functions in the library are identifies. We propose MERGESHUFFLE, a novel tool for reconstructing shared libraries from a given set of file ranges to eliminate unused code based on user-specified requirements, without requiring access to source code. MERGESHUFFLE takes as input a shared library and a set of file ranges to retain, and performs a two-phase reconstruction: merging nearby ranges to reduce loading overhead, and shuffling them to minimize file size while preserving page-aligned memory mappings. The shuffling problem is formulated as a variant of the Traveling Salesman Problem and solved using a heuristic algorithm. MERGESHUFFLE utilizes program headers to remap retained code to its original memory addresses, preserving user-specified functionality. Our results show that MERGESHUFFLE achieves up to 60% reduction in file size, 16% reduction in memory usage, and 32% reduction in runtime, while maintaining user-specified functionality and improving security.

Index Terms—Shared Libraries, Software Debloating, Software Optimization, Software Security, Cold Start Performance

I. INTRODUCTION

Modern software engineering relies on software reuse [31]. At each phase, new components—code, dependencies, and resources—are introduced, while the removal of unused or obsolete elements is rarely prioritized [40]. Generally, during development, features are continuously added, sometimes leading to feature creep [18]. In the build phase, the source code is compiled and often linked with numerous third-party libraries [19]. Finally, during deployment, applications are frequently containerized, bundling all dependencies and assets, regardless of whether they are necessary [46], [47].

This pervasive addition leads to software bloat: the inclusion of unused code, features, and resources [22]. Bloated software consumes excessive disk space and memory and increases the system's attack surface, potentially introducing security vulnerabilities [34], [46]. The problem is particularly acute for shared libraries. Shared libraries are designed to accelerate application development by offering reusable components [21]. Any bloat or vulnerability in a library propagates to all applications that depend on it [42]. Moreover, a fundamental gap exists between library developers and library users: developers aim to maximize adoption by incorporating many features, while individual library users typically require only a small subset of features. This gap has further widened with the advent of micro-services and serverless computing. Services are increasingly modular, narrow, and task-specific, yet they often rely on large, general-purpose shared libraries that are not tailored to their precise needs [16], [27], leading to significant inefficiencies, especially during cold start scenarios [43].

Shared libraries — which are the most common form of third-party libraries — suffer significantly from this gap due to their widespread use in both operating systems and applications [9], [38], [48]. For instance, Quach et al. report that on Ubuntu Desktop, only about 5% of the GNU C standard library (glibc) is used on average by the programs depending on it. Even the heaviest user of glibc in their survey (the VLC media player) invoked merely 18% of the library's code [38]. These rarely used features not only bloat the shared library but also increase the attack surface, making it more vulnerable to exploits [8]. For example, the Heartbleed vulnerability in OpenSSL was caused by a bug in a rarely-used TLS heartbeat feature – an optional extension that most users did not need, yet it was present in all builds and became a critical exploit vector [15]. Furthermore, malicious code can be injected into shared libraries through supply chain attacks, as was recently demonstrated by the XZ backdoor incident [6].

Despite ubiquity of shared libraries in modern software ecosystems, there exists limited support for tailoring them to the specific needs of individual users. This challenge has attracted attention from both academia and industry. From academia, several software debloating tools have been proposed for shared libraries [9], [38], [48]. However, a recent study shows that these tools have many limitations [13]. They either fail to produce functionally correct libraries, require access to source code, or result in negligible—sometimes even negative—performance improvements. From industry, the Rust programming language offers a feature-based dependency management system, where users explicitly declare required features, and only those are included at build time [3]. While effective, this strategy is not applicable to existing precompiled shared libraries.

In this paper, we argue that while discovering which parts of a shared library is used can be done using techniques such as dynamic analysis, it is challenging to reconstruct a working version of the shared library that reduces the size efficiently, and works robustly. To address these limitations, we present MERGESHUFFLE, a tool that customizes shared libraries according to user-specific needs—without requiring access to source code or modifications to system components. MERGESHUFFLE can be integrated with any tool for finding the used parts of a shared library, e.g., via dynamic tracing, runtime instrumentation for production workloads, or static analysis. These identified code regions are specified as file ranges, which serve as input to MERGESHUFFLE. Given this input, MERGESHUFFLE removes unused code, reorganizes the file layout, and produces a shared library fully compatible with existing systems. To minimize file size and memory overhead, MERGESHUFFLE formulates the reorganization of file ranges as a variant of the classic Traveling Salesman Problem (TSP) and applies a heuristic algorithm to find an approximately optimal layout. It then updates program headers to ensure that only the required code regions are mapped into correct memory addresses at runtime. Contrary to common belief that eliminating unused code yields negligible performance benefits—since such code is not executed [13], we show that MERGESHUFFLE delivers substantial improvements across all four key metrics: reducing the shared library file size, memory usage, runtime overhead for cold starts, and enhancing security. In summary, our contributions are as follows; (1) We present MERGESHUFFLE, a novel tool for reconstructing shared libraries to retain user-required functionalities, without access to source code or modifications to system components; (2) We demonstrate that MERGESHUFFLE achieves significant improvements, reducing shared library size by up to 60%, lowering memory usage by up to 16%, and decreasing run time by up to 32%, all while preserving functional correctness and enhancing security; (3) We open-source MERGESHUFFLE. 1^{1}

References (36)