[lld] 4e907e9 - [ELF] -M/-Map: fix VMA/LMA/Size columns of symbol assignments when address/size>=2**32

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 7 10:15:23 PDT 2020


Author: Fangrui Song
Date: 2020-04-07T10:15:15-07:00
New Revision: 4e907e93fb42eff4ffc9a93026d1665de503acc9

URL: https://github.com/llvm/llvm-project/commit/4e907e93fb42eff4ffc9a93026d1665de503acc9
DIFF: https://github.com/llvm/llvm-project/commit/4e907e93fb42eff4ffc9a93026d1665de503acc9.diff

LOG: [ELF] -M/-Map: fix VMA/LMA/Size columns of symbol assignments when address/size>=2**32

SymbolAssignment::addr stores the location counter. The type should be
uint64_t instead of unsigned. The upper half of the address space is
commonly used by operating system kernels.

Similarly, SymbolAssignment::size should be an uint64_t. A kernel linker
script can move the location counter from 0 to the upper half of the
address space.

Reviewed By: grimar

Differential Revision: https://reviews.llvm.org/D77445

Added: 
    lld/test/ELF/map-file-64bit.s

Modified: 
    lld/ELF/LinkerScript.h

Removed: 
    


################################################################################
diff  --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h
index 66ff79c32678..b21a6f35170e 100644
--- a/lld/ELF/LinkerScript.h
+++ b/lld/ELF/LinkerScript.h
@@ -109,11 +109,11 @@ struct SymbolAssignment : BaseCommand {
   std::string commandString;
 
   // Address of this assignment command.
-  unsigned addr;
+  uint64_t addr;
 
   // Size of this assignment command. This is usually 0, but if
   // you move '.' this may be greater than 0.
-  unsigned size;
+  uint64_t size;
 };
 
 // Linker scripts allow additional constraints to be put on output sections.

diff  --git a/lld/test/ELF/map-file-64bit.s b/lld/test/ELF/map-file-64bit.s
new file mode 100644
index 000000000000..274a8c51518c
--- /dev/null
+++ b/lld/test/ELF/map-file-64bit.s
@@ -0,0 +1,19 @@
+# REQUIRES: x86
+## Test how we display the upper half of the address space, which is commonly
+## used by operating system kernels.
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64 /dev/null -o %t.o
+# RUN: ld.lld -M -T %s %t.o -o /dev/null | FileCheck %s --match-full-lines --strict-whitespace
+
+## . = 0xffffffff80000000; has a misaligned Size column.
+#      CHECK:             VMA              LMA     Size Align Out     In      Symbol
+# CHECK-NEXT:               0                0 ffffffff80000000     1 . = 0xffffffff80000000
+# CHECK-NEXT:ffffffff80000000                0   100000     1 . += 0x100000
+# CHECK-NEXT:ffffffff80100000                0        0     1 _text = .
+# CHECK-NEXT:ffffffff80100000 ffffffff80100000        0     4 .text
+
+SECTIONS {
+  . = 0xffffffff80000000;
+  . += 0x100000;
+  _text = .;
+}


        


More information about the llvm-commits mailing list