Skip to content

Commit a40cba3

Browse files
authored
Merge pull request #14 from dpaoliello/sync
Sync to LLVM 18.1.3
2 parents c632d0c + bedca5c commit a40cba3

21 files changed

+2456
-425
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ jobs:
77
name: test
88
runs-on: ubuntu-latest
99
timeout-minutes: 10
10+
env:
11+
RUSTFLAGS: -Dwarnings
12+
RUST_BACKTRACE: full
1013
steps:
1114
- uses: actions/checkout@v3
15+
- name: Clippy
16+
run: |
17+
cargo clippy -- -Dwarnings
1218
- name: Test
1319
run: |
1420
cargo test

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ar_archive_writer"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
edition = "2021"
55
license = "Apache-2.0 WITH LLVM-exception"
66
description = "A writer for object file ar archives"
@@ -11,9 +11,9 @@ repository = "https://github.com/rust-lang/ar_archive_writer"
1111
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1212

1313
[dependencies]
14-
object = { version = "0.32.0", default-features = false, features = ["std", "read"] }
14+
object = { version = "0.35.0", default-features = false, features = ["std", "read"] }
1515

1616
[dev-dependencies]
1717
cargo-binutils = "0.3.6"
18-
object = { version = "0.32.0", default-features = false, features = ["write", "xcoff"] }
18+
object = { version = "0.35.0", default-features = false, features = ["write", "xcoff"] }
1919
pretty_assertions = "1.4.0"

Readme.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# A writer for object file ar archives
22

3-
This is a Rust port of LLVM's archive writer (`ArchiveWriter.cpp`):
4-
* Based on commit [8ef3e895a](https://github.com/llvm/llvm-project/tree/3d3ef9d073e1e27ea57480b371b7f5a9f5642ed2) (15.0.0-rc3).
5-
* With the following options removed:
6-
* Deterministic: always enabled.
7-
* Symbol tables: always enabled.
3+
This is a Rust port of LLVM's archive writer (see [the LLVM Reference](reference/Readme.md)
4+
for details) with the following options removed:
5+
* Deterministic: always enabled.
6+
* Symbol tables: always enabled.
87

98
## License
109

src/Alignment.h renamed to reference/Alignment.h

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Copied from https://github.com/llvm/llvm-project/blob/3d3ef9d073e1e27ea57480b371b7f5a9f5642ed2/llvm/include/llvm/Support/Alignment.h
2-
31
//===-- llvm/Support/Alignment.h - Useful alignment functions ---*- C++ -*-===//
42
//
53
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -23,9 +21,9 @@
2321
#ifndef LLVM_SUPPORT_ALIGNMENT_H_
2422
#define LLVM_SUPPORT_ALIGNMENT_H_
2523

26-
#include "llvm/ADT/Optional.h"
2724
#include "llvm/Support/MathExtras.h"
2825
#include <cassert>
26+
#include <optional>
2927
#ifndef NDEBUG
3028
#include <string>
3129
#endif // NDEBUG
@@ -95,14 +93,14 @@ struct Align {
9593
}
9694

