[PATCH] [lld] Rename variable to avoid system header conflict

Tim Northover t.p.northover at gmail.com
Fri Jun 20 01:20:21 PDT 2014


Hi,

I've started poking around with lld, and noticed that it doesn't build
on OS X at the moment because the PAGE_SIZE variable conflicts with a
predefine in one of the system headers (pulled in via pthreads.h, by
the looks of it).

The attached patch renames it to X86_PAGE_SIZE to avoid this. Is it OK
to commit?

Cheers.

Tim.
-------------- next part --------------
commit f9b4a38b6cc0ab721a6c849ce13a817269cb7823
Author: Tim Northover <tnorthover at apple.com>
Date:   Thu Jun 19 12:55:48 2014 +0100

    Rename variable to avoid conflict with system headers

diff --git a/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp b/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
index 1ac8d38..358e659 100644
--- a/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
+++ b/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
@@ -57,7 +57,7 @@ namespace pecoff {
 
 // Page size of x86 processor. Some data needs to be aligned at page boundary
 // when loaded into memory.
-static const int PAGE_SIZE = 4096;
+static const int X86_PAGE_SIZE = 4096;
 
 // Disk sector size. Some data needs to be aligned at disk sector boundary in
 // file.
@@ -787,7 +787,7 @@ BaseRelocChunk::listRelocSites(ChunkVectorT &chunks) const {
 BaseRelocChunk::PageOffsetT
 BaseRelocChunk::groupByPage(const std::vector<uint64_t> &relocSites) const {
   PageOffsetT blocks;
-  uint64_t mask = static_cast<uint64_t>(PAGE_SIZE) - 1;
+  uint64_t mask = static_cast<uint64_t>(X86_PAGE_SIZE) - 1;
   for (uint64_t addr : relocSites)
     blocks[addr & ~mask].push_back(addr & mask);
   return blocks;
@@ -815,7 +815,7 @@ std::vector<uint8_t> BaseRelocChunk::createBaseRelocBlock(
 
   // The rest of the block consists of offsets in the page.
   for (uint16_t offset : offsets) {
-    assert(offset < PAGE_SIZE);
+    assert(offset < X86_PAGE_SIZE);
     uint16_t val = (llvm::COFF::IMAGE_REL_BASED_HIGHLOW << 12) | offset;
     *reinterpret_cast<ulittle16_t *>(ptr) = val;
     ptr += sizeof(ulittle16_t);
@@ -828,7 +828,7 @@ std::vector<uint8_t> BaseRelocChunk::createBaseRelocBlock(
 class PECOFFWriter : public Writer {
 public:
   explicit PECOFFWriter(const PECOFFLinkingContext &context)
-      : _ctx(context), _numSections(0), _imageSizeInMemory(PAGE_SIZE),
+      : _ctx(context), _numSections(0), _imageSizeInMemory(X86_PAGE_SIZE),
         _imageSizeOnDisk(0) {}
 
   template <class PEHeader> void build(const File &linkedFile);
@@ -863,9 +863,9 @@ private:
   const PECOFFLinkingContext &_ctx;
   uint32_t _numSections;
 
-  // The size of the image in memory. This is initialized with PAGE_SIZE, as the
-  // first page starting at ImageBase is usually left unmapped. IIUC there's no
-  // technical reason to do so, but we'll follow that convention so that we
+  // The size of the image in memory. This is initialized with X86_PAGE_SIZE, as
+  // the first page starting at ImageBase is usually left unmapped. IIUC there's
+  // no technical reason to do so, but we'll follow that convention so that we
   // don't produce odd-looking binary.
   uint32_t _imageSizeInMemory;
 
@@ -1132,8 +1132,8 @@ void PECOFFWriter::addSectionChunk(SectionChunk *chunk,
   // memory. They are different from positions on disk because sections need
   // to be sector-aligned on disk but page-aligned in memory.
   chunk->setVirtualAddress(_imageSizeInMemory);
-  _imageSizeInMemory =
-      llvm::RoundUpToAlignment(_imageSizeInMemory + chunk->size(), PAGE_SIZE);
+  _imageSizeInMemory = llvm::RoundUpToAlignment(
+      _imageSizeInMemory + chunk->size(), X86_PAGE_SIZE);
 }
 
 void PECOFFWriter::setImageSizeOnDisk() {


More information about the llvm-commits mailing list