clang 24.0.0git
StaticLibrary.h
Go to the documentation of this file.
1//===- StaticLibrary.h ------------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the StaticLibrary class, which represents a static
10// library of translation unit summary encodings (the SSAF analogue of an
11// ar / libtool -static / lib.exe output).
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_SCALABLESTATICANALYSIS_CORE_ENTITYLINKER_STATICLIBRARY_H
16#define LLVM_CLANG_SCALABLESTATICANALYSIS_CORE_ENTITYLINKER_STATICLIBRARY_H
17
20#include "llvm/TargetParser/Triple.h"
21#include <memory>
22#include <set>
23
24namespace clang::ssaf {
25
26class LinkCLI;
27class MultiArchCreateCLI;
28class StaticLibraryCreateCLI;
29
30/// Represents a static library of translation unit summary encodings.
31///
32/// A StaticLibrary bundles member translation units without performing
33/// entity resolution, mirroring the role of ar / libtool -static / lib.exe
34/// in native build pipelines. It is consumed by the EntityLinker when passed
35/// as a command line argument.
36///
37/// Static libraries are single-architecture: every member's target triple
38/// must equal the library's. Multi-architecture static libraries are
39/// expressed as a fat wrapper around per-architecture StaticLibrary
40/// instances rather than as a single mixed-architecture library.
41///
42/// Members are stored as encoded TUSummaryEncoding objects: the
43/// static-library tool never decodes per-entity payloads, and the linker
44/// consumes them as-is while folding them into its link unit.
45///
46/// TODO: The linker currently folds in every member. Restrict inclusion to
47/// the members a link unit actually references, as native linkers do.
49 friend class EntityLinker;
50 friend class LinkCLI;
51 friend class MultiArchCreateCLI;
53 friend class SerializationFormat;
55 friend class TestFixture;
56
57 /// Orders members by their TUNamespace. As a nested struct of
58 /// StaticLibrary, it inherits StaticLibrary's friend access to
59 /// TUSummaryEncoding's private fields.
60 struct MemberByNamespace {
61 bool operator()(const std::unique_ptr<TUSummaryEncoding> &A,
62 const std::unique_ptr<TUSummaryEncoding> &B) const {
63 return A->TUNamespace < B->TUNamespace;
64 }
65 };
66
67 // Target triple of the static library. All member TUs must share this
68 // triple.
69 llvm::Triple TargetTriple;
70
71 // The namespace identifying this static library (kind=StaticLibrary).
72 BuildNamespace Namespace;
73
74 // Member translation units, ordered by their TUNamespace. Membership is
75 // by namespace identity: inserting a TU whose TUNamespace already exists
76 // in the set is rejected during deserialization.
77 std::set<std::unique_ptr<TUSummaryEncoding>, MemberByNamespace> Members;
78
79public:
80 StaticLibrary(llvm::Triple TargetTriple, BuildNamespace Namespace)
81 : TargetTriple(std::move(TargetTriple)), Namespace(std::move(Namespace)) {
82 }
83};
84
85} // namespace clang::ssaf
86
87#endif // LLVM_CLANG_SCALABLESTATICANALYSIS_CORE_ENTITYLINKER_STATICLIBRARY_H
Represents a single namespace in the build process.
StaticLibrary(llvm::Triple TargetTriple, BuildNamespace Namespace)
friend class MultiArchStaticLibrary
friend class StaticLibraryCreateCLI