9795
/// Allow constructions of constexpr Align.
98-
template <size_t kValue> constexpr static LogValue Constant() {
96+
template <size_t kValue> constexpr static Align Constant() {
9997
return LogValue{static_cast<uint8_t>(CTLog2<kValue>())};
10098
}
10199

102100
/// Allow constructions of constexpr Align from types.
103101
/// Compile time equivalent to Align(alignof(T)).
104-
template <typename T> constexpr static LogValue Of() {
105-
return Constant<std::alignment_of<T>::value>();
102+
template <typename T> constexpr static Align Of() {
103+
return Constant<std::alignment_of_v<T>>();
106104
}
107105

108106
/// Constexpr constructor from LogValue type.
@@ -116,9 +114,9 @@ inline Align assumeAligned(uint64_t Value) {
116114

117115
/// This struct is a compact representation of a valid (power of two) or
118116
/// undefined (0) alignment.
119-
struct MaybeAlign : public llvm::Optional<Align> {
117+
struct MaybeAlign : public std::optional<Align> {
120118
private:
121-
using UP = llvm::Optional<Align>;
119+
using UP = std::optional<Align>;
122120

123121
public:
124122
/// Default is undefined.
@@ -130,9 +128,8 @@ struct MaybeAlign : public llvm::Optional<Align> {
130128
MaybeAlign(MaybeAlign &&Other) = default;
131129
MaybeAlign &operator=(MaybeAlign &&Other) = default;
132130

133-
/// Use llvm::Optional<Align> constructor.
134-
using UP::UP;
135-
131+
constexpr MaybeAlign(std::nullopt_t None) : UP(None) {}
132+
constexpr MaybeAlign(Align Value) : UP(Value) {}
136133
explicit MaybeAlign(uint64_t Value) {
137134
assert((Value == 0 || llvm::isPowerOf2_64(Value)) &&
138135
"Alignment is neither 0 nor a power of 2");
@@ -294,6 +291,22 @@ bool operator>=(MaybeAlign Lhs, MaybeAlign Rhs) = delete;
294291
bool operator<(MaybeAlign Lhs, MaybeAlign Rhs) = delete;
295292
bool operator>(MaybeAlign Lhs, MaybeAlign Rhs) = delete;
296293

294+
// Allow equality comparisons between Align and MaybeAlign.
295+
inline bool operator==(MaybeAlign Lhs, Align Rhs) { return Lhs && *Lhs == Rhs; }
296+
inline bool operator!=(MaybeAlign Lhs, Align Rhs) { return !(Lhs == Rhs); }
297+
inline bool operator==(Align Lhs, MaybeAlign Rhs) { return Rhs == Lhs; }
298+
inline bool operator!=(Align Lhs, MaybeAlign Rhs) { return !(Rhs == Lhs); }
299+
// Allow equality comparisons with MaybeAlign.
300+
inline bool operator==(MaybeAlign Lhs, MaybeAlign Rhs) {
301+
return (Lhs && Rhs && (*Lhs == *Rhs)) || (!Lhs && !Rhs);
302+
}
303+
inline bool operator!=(MaybeAlign Lhs, MaybeAlign Rhs) { return !(Lhs == Rhs); }
304+
// Allow equality comparisons with std::nullopt.
305+
inline bool operator==(MaybeAlign Lhs, std::nullopt_t) { return !bool(Lhs); }
306+
inline bool operator!=(MaybeAlign Lhs, std::nullopt_t) { return bool(Lhs); }
307+
inline bool operator==(std::nullopt_t, MaybeAlign Rhs) { return !bool(Rhs); }
308+
inline bool operator!=(std::nullopt_t, MaybeAlign Rhs) { return bool(Rhs); }
309+
297310
#ifndef NDEBUG
298311
// For usage in LLVM_DEBUG macros.
299312
inline std::string DebugStr(const Align &A) {
@@ -311,4 +324,4 @@ inline std::string DebugStr(const MaybeAlign &MA) {
311324

312325
} // namespace llvm
313326

314-
#endif // LLVM_SUPPORT_ALIGNMENT_H_
327+
#endif // LLVM_SUPPORT_ALIGNMENT_H_

src/Archive.h renamed to reference/Archive.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Copied from https://github.com/llvm/llvm-project/blob/3d3ef9d073e1e27ea57480b371b7f5a9f5642ed2/llvm/include/llvm/Object/Archive.h
2-
31
//===- Archive.h - ar archive file format -----------------------*- C++ -*-===//
42
//
53
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -30,9 +28,6 @@
3028
#include <vector>
3129

3230
namespace llvm {
33-
34-
template <typename T> class Optional;
35-
3631
namespace object {
3732

3833
const char ArchiveMagic[] = "!<arch>\n";
@@ -307,6 +302,7 @@ class Archive : public Binary {
307302
StringRef getName() const;
308303
Expected<Child> getMember() const;
309304
Symbol getNext() const;
305+
bool isECSymbol() const;
310306
};
311307

312308
class symbol_iterator {
@@ -357,16 +353,19 @@ class Archive : public Binary {
357353
return make_range(symbol_begin(), symbol_end());
358354
}
359355

356+
Expected<iterator_range<symbol_iterator>> ec_symbols() const;
357+
360358
static bool classof(Binary const *v) { return v->isArchive(); }
361359

362360
// check if a symbol is in the archive
363-
Expected<Optional<Child>> findSym(StringRef name) const;
361+
Expected<std::optional<Child>> findSym(StringRef name) const;
364362

365363
virtual bool isEmpty() const;
366364
bool hasSymbolTable() const;
367365
StringRef getSymbolTable() const { return SymbolTable; }
368366
StringRef getStringTable() const { return StringTable; }
369367
uint32_t getNumberOfSymbols() const;
368+
uint32_t getNumberOfECSymbols() const;
370369
virtual uint64_t getFirstChildOffset() const { return getArchiveMagicLen(); }
371370

372371
std::vector<std::unique_ptr<MemoryBuffer>> takeThinBuffers() {
@@ -382,6 +381,7 @@ class Archive : public Binary {
382381
void setFirstRegular(const Child &C);
383382

384383
StringRef SymbolTable;
384+
StringRef ECSymbolTable;
385385
StringRef StringTable;
386386

387387
private:
@@ -410,17 +410,21 @@ class BigArchive : public Archive {
410410
const FixLenHdr *ArFixLenHdr;
411411
uint64_t FirstChildOffset = 0;
412412
uint64_t LastChildOffset = 0;
413+
std::string MergedGlobalSymtabBuf;
414+
bool Has32BitGlobalSymtab = false;
415+
bool Has64BitGlobalSymtab = false;
413416

414417
public:
415418
BigArchive(MemoryBufferRef Source, Error &Err);
416419
uint64_t getFirstChildOffset() const override { return FirstChildOffset; }
417420
uint64_t getLastChildOffset() const { return LastChildOffset; }
418-
bool isEmpty() const override {
419-
return Data.getBufferSize() == sizeof(FixLenHdr);
420-
};
421+
bool isEmpty() const override { return getFirstChildOffset() == 0; }
422+
423+
bool has32BitGlobalSymtab() { return Has32BitGlobalSymtab; }
424+
bool has64BitGlobalSymtab() { return Has64BitGlobalSymtab; }
421425
};
422426

423427
} // end namespace object
424428
} // end namespace llvm
425429

426-
#endif // LLVM_OBJECT_ARCHIVE_H
430+
#endif // LLVM_OBJECT_ARCHIVE_H

0 commit comments

Comments
 (0)