Skip to content

Commit d88c9c3

Browse files
authored
Merge pull request #2 from rust-lang/aix_big
Add support for the AIX Big archive format
2 parents 532a045 + ebbb247 commit d88c9c3

File tree

7 files changed

+554
-151
lines changed

7 files changed

+554
-151
lines changed

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# A writer for object file ar archives
22

3-
This is based on commit [8ef3e895a](https://github.com/llvm/llvm-project/tree/8ef3e895ad8ab1724e2b87cabad1dacdc7a397a3) of LLVM's archive writer.
3+
This is based on commit [8ef3e895a](https://github.com/llvm/llvm-project/tree/3d3ef9d073e1e27ea57480b371b7f5a9f5642ed2) (15.0.0-rc3) of LLVM's archive writer.
44

55
## License
66

src/Alignment.h

Lines changed: 11 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copied from https://github.com/llvm/llvm-project/blob/8ef3e895ad8ab1724e2b87cabad1dacdc7a397a3/llvm/include/llvm/Support/Alignment.h
1+
// Copied from https://github.com/llvm/llvm-project/blob/3d3ef9d073e1e27ea57480b371b7f5a9f5642ed2/llvm/include/llvm/Support/Alignment.h
22

33
//===-- llvm/Support/Alignment.h - Useful alignment functions ---*- C++ -*-===//
44
//
@@ -86,6 +86,14 @@ struct Align {
8686
/// Needed to interact with C for instance.
8787
uint64_t value() const { return uint64_t(1) << ShiftValue; }
8888

89+
// Returns the previous alignment.
90+
Align previous() const {
91+
assert(ShiftValue != 0 && "Undefined operation");
92+
Align Out;
93+
Out.ShiftValue = ShiftValue - 1;
94+
return Out;
95+
}
96+
8997
/// Allow constructions of constexpr Align.
9098
template <size_t kValue> constexpr static LogValue Constant() {
9199
return LogValue{static_cast<uint8_t>(CTLog2<kValue>())};
@@ -133,7 +141,7 @@ struct MaybeAlign : public llvm::Optional<Align> {
133141
}
134142

135143
/// For convenience, returns a valid alignment or 1 if undefined.
136-
Align valueOrOne() const { return hasValue() ? getValue() : Align(); }
144+
Align valueOrOne() const { return value_or(Align()); }
137145
};
138146

139147
/// Checks that SizeInBytes is a multiple of the alignment.
@@ -175,13 +183,7 @@ inline uint64_t alignTo(uint64_t Size, Align A) {
175183
inline uint64_t alignTo(uint64_t Size, Align A, uint64_t Skew) {
176184
const uint64_t Value = A.value();
177185
Skew %= Value;
178-
return ((Size + Value - 1 - Skew) & ~(Value - 1U)) + Skew;
179-
}
180-
181-
/// Returns a multiple of A needed to store `Size` bytes.
182-
/// Returns `Size` if current alignment is undefined.
183-
inline uint64_t alignTo(uint64_t Size, MaybeAlign A) {
184-
return A ? alignTo(Size, A.getValue()) : Size;
186+
return alignTo(Size - Skew, A) + Skew;
185187
}
186188

187189
/// Aligns `Addr` to `Alignment` bytes, rounding up.
@@ -208,28 +210,12 @@ inline uint64_t offsetToAlignedAddr(const void *Addr, Align Alignment) {
208210
/// Returns the log2 of the alignment.
209211
inline unsigned Log2(Align A) { return A.ShiftValue; }
210212

211-
/// Returns the alignment that satisfies both alignments.
212-
/// Same semantic as MinAlign.
213-
inline Align commonAlignment(Align A, Align B) { return std::min(A, B); }
214-
215213
/// Returns the alignment that satisfies both alignments.
216214
/// Same semantic as MinAlign.
217215
inline Align commonAlignment(Align A, uint64_t Offset) {
218216
return Align(MinAlign(A.value(), Offset));
219217
}
220218

221-
/// Returns the alignment that satisfies both alignments.
222-
/// Same semantic as MinAlign.
223-
inline MaybeAlign commonAlignment(MaybeAlign A, MaybeAlign B) {
224-
return A && B ? commonAlignment(*A, *B) : A ? A : B;
225-
}
226-
227-
/// Returns the alignment that satisfies both alignments.
228-
/// Same semantic as MinAlign.
229-
inline MaybeAlign commonAlignment(MaybeAlign A, uint64_t Offset) {
230-
return MaybeAlign(MinAlign((*A).value(), Offset));
231-
}
232-
233219
/// Returns a representation of the alignment that encodes undefined as 0.
234220
inline unsigned encode(MaybeAlign A) { return A ? A->ShiftValue + 1 : 0; }
235221

@@ -272,14 +258,6 @@ inline bool operator>(Align Lhs, uint64_t Rhs) {
272258
return Lhs.value() > Rhs;
273259
}
274260

275-
/// Comparisons between MaybeAlign and scalars.
276-
inline bool operator==(MaybeAlign Lhs, uint64_t Rhs) {
277-
return Lhs ? (*Lhs).value() == Rhs : Rhs == 0;
278-
}
279-
inline bool operator!=(MaybeAlign Lhs, uint64_t Rhs) {
280-
return Lhs ? (*Lhs).value() != Rhs : Rhs != 0;
281-
}
282-
283261
/// Comparisons operators between Align.
284262
inline bool operator==(Align Lhs, Align Rhs) {
285263
return Lhs.ShiftValue == Rhs.ShiftValue;
@@ -316,37 +294,6 @@ bool operator>=(MaybeAlign Lhs, MaybeAlign Rhs) = delete;
316294
bool operator<(MaybeAlign Lhs, MaybeAlign Rhs) = delete;
317295
bool operator>(MaybeAlign Lhs, MaybeAlign Rhs) = delete;
318296

319-
inline Align operator*(Align Lhs, uint64_t Rhs) {
320-
assert(Rhs > 0 && "Rhs must be positive");
321-
return Align(Lhs.value() * Rhs);
322-
}
323-
324-
inline MaybeAlign operator*(MaybeAlign Lhs, uint64_t Rhs) {
325-
assert(Rhs > 0 && "Rhs must be positive");
326-
return Lhs ? Lhs.getValue() * Rhs : MaybeAlign();
327-
}
328-
329-
inline Align operator/(Align Lhs, uint64_t Divisor) {
330-
assert(llvm::isPowerOf2_64(Divisor) &&
331-
"Divisor must be positive and a power of 2");
332-
assert(Lhs != 1 && "Can't halve byte alignment");
333-
return Align(Lhs.value() / Divisor);
334-
}
335-
336-
inline MaybeAlign operator/(MaybeAlign Lhs, uint64_t Divisor) {
337-
assert(llvm::isPowerOf2_64(Divisor) &&
338-
"Divisor must be positive and a power of 2");
339-
return Lhs ? Lhs.getValue() / Divisor : MaybeAlign();
340-
}
341-
342-
inline Align max(MaybeAlign Lhs, Align Rhs) {
343-
return Lhs && *Lhs > Rhs ? *Lhs : Rhs;
344-
}
345-
346-
inline Align max(Align Lhs, MaybeAlign Rhs) {
347-
return Rhs && *Rhs > Lhs ? *Rhs : Lhs;
348-
}
349-
350297
#ifndef NDEBUG
351298
// For usage in LLVM_DEBUG macros.
352299
inline std::string DebugStr(const Align &A) {

src/Archive.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copied from https://github.com/llvm/llvm-project/blob/8ef3e895ad8ab1724e2b87cabad1dacdc7a397a3/llvm/include/llvm/Object/Archive.h
1+
// Copied from https://github.com/llvm/llvm-project/blob/3d3ef9d073e1e27ea57480b371b7f5a9f5642ed2/llvm/include/llvm/Object/Archive.h
22

33
//===- Archive.h - ar archive file format -----------------------*- C++ -*-===//
44
//
@@ -342,6 +342,7 @@ class Archive : public Binary {
342342

343343
Kind kind() const { return (Kind)Format; }
344344
bool isThin() const { return IsThin; }
345+
static object::Archive::Kind getDefaultKindForHost();
345346

346347
child_iterator child_begin(Error &Err, bool SkipInternal = true) const;
347348
child_iterator child_end() const;
@@ -361,7 +362,7 @@ class Archive : public Binary {
361362
// check if a symbol is in the archive
362363
Expected<Optional<Child>> findSym(StringRef name) const;
363364

364-
bool isEmpty() const;
365+
virtual bool isEmpty() const;
365366
bool hasSymbolTable() const;
366367
StringRef getSymbolTable() const { return SymbolTable; }
367368
StringRef getStringTable() const { return StringTable; }
@@ -380,10 +381,10 @@ class Archive : public Binary {
380381
uint64_t getArchiveMagicLen() const;
381382
void setFirstRegular(const Child &C);
382383

383-
private:
384384
StringRef SymbolTable;
385385
StringRef StringTable;
386386

387+
private:
387388
StringRef FirstRegularData;
388389
uint16_t FirstRegularStartOfFile = -1;
389390

@@ -393,6 +394,7 @@ class Archive : public Binary {
393394
};
394395

395396
class BigArchive : public Archive {
397+
public:
396398
/// Fixed-Length Header.
397399
struct FixLenHdr {
398400
char Magic[sizeof(BigArchiveMagic) - 1]; ///< Big archive magic string.
@@ -413,6 +415,9 @@ class BigArchive : public Archive {
413415
BigArchive(MemoryBufferRef Source, Error &Err);
414416
uint64_t getFirstChildOffset() const override { return FirstChildOffset; }
415417
uint64_t getLastChildOffset() const { return LastChildOffset; }
418+
bool isEmpty() const override {
419+
return Data.getBufferSize() == sizeof(FixLenHdr);
420+
};
416421
};
417422

418423
} // end namespace object

0 commit comments

Comments
 (0)