File tree Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -972,21 +972,21 @@ std::vector<size_t> LinkerScript<ELFT>::getPhdrIndices(StringRef SectionName) {
972
972
973
973
std::vector<size_t > Ret;
974
974
for (StringRef PhdrName : Cmd->Phdrs )
975
- Ret.push_back (getPhdrIndex (PhdrName));
975
+ Ret.push_back (getPhdrIndex (Cmd-> Location , PhdrName));
976
976
return Ret;
977
977
}
978
978
return {};
979
979
}
980
980
981
981
template <class ELFT >
982
- size_t LinkerScript<ELFT>::getPhdrIndex(StringRef PhdrName) {
982
+ size_t LinkerScript<ELFT>::getPhdrIndex(const Twine &Loc, StringRef PhdrName) {
983
983
size_t I = 0 ;
984
984
for (PhdrsCommand &Cmd : Opt.PhdrsCommands ) {
985
985
if (Cmd.Name == PhdrName)
986
986
return I;
987
987
++I;
988
988
}
989
- error (" section header '" + PhdrName + " ' is not listed in PHDRS" );
989
+ error (Loc + " : section header '" + PhdrName + " ' is not listed in PHDRS" );
990
990
return 0 ;
991
991
}
992
992
@@ -1441,6 +1441,7 @@ uint32_t ScriptParser::readFill() {
1441
1441
OutputSectionCommand *
1442
1442
ScriptParser::readOutputSectionDescription (StringRef OutSec) {
1443
1443
OutputSectionCommand *Cmd = new OutputSectionCommand (OutSec);
1444
+ Cmd->Location = getCurrentLocation ();
1444
1445
1445
1446
// Read an address expression.
1446
1447
// https://sourceware.org/binutils/docs/ld/Output-Section-Address.html#Output-Section-Address
Original file line number Diff line number Diff line change @@ -124,6 +124,7 @@ struct OutputSectionCommand : BaseCommand {
124
124
std::vector<StringRef> Phdrs;
125
125
uint32_t Filler = 0 ;
126
126
ConstraintKind Constraint = ConstraintKind::NoConstraint;
127
+ std::string Location;
127
128
};
128
129
129
130
// This struct represents one section match pattern in SECTIONS() command.
@@ -268,7 +269,7 @@ template <class ELFT> class LinkerScript final : public LinkerScriptBase {
268
269
ScriptConfiguration &Opt = *ScriptConfig;
269
270
270
271
std::vector<size_t > getPhdrIndices (StringRef SectionName);
271
- size_t getPhdrIndex (StringRef PhdrName);
272
+ size_t getPhdrIndex (const Twine &Loc, StringRef PhdrName);
272
273
273
274
uintX_t Dot;
274
275
uintX_t LMAOffset = 0 ;
Original file line number Diff line number Diff line change 39
39
# RUN: ld.lld -o %t1 --script %t.script %t
40
40
# RUN: llvm-readobj -program-headers %t1 | FileCheck --check-prefix=DEFHDR %s
41
41
42
+ ## Check that error is reported when trying to use phdr which is not listed
43
+ ## inside PHDRS {} block
44
+ ## TODO: If script doesn't contain PHDRS {} block then default phdr is always
45
+ ## created and error is not reported.
46
+ # RUN: echo "PHDRS { all PT_LOAD; } \
47
+ # RUN: SECTIONS { .baz : {*(.foo.*)} :bar }" > %t.script
48
+ # RUN: not ld.lld -o %t1 --script %t.script %t 2>&1 | FileCheck --check-prefix=BADHDR %s
49
+
42
50
# CHECK: ProgramHeaders [
43
51
# CHECK-NEXT: ProgramHeader {
44
52
# CHECK-NEXT: Type: PT_LOAD (0x1)
120
128
# DEFHDR-NEXT: PF_X (0x1)
121
129
# DEFHDR-NEXT: ]
122
130
131
+ # BADHDR: {{.*}}.script:1: section header 'bar' is not listed in PHDRS
132
+
123
133
.global _start
124
134
_start:
125
135
nop
You can’t perform that action at this time.
0 commit comments