Skip to content

Commit 2e67776

Browse files
committed
make code more conventional; simplify code; use just diag prefix in CHECK-NOT.
1 parent 1d2db0b commit 2e67776

File tree

4 files changed

+22
-37
lines changed

4 files changed

+22
-37
lines changed

lld/ELF/Driver.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,7 +1629,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
16291629
std::make_pair("gcs-report", &ctx.arg.zGcsReport),
16301630
std::make_pair("gcs-report-dynamic", &ctx.arg.zGcsReportDynamic),
16311631
std::make_pair("pauth-report", &ctx.arg.zPauthReport)};
1632-
bool zGcsReportDynamicDefined = false;
1632+
bool hasGcsReportDynamic = false;
16331633
for (opt::Arg *arg : args.filtered(OPT_z)) {
16341634
std::pair<StringRef, StringRef> option =
16351635
StringRef(arg->getValue()).split('=');
@@ -1641,27 +1641,22 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
16411641
*reportArg.second = ReportPolicy::None;
16421642
else if (option.second == "warning") {
16431643
*reportArg.second = ReportPolicy::Warning;
1644-
// To be able to match the GNU ld inheritance rules for -zgcs-report
1645-
// and -zgcs-report-dynamic, we need to know if -zgcs-report-dynamic
1646-
// has been defined by the user.
1647-
if (option.first == "gcs-report-dynamic")
1648-
zGcsReportDynamicDefined = true;
16491644
} else if (option.second == "error") {
16501645
*reportArg.second = ReportPolicy::Error;
1651-
if (option.first == "gcs-report-dynamic")
1652-
zGcsReportDynamicDefined = true;
16531646
} else {
16541647
ErrAlways(ctx) << "unknown -z " << reportArg.first
16551648
<< "= value: " << option.second;
16561649
continue;
16571650
}
1651+
if (option.first == "gcs-report-dynamic")
1652+
hasGcsReportDynamic = true;
16581653
}
16591654
}
16601655

1661-
if (!zGcsReportDynamicDefined && ctx.arg.zGcsReport != ReportPolicy::None &&
1662-
ctx.arg.zGcsReportDynamic == ReportPolicy::None)
1663-
// When inheriting the -zgcs-report option, it is capped at a `warning` to
1664-
// avoid needing to rebuild the shared library with GCS enabled.
1656+
// When -zgcs-report-dynamic is unspecified, it inherits -zgcs-report
1657+
// but is capped at warning to avoid needing to rebuild the shared library
1658+
// with GCS enabled.
1659+
if (!hasGcsReportDynamic && ctx.arg.zGcsReport != ReportPolicy::None)
16651660
ctx.arg.zGcsReportDynamic = ReportPolicy::Warning;
16661661

