@@ -48,7 +48,6 @@ NewArchiveMember::getOldMember(const object::Archive::Child &OldMember,
48
48
return BufOrErr.takeError ();
49
49
50
50
NewArchiveMember M;
51
- assert (M.IsNew == false );
52
51
M.Buf = MemoryBuffer::getMemBuffer (*BufOrErr, false );
53
52
M.MemberName = M.Buf ->getBufferIdentifier ();
54
53
if (!Deterministic) {
@@ -98,7 +97,6 @@ Expected<NewArchiveMember> NewArchiveMember::getFile(StringRef FileName,
98
97
return errorCodeToError (std::error_code (errno, std::generic_category ()));
99
98
100
99
NewArchiveMember M;
101
- M.IsNew = true ;
102
100
M.Buf = std::move (*MemberBufferOrErr);
103
101
M.MemberName = M.Buf ->getBufferIdentifier ();
104
102
if (!Deterministic) {
@@ -191,35 +189,6 @@ static bool useStringTable(bool Thin, StringRef Name) {
191
189
return Thin || Name.size () >= 16 || Name.contains (' /' );
192
190
}
193
191
194
- // Compute the relative path from From to To.
195
- static std::string computeRelativePath (StringRef From, StringRef To) {
196
- if (sys::path::is_absolute (From) || sys::path::is_absolute (To))
197
- return To;
198
-
199
- StringRef DirFrom = sys::path::parent_path (From);
200
- auto FromI = sys::path::begin (DirFrom);
201
- auto ToI = sys::path::begin (To);
202
- while (*FromI == *ToI) {
203
- ++FromI;
204
- ++ToI;
205
- }
206
-
207
- SmallString<128 > Relative;
208
- for (auto FromE = sys::path::end (DirFrom); FromI != FromE; ++FromI)
209
- sys::path::append (Relative, " .." );
210
-
211
- for (auto ToE = sys::path::end (To); ToI != ToE; ++ToI)
212
- sys::path::append (Relative, *ToI);
213
-
214
- #ifdef _WIN32
215
- // Replace backslashes with slashes so that the path is portable between *nix
216
- // and Windows.
217
- std::replace (Relative.begin (), Relative.end (), ' \\ ' , ' /' );
218
- #endif
219
-
220
- return Relative.str ();
221
- }
222
-
223
192
static bool is64BitKind (object::Archive::Kind Kind) {
224
193
switch (Kind) {
225
194
case object::Archive::K_GNU:
@@ -234,27 +203,11 @@ static bool is64BitKind(object::Archive::Kind Kind) {
234
203
llvm_unreachable (" not supported for writting" );
235
204
}
236
205
237
- static void addToStringTable (raw_ostream &Out, StringRef ArcName,
238
- const NewArchiveMember &M, bool Thin) {
239
- StringRef ID = M.Buf ->getBufferIdentifier ();
240
- if (Thin) {
241
- if (M.IsNew )
242
- Out << computeRelativePath (ArcName, ID);
243
- else
244
- Out << ID;
245
- } else
246
- Out << M.MemberName ;
247
- Out << " /\n " ;
248
- }
249
-
250
- static void printMemberHeader (raw_ostream &Out, uint64_t Pos,
251
- raw_ostream &StringTable,
252
- StringMap<uint64_t > &MemberNames,
253
- object::Archive::Kind Kind, bool Thin,
254
- StringRef ArcName, const NewArchiveMember &M,
255
- sys::TimePoint<std::chrono::seconds> ModTime,
256
- unsigned Size ) {
257
-
206
+ static void
207
+ printMemberHeader (raw_ostream &Out, uint64_t Pos, raw_ostream &StringTable,
208
+ StringMap<uint64_t > &MemberNames, object::Archive::Kind Kind,
209
+ bool Thin, const NewArchiveMember &M,
210
+ sys::TimePoint<std::chrono::seconds> ModTime, unsigned Size ) {
258
211
if (isBSDLike (Kind))
259
212
return printBSDMemberHeader (Out, Pos, M.MemberName , ModTime, M.UID , M.GID ,
260
213
M.Perms , Size );
@@ -265,12 +218,12 @@ static void printMemberHeader(raw_ostream &Out, uint64_t Pos,
265
218
uint64_t NamePos;
266
219
if (Thin) {
267
220
NamePos = StringTable.tell ();
268
- addToStringTable ( StringTable, ArcName, M, Thin) ;
221
+ StringTable << M. MemberName << " / \n " ;
269
222
} else {
270
223
auto Insertion = MemberNames.insert ({M.MemberName , uint64_t (0 )});
271
224
if (Insertion.second ) {
272
225
Insertion.first ->second = StringTable.tell ();
273
- addToStringTable ( StringTable, ArcName, M, Thin) ;
226
+ StringTable << M. MemberName << " / \n " ;
274
227
}
275
228
NamePos = Insertion.first ->second ;
276
229
}
@@ -432,8 +385,8 @@ getSymbols(MemoryBufferRef Buf, raw_ostream &SymNames, bool &HasObject) {
432
385
433
386
static Expected<std::vector<MemberData>>
434
387
computeMemberData (raw_ostream &StringTable, raw_ostream &SymNames,
435
- object::Archive::Kind Kind, bool Thin, StringRef ArcName ,
436
- bool Deterministic, ArrayRef<NewArchiveMember> NewMembers) {
388
+ object::Archive::Kind Kind, bool Thin, bool Deterministic ,
389
+ ArrayRef<NewArchiveMember> NewMembers) {
437
390
static char PaddingData[8 ] = {' \n ' , ' \n ' , ' \n ' , ' \n ' , ' \n ' , ' \n ' , ' \n ' , ' \n ' };
438
391
439
392
// This ignores the symbol table, but we only need the value mod 8 and the
@@ -520,8 +473,8 @@ computeMemberData(raw_ostream &StringTable, raw_ostream &SymNames,
520
473
ModTime = sys::toTimePoint (FilenameCount[M.MemberName ]++);
521
474
else
522
475
ModTime = M.ModTime ;
523
- printMemberHeader (Out, Pos, StringTable, MemberNames, Kind, Thin, ArcName ,
524
- M, ModTime, Buf.getBufferSize () + MemberPadding);
476
+ printMemberHeader (Out, Pos, StringTable, MemberNames, Kind, Thin, M ,
477
+ ModTime, Buf.getBufferSize () + MemberPadding);
525
478
Out.flush ();
526
479
527
480
Expected<std::vector<unsigned >> Symbols =
@@ -540,11 +493,40 @@ computeMemberData(raw_ostream &StringTable, raw_ostream &SymNames,
540
493
return Ret;
541
494
}
542
495
543
- Error llvm::writeArchive (StringRef ArcName,
544
- ArrayRef<NewArchiveMember> NewMembers,
545
- bool WriteSymtab, object::Archive::Kind Kind,
546
- bool Deterministic, bool Thin,
547
- std::unique_ptr<MemoryBuffer> OldArchiveBuf) {
496
+ namespace llvm {
497
+ // Compute the relative path from From to To.
498
+ std::string computeArchiveRelativePath (StringRef From, StringRef To) {
499
+ if (sys::path::is_absolute (From) || sys::path::is_absolute (To))
500
+ return To;
501
+
502
+ StringRef DirFrom = sys::path::parent_path (From);
503
+ auto FromI = sys::path::begin (DirFrom);
504
+ auto ToI = sys::path::begin (To);
505
+ while (*FromI == *ToI) {
506
+ ++FromI;
507
+ ++ToI;
508
+ }
509
+
510
+ SmallString<128 > Relative;
511
+ for (auto FromE = sys::path::end (DirFrom); FromI != FromE; ++FromI)
512
+ sys::path::append (Relative, " .." );
513
+
514
+ for (auto ToE = sys::path::end (To); ToI != ToE; ++ToI)
515
+ sys::path::append (Relative, *ToI);
516
+
517
+ #ifdef _WIN32
518
+ // Replace backslashes with slashes so that the path is portable between *nix
519
+ // and Windows.
520
+ std::replace (Relative.begin (), Relative.end (), ' \\ ' , ' /' );
521
+ #endif
522
+
523
+ return Relative.str ();
524
+ }
525
+
526
+ Error writeArchive (StringRef ArcName, ArrayRef<NewArchiveMember> NewMembers,
527
+ bool WriteSymtab, object::Archive::Kind Kind,
528
+ bool Deterministic, bool Thin,
529
+ std::unique_ptr<MemoryBuffer> OldArchiveBuf) {
548
530
assert ((!Thin || !isBSDLike (Kind)) && " Only the gnu format has a thin mode" );
549
531
550
532
SmallString<0 > SymNamesBuf;
@@ -553,7 +535,7 @@ Error llvm::writeArchive(StringRef ArcName,
553
535
raw_svector_ostream StringTable (StringTableBuf);
554
536
555
537
Expected<std::vector<MemberData>> DataOrErr = computeMemberData (
556
- StringTable, SymNames, Kind, Thin, ArcName, Deterministic, NewMembers);
538
+ StringTable, SymNames, Kind, Thin, Deterministic, NewMembers);
557
539
if (Error E = DataOrErr.takeError ())
558
540
return E;
559
541
std::vector<MemberData> &Data = *DataOrErr;
@@ -630,3 +612,5 @@ Error llvm::writeArchive(StringRef ArcName,
630
612
631
613
return Temp->keep (ArcName);
632
614
}
615
+
616
+ } // namespace llvm
0 commit comments