Skip to content

Commit bedca5c

Browse files
committed
Sync to LLVM 18.1.3
1 parent 1185cf6 commit bedca5c

18 files changed

+2436
-406
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"

reference/Alignment.h

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
#ifndef LLVM_SUPPORT_ALIGNMENT_H_
2222
#define LLVM_SUPPORT_ALIGNMENT_H_
2323

24-
#include "llvm/ADT/Optional.h"
2524
#include "llvm/Support/MathExtras.h"
2625
#include <cassert>
26+
#include <optional>
2727
#ifndef NDEBUG
2828
#include <string>
2929
#endif // NDEBUG
@@ -93,14 +93,14 @@ struct Align {
9393
}
9494

9595
/// Allow constructions of constexpr Align.
96-
template <size_t kValue> constexpr static LogValue Constant() {
96+
template <size_t kValue> constexpr static Align Constant() {
9797
return LogValue{static_cast<uint8_t>(CTLog2<kValue>())};
9898
}
9999

100100
/// Allow constructions of constexpr Align from types.
101101
/// Compile time equivalent to Align(alignof(T)).
102-
template <typename T> constexpr static LogValue Of() {
103-
return Constant<std::alignment_of<T>::value>();
102+
template <typename T> constexpr static Align Of() {
103+
return Constant<std::alignment_of_v<T>>();
104104
}
105105

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

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

121121
public:
122122
/// Default is undefined.
@@ -128,9 +128,8 @@ struct MaybeAlign : public llvm::Optional<Align> {
128128
MaybeAlign(MaybeAlign &&Other) = default;
129129
MaybeAlign &operator=(MaybeAlign &&Other) = default;
130130

131-
/// Use llvm::Optional<Align> constructor.
132-
using UP::UP;
133-
131+
constexpr MaybeAlign(std::nullopt_t None) : UP(None) {}
132+
constexpr MaybeAlign(Align Value) : UP(Value) {}
134133
explicit MaybeAlign(uint64_t Value) {
135134
assert((Value == 0 || llvm::isPowerOf2_64(Value)) &&
136135
"Alignment is neither 0 nor a power of 2");
@@ -292,6 +291,22 @@ bool operator>=(MaybeAlign Lhs, MaybeAlign Rhs) = delete;
292291
bool operator<(MaybeAlign Lhs, MaybeAlign Rhs) = delete;
293292
bool operator>(MaybeAlign Lhs, MaybeAlign Rhs) = delete;
294293

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+
295310
#ifndef NDEBUG
296311
// For usage in LLVM_DEBUG macros.
297312
inline std::string DebugStr(const Align &A) {
@@ -309,4 +324,4 @@ inline std::string DebugStr(const MaybeAlign &MA) {
309324

310325
} // namespace llvm
311326

312-
#endif // LLVM_SUPPORT_ALIGNMENT_H_
327+
#endif // LLVM_SUPPORT_ALIGNMENT_H_

reference/Archive.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
#include <vector>
2929

3030
namespace llvm {
31-
32-
template <typename T> class Optional;
33-
3431
namespace object {
3532

3633
const char ArchiveMagic[] = "!<arch>\n";
@@ -305,6 +302,7 @@ class Archive : public Binary {
305302
StringRef getName() const;
306303
Expected<Child> getMember() const;
307304
Symbol getNext() const;
305+
bool isECSymbol() const;
308306
};
309307

310308
class symbol_iterator {
@@ -355,16 +353,19 @@ class Archive : public Binary {
355353
return make_range(symbol_begin(), symbol_end());
356354
}
357355

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

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

363363
virtual bool isEmpty() const;
364364
bool hasSymbolTable() const;
365365
StringRef getSymbolTable() const { return SymbolTable; }
366366
StringRef getStringTable() const { return StringTable; }
367367
uint32_t getNumberOfSymbols() const;
368+
uint32_t getNumberOfECSymbols() const;
368369
virtual uint64_t getFirstChildOffset() const { return getArchiveMagicLen(); }
369370

370371
std::vector<std::unique_ptr<MemoryBuffer>> takeThinBuffers() {
@@ -380,6 +381,7 @@ class Archive : public Binary {
380381
void setFirstRegular(const Child &C);
381382

382383
StringRef SymbolTable;
384+
StringRef ECSymbolTable;
383385
StringRef StringTable;
384386

385387
private:
@@ -408,17 +410,21 @@ class BigArchive : public Archive {
408410
const FixLenHdr *ArFixLenHdr;
409411
uint64_t FirstChildOffset = 0;
410412
uint64_t LastChildOffset = 0;
413+
std::string MergedGlobalSymtabBuf;
414+
bool Has32BitGlobalSymtab = false;
415+
bool Has64BitGlobalSymtab = false;
411416

412417
public:
413418
BigArchive(MemoryBufferRef Source, Error &Err);
414419
uint64_t getFirstChildOffset() const override { return FirstChildOffset; }
415420
uint64_t getLastChildOffset() const { return LastChildOffset; }
416-
bool isEmpty() const override {
417-
return Data.getBufferSize() == sizeof(FixLenHdr);
418-
};
421+
bool isEmpty() const override { return getFirstChildOffset() == 0; }
422+
423+
bool has32BitGlobalSymtab() { return Has32BitGlobalSymtab; }
424+
bool has64BitGlobalSymtab() { return Has64BitGlobalSymtab; }
419425
};
420426

421427
} // end namespace object
422428
} // end namespace llvm
423429

424-
#endif // LLVM_OBJECT_ARCHIVE_H
430+
#endif // LLVM_OBJECT_ARCHIVE_H

0 commit comments

Comments
 (0)