16671662
for (opt::Arg *arg : args.filtered(OPT_compress_sections)) {

lld/ELF/InputFiles.cpp

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,30 +1434,23 @@ std::vector<uint32_t> SharedFile::parseVerneed(const ELFFile<ELFT> &obj,
14341434
return verneeds;
14351435
}
14361436

1437-
// To determine if a shared file can support any of the GNU Attributes,
1438-
// the .note.gnu.properties section need to be read. The appropriate
1439-
// location in memory is located then the GnuPropertyNote can be parsed.
1440-
// This is the same process as is used for readGnuProperty, however we
1441-
// do not pass the data variable as, without an InputSection, its value
1442-
// is unknown in a SharedFile. This is ok as the information that would
1443-
// be collected from this is irrelevant for a dynamic object.
1437+
// Parse PT_GNU_PROPERTY segments in DSO. The process is similar to
1438+
// readGnuProperty, but we don't have the InputSection information.
14441439
template <typename ELFT>
1445-
void SharedFile::parseGnuAndFeatures(const uint8_t *base,
1446-
const typename ELFT::PhdrRange headers) {
1447-
if (headers.size() == 0 || ctx.arg.emachine != EM_AARCH64)
1440+
void SharedFile::parseGnuAndFeatures(const ELFFile<ELFT> &obj) {
1441+
if (ctx.arg.emachine != EM_AARCH64)
14481442
return;
1449-
1450-
for (unsigned i = 0; i < headers.size(); i++) {
1451-
if (headers[i].p_type != PT_GNU_PROPERTY)
1443+
const uint8_t *base = obj.base();
1444+
auto phdrs = CHECK2(obj.program_headers(), this);
1445+
for (auto phdr : phdrs) {
1446+
if (phdr.p_type != PT_GNU_PROPERTY)
14521447
continue;
1453-
const typename ELFT::Note note(
1454-
*reinterpret_cast<const typename ELFT::Nhdr *>(base +
1455-
headers[i].p_offset));
1448+
typename ELFT::Note note(
1449+
*reinterpret_cast<const typename ELFT::Nhdr *>(base + phdr.p_offset));
14561450
if (note.getType() != NT_GNU_PROPERTY_TYPE_0 || note.getName() != "GNU")
14571451
continue;
14581452

1459-
// Read a body of a NOTE record, which consists of type-length-value fields.
1460-
ArrayRef<uint8_t> desc = note.getDesc(headers[i].p_align);
1453+
ArrayRef<uint8_t> desc = note.getDesc(phdr.p_align);
14611454
parseGnuPropertyNote<ELFT>(ctx, *this, GNU_PROPERTY_AARCH64_FEATURE_1_AND,
14621455
desc, base);
14631456
}
@@ -1499,12 +1492,10 @@ template <class ELFT> void SharedFile::parse() {
14991492
using Elf_Sym = typename ELFT::Sym;
15001493
using Elf_Verdef = typename ELFT::Verdef;
15011494
using Elf_Versym = typename ELFT::Versym;
1502-
using Elf_Phdr = typename ELFT::Phdr;
15031495

15041496
ArrayRef<Elf_Dyn> dynamicTags;
15051497
const ELFFile<ELFT> obj = this->getObj<ELFT>();
15061498
ArrayRef<Elf_Shdr> sections = getELFShdrs<ELFT>();
1507-
ArrayRef<Elf_Phdr> pHeaders = CHECK2(obj.program_headers(), this);
15081499

15091500
const Elf_Shdr *versymSec = nullptr;
15101501
const Elf_Shdr *verdefSec = nullptr;
@@ -1575,7 +1566,7 @@ template <class ELFT> void SharedFile::parse() {
15751566

15761567
verdefs = parseVerdefs<ELFT>(obj.base(), verdefSec);
15771568
std::vector<uint32_t> verneeds = parseVerneed<ELFT>(obj, verneedSec);
1578-
parseGnuAndFeatures<ELFT>(obj.base(), pHeaders);
1569+
parseGnuAndFeatures<ELFT>(obj);
15791570

15801571
// Parse ".gnu.version" section which is a parallel array for the symbol
15811572
// table. If a given file doesn't have a ".gnu.version" section, we use

lld/ELF/InputFiles.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,7 @@ class SharedFile : public ELFFileBase {
365365
std::vector<uint32_t> parseVerneed(const llvm::object::ELFFile<ELFT> &obj,
366366
const typename ELFT::Shdr *sec);
367367
template <typename ELFT>
368-
void parseGnuAndFeatures(const uint8_t *base,
369-
const typename ELFT::PhdrRange headers);
368+
void parseGnuAndFeatures(const llvm::object::ELFFile<ELFT> &obj);
370369
};
371370

372371
class BinaryFile : public InputFile {

lld/test/ELF/aarch64-feature-gcs.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@
5959
# RUN: ld.lld func1-gcs.o func3-gcs.o force-gcs.so -z gcs-report-dynamic=error -z gcs=always 2>&1 | count 0
6060

6161
# REPORT-WARN-DYNAMIC: warning: no-gcs.so: GCS is required by -z gcs, but this shared library lacks the necessary property note. The dynamic loader might not enable GCS or refuse to load the program unless all shared library dependencies have the GCS marking.
62-
# REPORT-WARN-DYNAMIC-NOT: warning: force-gcs.so: GCS is required by -z gcs, but this shared library lacks the necessary property note. The dynamic loader might not enable GCS or refuse to load the program unless all shared library dependencies have the GCS marking.
62+
# REPORT-WARN-DYNAMIC-NOT: warning:
6363
# REPORT-ERROR-DYNAMIC: error: no-gcs.so: GCS is required by -z gcs, but this shared library lacks the necessary property note. The dynamic loader might not enable GCS or refuse to load the program unless all shared library dependencies have the GCS marking.
64-
# REPORT-ERROR-DYNAMIC-NOT: error: force-gcs.so: GCS is required by -z gcs, but this shared library lacks the necessary property note. The dynamic loader might not enable GCS or refuse to load the program unless all shared library dependencies have the GCS marking.
64+
# REPORT-ERROR-DYNAMIC-NOT: error:
6565

6666
## An invalid gcs option should give an error
6767
# RUN: not ld.lld func1-gcs.o func2-gcs.o func3-gcs.o -z gcs=nonsense -z gcs-report=nonsense -z gcs-report-dynamic=nonsense 2>&1 | FileCheck --check-prefix=INVALID %s

0 commit comments

Comments
 (0)