llvm.org GIT mirror llvm / e015a1a
[llvm-objcopy] Tidy up error messages This patch brings various error messages into line with each other, by removing trailing full stops, and making the first letter lower-case. This addresses https://bugs.llvm.org/show_bug.cgi?id=40859. Reviewed by: jhenderson, rupprecht, jakehehrlich Differential Revision: https://reviews.llvm.org/D62072 Patch by Alex Brachet git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361384 91177308-0d34-0410-b5e6-96231b3b80d8 James Henderson 5 months ago
27 changed file(s) with 128 addition(s) and 128 deletion(s). Raw diff Collapse all Expand all
9595 # Removing the .comdat section fails, since the .text section has relocations
9696 # against it.
9797 #
98 # ERROR-RELOC: Relocation target 'foo' ({{.*}}) not found
98 # ERROR-RELOC: relocation target 'foo' ({{.*}}) not found
9999 #
100100 #
101101 # Removing the .comdat section and .text (with a relocation against .comdat)
11 RUN: not llvm-objcopy -N foo %t.o 2>&1 | FileCheck %s --check-prefix=ERROR
22 RUN: not llvm-objcopy --strip-symbol foo %t.o 2>&1 | FileCheck %s --check-prefix=ERROR
33
4 ERROR: error: '{{.*}}{{/|\\}}strip-reloc-symbol.test.tmp.o': not stripping symbol 'foo' because it is named in a relocation.
4 ERROR: error: '{{.*}}{{/|\\}}strip-reloc-symbol.test.tmp.o': not stripping symbol 'foo' because it is named in a relocation
1414 # SYMBOLS-POST-NEXT: AUX indx 0
1515 # SYMBOLS-EMPTY:
1616
17 # ERROR: Symbol 'foobar' is missing its weak target
17 # ERROR: symbol 'foobar' is missing its weak target
1818
1919 --- !COFF
2020 header:
0 # RUN: yaml2obj %s > %t
11 # RUN: not llvm-objcopy --build-id-link-dir=%t-dir --build-id-link-input=.debug %t 2>&1 >/dev/null | FileCheck %s
22
3 # CHECK: build ID is smaller than two bytes.
3 # CHECK: build ID is smaller than two bytes
44
55 --- !ELF
66 FileHeader:
0 # RUN: not llvm-objcopy -O binary %p/Inputs/alloc-symtab.o %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=SYMTAB
1 # SYMTAB: Cannot write symbol table '.symtab' out to binary
1 # SYMTAB: cannot write symbol table '.symtab' out to binary
2222 Type: STT_FUNC
2323 Section: .text
2424
25 # CHECK: not stripping symbol '.L.rel' because it is named in a relocation.
25 # CHECK: not stripping symbol '.L.rel' because it is named in a relocation
4040
4141 #SIZE: 4
4242
43 #NOBITS: Can't dump section ".bar": it has no contents
43 #NOBITS: cannot dump section '.bar': it has no contents
22 ## Check we cannot remove the .dynsym symbol table because dynamic
33 ## relocation section .rela.dyn still references it via sh_link field.
44 # RUN: not llvm-objcopy -R .dynsym %t %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
5 # ERR: error: Symbol table .dynsym cannot be removed because it is referenced by the relocation section .rela.dyn.
5 # ERR: error: symbol table '.dynsym' cannot be removed because it is referenced by the relocation section '.rela.dyn'
66
77 ## Check we can remove .dynsym after removing the reference.
88 # RUN: llvm-objcopy -R .dynsym -R .rela.dyn %t %t2
11 # RUN: cp %p/Inputs/dynsym.so %t2
22 # RUN: not llvm-strip --no-strip-all -R .dynstr %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
33
4 # ERR: Section .dynstr cannot be removed because it is referenced by the section .dynsym
4 # ERR: section '.dynstr' cannot be removed because it is referenced by the section '.dynsym'
55
66 # RUN: llvm-objcopy --allow-broken-links -R .dynstr %p/Inputs/dynsym.so %t3
77 # RUN: llvm-objdump --section-headers %t3 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.dynstr
0 # RUN: yaml2obj %s > %t
11 # RUN: not llvm-objcopy %t %t2 2>&1 | FileCheck %s
2 # CHECK: error: Invalid alignment 1 of group section .group.
2 # CHECK: error: invalid alignment 1 of group section '.group'
33
44 # In this test, we check that llvm-objcopy reports an error
55 # for SHT_GROUP section with invalid alignment (not a multiple of 4).
1111 Index: SHN_HEXAGON_SCOMMON
1212 Binding: STB_GLOBAL
1313
14 # CHECK: Symbol 'test' has unsupported value greater than or equal to SHN_LORESERVE: 65280
14 # CHECK: symbol 'test' has unsupported value greater than or equal to SHN_LORESERVE: 65280
0 # RUN: yaml2obj %s > %t
11 # RUN: not llvm-objcopy --build-id-link-dir=%t-dir --build-id-link-input=.debug %t 2>&1 >/dev/null | FileCheck %s
22
3 # CHECK: Could not find build ID.
3 # CHECK: could not find build ID
44
55 --- !ELF
66 FileHeader:
0 # RUN: yaml2obj %s > %t
11 # RUN: not llvm-objcopy --build-id-link-dir=%t-dir --build-id-link-input=.debug %t 2>&1 >/dev/null | FileCheck %s
22
3 # CHECK: Could not find build ID.
3 # CHECK: could not find build ID
44
55 --- !ELF
66 FileHeader:
3030 Size: 4
3131 Binding: STB_GLOBAL
3232
33 # ERR: Symbol table .symtab cannot be removed because it is referenced by the relocation section .rel.text.
33 # ERR: symbol table '.symtab' cannot be removed because it is referenced by the relocation section '.rel.text'
3434
3535 # RUN: llvm-objcopy --allow-broken-links -R .symtab %t %t4
3636 # RUN: llvm-readobj --sections %t4 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.symtab
1515 Type: SHT_PROGBITS
1616 Link: .foo
1717
18 # ERR: Section .foo cannot be removed because it is referenced by the section .bar
18 # ERR: section '.foo' cannot be removed because it is referenced by the section '.bar'
1919
2020 # RUN: llvm-objcopy --allow-broken-links -R .foo %t.o %t3
2121 # RUN: llvm-readobj --sections %t3 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.foo
77 Type: ET_REL
88 Machine: EM_X86_64
99
10 # CHECK: Cannot write section header table because section header string table was removed.
10 # CHECK: cannot write section header table because section header string table was removed
1111 Index: 0xff05
1212 Binding: STB_GLOBAL
1313
14 # CHECK: Symbol 'test' has unsupported value greater than or equal to SHN_LORESERVE: 65285
14 # CHECK: symbol 'test' has unsupported value greater than or equal to SHN_LORESERVE: 65285
2727 Section: .text
2828 Binding: STB_WEAK
2929
30 #CHECK: Symbol foo cannot be removed because it is referenced by the section .group[1].
30 # CHECK: symbol 'foo' cannot be removed because it is referenced by the section '.group[1]'
2727 Value: 0x1000
2828 Size: 8
2929
30 #CHECK: not stripping symbol 'foo' because it is named in a relocation.
30 # CHECK: not stripping symbol 'foo' because it is named in a relocation
22
33 # RUN: yaml2obj %s > %t1
44 # RUN: not llvm-objcopy -R .data %t1 2>&1 | FileCheck %s
5 # CHECK: error: Section .data can't be removed: (.text+0x1) has relocation against symbol 'foo'
5 # CHECK: error: section '.data' cannot be removed: (.text+0x1) has relocation against symbol 'foo'
66
77 ## Check the behavior when we also remove the relocation section.
88 ## We have no reference in this case and hence no error should be emitted.
99 Type: ET_REL
1010 Machine: EM_X86_64
1111
12 # ERR: String table .strtab cannot be removed because it is referenced by the symbol table .symtab
12 # ERR: string table '.strtab' cannot be removed because it is referenced by the symbol table '.symtab'
1313
1414 # RUN: llvm-objcopy --allow-broken-links -R .strtab %t %t4
1515 # RUN: llvm-objdump --section-headers %t4 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.strtab
142142 reportError(Config.OutputFilename,
143143 createStringError(llvm::errc::invalid_argument,
144144 "not stripping symbol '%s' because it is "
145 "named in a relocation.",
145 "named in a relocation",
146146 Sym.Name.str().c_str()));
147147 return true;
148148 }
188188 Config.DiscardMode == DiscardType::Locals ||
189189 !Config.SymbolsToAdd.empty() || Config.EntryExpr) {
190190 return createStringError(llvm::errc::invalid_argument,
191 "Option not supported by llvm-objcopy for COFF");
191 "option not supported by llvm-objcopy for COFF");
192192 }
193193
194194 return Error::success();
5252 auto It = SymbolMap.find(R.Target);
5353 if (It == SymbolMap.end())
5454 return createStringError(object_error::invalid_symbol_index,
55 "Relocation target %zu not found", R.Target);
55 "relocation target %zu not found", R.Target);
5656 It->second->Referenced = true;
5757 }
5858 }
8080 return NameOrErr.takeError();
8181 if (Sec->hasExtendedRelocations())
8282 return createStringError(object_error::parse_failed,
83 "Extended relocations not supported yet");
83 "extended relocations not supported yet");
8484 }
8585 Obj.addSections(Sections);
8686 return Error::success();
134134 Sym.TargetSectionId = Sections[SymRef.getSectionNumber() - 1].UniqueId;
135135 else
136136 return createStringError(object_error::parse_failed,
137 "Section number out of range");
137 "section number out of range");
138138 // For section definitions, check if it is comdat associative, and if
139139 // it is, find the target section unique id.
140140 const coff_aux_section_definition *SD = SymRef.getSectionDefinition();
143143 int32_t Index = SD->getNumber(IsBigObj);
144144 if (Index <= 0 || static_cast(Index - 1) >= Sections.size())
145145 return createStringError(object_error::parse_failed,
146 "Unexpected associative section index");
146 "unexpected associative section index");
147147 Sym.AssociativeComdatTargetSectionId = Sections[Index - 1].UniqueId;
148148 } else if (WE) {
149149 // This is a raw symbol index for now, but store it in the Symbol
170170 if (Sym.WeakTargetSymbolId) {
171171 if (*Sym.WeakTargetSymbolId >= RawSymbolTable.size())
172172 return createStringError(object_error::parse_failed,
173 "Weak external reference out of range");
173 "weak external reference out of range");
174174 const Symbol *Target = RawSymbolTable[*Sym.WeakTargetSymbolId];
175175 if (Target == nullptr)
176176 return createStringError(object_error::parse_failed,
177 "Invalid SymbolTableIndex");
177 "invalid SymbolTableIndex");
178178 Sym.WeakTargetSymbolId = Target->UniqueId;
179179 }
180180 }
186186 const Symbol *Sym = RawSymbolTable[R.Reloc.SymbolTableIndex];
187187 if (Sym == nullptr)
188188 return createStringError(object_error::parse_failed,
189 "Invalid SymbolTableIndex");
189 "invalid SymbolTableIndex");
190190 R.Target = Sym->UniqueId;
191191 R.TargetName = Sym->Name;
192192 }
207207 } else {
208208 if (!CBFH)
209209 return createStringError(object_error::parse_failed,
210 "No COFF file header returned");
210 "no COFF file header returned");
211211 // Only copying the few fields from the bigobj header that we need
212212 // and won't recreate in the end.
213213 Obj->CoffFileHeader.Machine = CBFH->Machine;
2828 const Symbol *Sym = Obj.findSymbol(R.Target);
2929 if (Sym == nullptr)
3030 return createStringError(object_error::invalid_symbol_index,
31 "Relocation target '%s' (%zu) not found",
31 "relocation target '%s' (%zu) not found",
3232 R.TargetName.str().c_str(), R.Target);
3333 R.Reloc.SymbolTableIndex = Sym->RawIndex;
3434 }
4646 const Section *Sec = Obj.findSection(Sym.TargetSectionId);
4747 if (Sec == nullptr)
4848 return createStringError(object_error::invalid_symbol_index,
49 "Symbol '%s' points to a removed section",
49 "symbol '%s' points to a removed section",
5050 Sym.Name.str().c_str());
5151 Sym.Sym.SectionNumber = Sec->Index;
5252
6565 if (Sec == nullptr)
6666 return createStringError(
6767 object_error::invalid_symbol_index,
68 "Symbol '%s' is associative to a removed section",
68 "symbol '%s' is associative to a removed section",
6969 Sym.Name.str().c_str());
7070 SDSectionNumber = Sec->Index;
7171 }
8282 const Symbol *Target = Obj.findSymbol(*Sym.WeakTargetSymbolId);
8383 if (Target == nullptr)
8484 return createStringError(object_error::invalid_symbol_index,
85 "Symbol '%s' is missing its weak target",
85 "symbol '%s' is missing its weak target",
8686 Sym.Name.str().c_str());
8787 WE->TagIndex = Target->RawIndex;
8888 }
382382 if (Dir->RelativeVirtualAddress + Dir->Size >
383383 S.Header.VirtualAddress + S.Header.SizeOfRawData)
384384 return createStringError(object_error::parse_failed,
385 "Debug directory extends past end of section");
385 "debug directory extends past end of section");
386386
387387 size_t Offset = Dir->RelativeVirtualAddress - S.Header.VirtualAddress;
388388 uint8_t *Ptr = Buf.getBufferStart() + S.Header.PointerToRawData + Offset;
399399 }
400400 }
401401 return createStringError(object_error::parse_failed,
402 "Debug directory not found");
402 "debug directory not found");
403403 }
404404
405405 Error COFFWriter::write() {
406406 bool IsBigObj = Obj.getSections().size() > MaxNumberOfSections16;
407407 if (IsBigObj && Obj.IsPE)
408408 return createStringError(object_error::parse_failed,
409 "Too many sections for executable");
409 "too many sections for executable");
410410 return write(IsBigObj);
411411 }
412412
167167 return std::move(Err);
168168 }
169169 return createStringError(llvm::errc::invalid_argument,
170 "Could not find build ID.");
170 "could not find build ID");
171171 }
172172
173173 static Expected>
185185 }
186186
187187 template
188 static Error makeStringError(std::error_code EC, const Twine &Msg, Ts&&... Args) {
188 static Error makeStringError(std::error_code EC, const Twine &Msg, Ts &&... Args) {
189189 std::string FullMsg = (EC.message() + ": " + Msg).str();
190190 return createStringError(EC, FullMsg.c_str(), std::forward(Args)...);
191191 }
221221 /*MakeAbsolute*/ false);
222222 if (auto EC = sys::fs::create_hard_link(ToLink, TmpPath)) {
223223 Path.push_back('\0');
224 return makeStringError(EC, "cannot link %s to %s", ToLink.data(),
225 Path.data());
224 return makeStringError(EC, "cannot link '%s' to '%s'", ToLink.data(),
225 Path.data());
226226 }
227227 // We then atomically rename the link into place which will just move the
228228 // link. If rename fails something is more seriously wrong so just return
229229 // an error.
230230 if (auto EC = sys::fs::rename(TmpPath, Path)) {
231231 Path.push_back('\0');
232 return makeStringError(EC, "cannot link %s to %s", ToLink.data(),
233 Path.data());
232 return makeStringError(EC, "cannot link '%s' to '%s'", ToLink.data(),
233 Path.data());
234234 }
235235 // If `Path` was already a hard-link to the same underlying file then the
236236 // temp file will be left so we need to remove it. Remove will not cause
238238 // it rather than checking.
239239 if (auto EC = sys::fs::remove(TmpPath)) {
240240 TmpPath.push_back('\0');
241 return makeStringError(EC, "could not remove %s", TmpPath.data());
241 return makeStringError(EC, "could not remove '%s'", TmpPath.data());
242242 }
243243 return Error::success();
244244 }
249249 auto OnlyKeepDWOPred = [&DWOFile](const SectionBase &Sec) {
250250 return onlyKeepDWOPred(*DWOFile, Sec);
251251 };
252 if (Error E = DWOFile->removeSections(Config.AllowBrokenLinks,
252 if (Error E = DWOFile->removeSections(Config.AllowBrokenLinks,
253253 OnlyKeepDWOPred))
254254 return E;
255255 if (Config.OutputArch) {
268268 for (auto &Sec : Obj.sections()) {
269269 if (Sec.Name == SecName) {
270270 if (Sec.OriginalData.empty())
271 return createStringError(
272 object_error::parse_failed,
273 "Can't dump section \"%s\": it has no contents",
274 SecName.str().c_str());
271 return createStringError(object_error::parse_failed,
272 "cannot dump section '%s': it has no contents",
273 SecName.str().c_str());
275274 Expected> BufferOrErr =
276275 FileOutputBuffer::create(Filename, Sec.OriginalData.size());
277276 if (!BufferOrErr)
284283 return Error::success();
285284 }
286285 }
287 return createStringError(object_error::parse_failed, "Section not found");
286 return createStringError(object_error::parse_failed, "section '%s' not found",
287 SecName.str().c_str());
288288 }
289289
290290 static bool isCompressable(const SectionBase &Section) {
533533 }
534534
535535 if (Config.CompressionType != DebugCompressionType::None)
536 replaceDebugSections(Obj, RemovePred, isCompressable,
536 replaceDebugSections(Obj, RemovePred, isCompressable,
537537 [&Config, &Obj](const SectionBase *S) {
538538 return &Obj.addSection(
539 *S, Config.CompressionType);
540 });
539 *S, Config.CompressionType);
540 });
541541 else if (Config.DecompressDebugSections)
542542 replaceDebugSections(
543543 Obj, RemovePred,
599599 Sec.Name = (Config.AllocSectionsPrefix + Sec.Name).str();
600600 PrefixedSections.insert(&Sec);
601601
602 // Rename relocation sections associated to the allocated sections.
603 // For example, if we rename .text to .prefix.text, we also rename
604 // .rel.text to .rel.prefix.text.
605 //
606 // Dynamic relocation sections (SHT_REL[A] with SHF_ALLOC) are handled
607 // above, e.g., .rela.plt is renamed to .prefix.rela.plt, not
608 // .rela.prefix.plt since GNU objcopy does so.
602 // Rename relocation sections associated to the allocated sections.
603 // For example, if we rename .text to .prefix.text, we also rename
604 // .rel.text to .rel.prefix.text.
605 //
606 // Dynamic relocation sections (SHT_REL[A] with SHF_ALLOC) are handled
607 // above, e.g., .rela.plt is renamed to .prefix.rela.plt, not
608 // .rela.prefix.plt since GNU objcopy does so.
609609 } else if (auto *RelocSec = dyn_cast(&Sec)) {
610610 auto *TargetSec = RelocSec->getSection();
611611 if (TargetSec && (TargetSec->Flags & SHF_ALLOC)) {
734734 return createFileError(
735735 Config.InputFilename,
736736 createStringError(object_error::parse_failed,
737 "build ID is smaller than two bytes."));
737 "build ID is smaller than two bytes"));
738738 }
739739
740740 if (!Config.BuildIdLinkDir.empty() && Config.BuildIdLinkInput)
123123 void ELFSectionSizer::visit(DecompressedSection &Sec) {}
124124
125125 void BinarySectionWriter::visit(const SectionIndexSection &Sec) {
126 error("Cannot write symbol section index table '" + Sec.Name + "' ");
126 error("cannot write symbol section index table '" + Sec.Name + "' ");
127127 }
128128
129129 void BinarySectionWriter::visit(const SymbolTableSection &Sec) {
130 error("Cannot write symbol table '" + Sec.Name + "' out to binary");
130 error("cannot write symbol table '" + Sec.Name + "' out to binary");
131131 }
132132
133133 void BinarySectionWriter::visit(const RelocationSection &Sec) {
134 error("Cannot write relocation section '" + Sec.Name + "' out to binary");
134 error("cannot write relocation section '" + Sec.Name + "' out to binary");
135135 }
136136
137137 void BinarySectionWriter::visit(const GnuDebugLinkSection &Sec) {
138 error("Cannot write '" + Sec.Name + "' out to binary");
138 error("cannot write '" + Sec.Name + "' out to binary");
139139 }
140140
141141 void BinarySectionWriter::visit(const GroupSection &Sec) {
142 error("Cannot write '" + Sec.Name + "' out to binary");
142 error("cannot write '" + Sec.Name + "' out to binary");
143143 }
144144
145145 void SectionWriter::visit(const Section &Sec) {
201201 }
202202
203203 void BinarySectionWriter::visit(const DecompressedSection &Sec) {
204 error("Cannot write compressed section '" + Sec.Name + "' ");
204 error("cannot write compressed section '" + Sec.Name + "' ");
205205 }
206206
207207 void DecompressedSection::accept(SectionVisitor &Visitor) const {
221221 }
222222
223223 void BinarySectionWriter::visit(const CompressedSection &Sec) {
224 error("Cannot write compressed section '" + Sec.Name + "' ");
224 error("cannot write compressed section '" + Sec.Name + "' ");
225225 }
226226
227227 template
432432 if (!AllowBrokenLinks)
433433 return createStringError(
434434 llvm::errc::invalid_argument,
435 "String table %s cannot be removed because it is "
436 "referenced by the symbol table %s",
435 "string table '%s' cannot be removed because it is "
436 "referenced by the symbol table '%s'",
437437 SymbolNames->Name.data(), this->Name.data());
438438 SymbolNames = nullptr;
439439 }
522522
523523 const Symbol *SymbolTableSection::getSymbolByIndex(uint32_t Index) const {
524524 if (Symbols.size() <= Index)
525 error("Invalid symbol index: " + Twine(Index));
525 error("invalid symbol index: " + Twine(Index));
526526 return Symbols[Index].get();
527527 }
528528
564564 if (!AllowBrokenLinks)
565565 return createStringError(
566566 llvm::errc::invalid_argument,
567 "Symbol table %s cannot be removed because it is "
568 "referenced by the relocation section %s.",
567 "symbol table '%s' cannot be removed because it is "
568 "referenced by the relocation section '%s'",
569569 Symbols->Name.data(), this->Name.data());
570570 Symbols = nullptr;
571571 }
574574 if (!R.RelocSymbol->DefinedIn || !ToRemove(R.RelocSymbol->DefinedIn))
575575 continue;
576576 return createStringError(llvm::errc::invalid_argument,
577 "Section %s can't be removed: (%s+0x%" PRIx64
577 "section '%s' cannot be removed: (%s+0x%" PRIx64
578578 ") has relocation against symbol '%s'",
579579 R.RelocSymbol->DefinedIn->Name.data(),
580580 SecToApplyRel->Name.data(), R.Offset,
652652 if (ToRemove(*Reloc.RelocSymbol))
653653 return createStringError(
654654 llvm::errc::invalid_argument,
655 "not stripping symbol '%s' because it is named in a relocation.",
655 "not stripping symbol '%s' because it is named in a relocation",
656656 Reloc.RelocSymbol->Name.data());
657657 return Error::success();
658658 }
679679 }
680680
681681 void DynamicRelocationSection::accept(MutableSectionVisitor &Visitor) {
682 Visitor.visit(*this);
683 }
684
685 Error DynamicRelocationSection::removeSectionReferences(
686 bool AllowBrokenLinks, function_ref ToRemove) {
687 if (ToRemove(Symbols)) {
688 if (!AllowBrokenLinks)
689 return createStringError(
690 llvm::errc::invalid_argument,
691 "Symbol table %s cannot be removed because it is "
692 "referenced by the relocation section %s.",
693 Symbols->Name.data(), this->Name.data());
694 Symbols = nullptr;
695 }
696
697 // SecToApplyRel contains a section referenced by sh_info field. It keeps
698 // a section to which the relocation section applies. When we remove any
699 // sections we also remove their relocation sections. Since we do that much
700 // earlier, this assert should never be triggered.
701 assert(!SecToApplyRel || !ToRemove(SecToApplyRel));
702
703 return Error::success();
704 }
705
706 Error Section::removeSectionReferences(bool AllowBrokenDependency,
707 function_ref ToRemove) {
708 if (ToRemove(LinkSection)) {
682 Visitor.visit(*this);
683 }
684
685 Error DynamicRelocationSection::removeSectionReferences(
686 bool AllowBrokenLinks, function_ref ToRemove) {
687 if (ToRemove(Symbols)) {
688 if (!AllowBrokenLinks)
689 return createStringError(
690 llvm::errc::invalid_argument,
691 "symbol table '%s' cannot be removed because it is "
692 "referenced by the relocation section '%s'",
693 Symbols->Name.data(), this->Name.data());
694 Symbols = nullptr;
695 }
696
697 // SecToApplyRel contains a section referenced by sh_info field. It keeps
698 // a section to which the relocation section applies. When we remove any
699 // sections we also remove their relocation sections. Since we do that much
700 // earlier, this assert should never be triggered.
701 assert(!SecToApplyRel || !ToRemove(SecToApplyRel));
702
703 return Error::success();
704 }
705
706 Error Section::removeSectionReferences(bool AllowBrokenDependency,
707 function_ref ToRemove) {
708 if (ToRemove(LinkSection)) {
709709 if (!AllowBrokenDependency)
710710 return createStringError(llvm::errc::invalid_argument,
711 "Section %s cannot be removed because it is "
712 "referenced by the section %s",
711 "section '%s' cannot be removed because it is "
712 "referenced by the section '%s'",
713713 LinkSection->Name.data(), this->Name.data());
714714 LinkSection = nullptr;
715715 }
724724 Error GroupSection::removeSymbols(function_ref ToRemove) {
725725 if (ToRemove(*Sym))
726726 return createStringError(llvm::errc::invalid_argument,
727 "Symbol %s cannot be removed because it is "
728 "referenced by the section %s[%d].",
727 "symbol '%s' cannot be removed because it is "
728 "referenced by the section '%s[%d]'",
729729 Sym->Name.data(), this->Name.data(), this->Index);
730730 return Error::success();
731731 }
995995 template
996996 void ELFBuilder::initGroupSection(GroupSection *GroupSec) {
997997 if (GroupSec->Align % sizeof(ELF::Elf32_Word) != 0)
998 error("Invalid alignment " + Twine(GroupSec->Align) + " of group section " +
999 GroupSec->Name);
998 error("invalid alignment " + Twine(GroupSec->Align) + " of group section '" +
999 GroupSec->Name + "'");
10001000 auto SecTable = Obj.sections();
10011001 auto SymTab = SecTable.template getSectionOfType(
10021002 GroupSec->Link,
1003 "Link field value " + Twine(GroupSec->Link) + " in section " +
1004 GroupSec->Name + " is invalid",
1005 "Link field value " + Twine(GroupSec->Link) + " in section " +
1006 GroupSec->Name + " is not a symbol table");
1003 "link field value '" + Twine(GroupSec->Link) + "' in section '" +
1004 GroupSec->Name + "' is invalid",
1005 "link field value '" + Twine(GroupSec->Link) + "' in section '" +
1006 GroupSec->Name + "' is not a symbol table");
10071007 auto Sym = SymTab->getSymbolByIndex(GroupSec->Info);
10081008 if (!Sym)
1009 error("Info field value " + Twine(GroupSec->Info) + " in section " +
1010 GroupSec->Name + " is not a valid symbol index");
1009 error("info field value '" + Twine(GroupSec->Info) + "' in section '" +
1010 GroupSec->Name + "' is not a valid symbol index");
10111011 GroupSec->setSymTab(SymTab);
10121012 GroupSec->setSymbol(Sym);
10131013 if (GroupSec->Contents.size() % sizeof(ELF::Elf32_Word) ||
10141014 GroupSec->Contents.empty())
1015 error("The content of the section " + GroupSec->Name + " is malformed");
1015 error("the content of the section " + GroupSec->Name + " is malformed");
10161016 const ELF::Elf32_Word *Word =
10171017 reinterpret_cast(GroupSec->Contents.data());
10181018 const ELF::Elf32_Word *End =
10211021 for (; Word != End; ++Word) {
10221022 uint32_t Index = support::endian::read32(Word);
10231023 GroupSec->addMember(SecTable.getSection(
1024 Index, "Group member index " + Twine(Index) + " in section " +
1025 GroupSec->Name + " is invalid"));
1024 Index, "group member index " + Twine(Index) + " in section '" +
1025 GroupSec->Name + "' is invalid"));
10261026 }
10271027 }
10281028
10391039
10401040 if (Sym.st_shndx == SHN_XINDEX) {
10411041 if (SymTab->getShndxTable() == nullptr)
1042 error("Symbol '" + Name +
1043 "' has index SHN_XINDEX but no SHT_SYMTAB_SHNDX section exists.");
1042 error("symbol '" + Name +
1043 "' has index SHN_XINDEX but no SHT_SYMTAB_SHNDX section exists");
10441044 if (ShndxData.data() == nullptr) {
10451045 const Elf_Shdr &ShndxSec =
10461046 *unwrapOrError(ElfFile.getSection(SymTab->getShndxTable()->Index));
10471047 ShndxData = unwrapOrError(
10481048 ElfFile.template getSectionContentsAsArray(&ShndxSec));
10491049 if (ShndxData.size() != Symbols.size())
1050 error("Symbol section index table does not have the same number of "
1051 "entries as the symbol table.");
1050 error("symbol section index table does not have the same number of "
1051 "entries as the symbol table");
10521052 }
10531053 Elf_Word Index = ShndxData[&Sym - Symbols.begin()];
10541054 DefSection = Obj.sections().getSection(
10551055 Index,
1056 "Symbol '" + Name + "' has invalid section index " + Twine(Index));
1056 "symbol '" + Name + "' has invalid section index " + Twine(Index));
10571057 } else if (Sym.st_shndx >= SHN_LORESERVE) {
10581058 if (!isValidReservedSectionIndex(Sym.st_shndx, Obj.Machine)) {
10591059 error(
1060 "Symbol '" + Name +
1060 "symbol '" + Name +
10611061 "' has unsupported value greater than or equal to SHN_LORESERVE: " +
10621062 Twine(Sym.st_shndx));
10631063 }
10641064 } else if (Sym.st_shndx != SHN_UNDEF) {
10651065 DefSection = Obj.sections().getSection(
1066 Sym.st_shndx, "Symbol '" + Name +
1066 Sym.st_shndx, "symbol '" + Name +
10671067 "' is defined has invalid section index " +
10681068 Twine(Sym.st_shndx));
10691069 }
12891289 Builder.build();
12901290 return Obj;
12911291 }
1292 error("Invalid file type");
1292 error("invalid file type");
12931293 }
12941294
12951295 template void ELFWriter::writeEhdr() {
16241624 // to do that.
16251625 if (Obj.SectionNames == nullptr && WriteSectionHeaders)
16261626 return createStringError(llvm::errc::invalid_argument,
1627 "Cannot write section header table because "
1628 "section header string table was removed.");
1627 "cannot write section header table because "
1628 "section header string table was removed");
16291629
16301630 Obj.sortSections();
16311631