This improves the portability of the linker script and allows lld to link rom.o

Dot assignment inside an output section has an inconsistent behavior
which makes lld difficult to implement.
See https://bugs.llvm.org/show_bug.cgi?id=43083

Dropping `. =` turns out to be beneficial to older GNU ld as well
because we can delete an ld check detecting "cannot move location
counter backwards".

Signed-off-by: Fangrui Song <mask...@google.com>
---
 scripts/layoutrom.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/scripts/layoutrom.py b/scripts/layoutrom.py
index fa270ef..7bc4a57 100755
--- a/scripts/layoutrom.py
+++ b/scripts/layoutrom.py
@@ -336,14 +336,19 @@ def outRelSections(sections, startsym, useseg=0):
                 if section.finalloc is not None]
     sections.sort(key=operator.itemgetter(0))
     out = ""
+    location = "_reloc_init_end"
     for addr, section in sections:
         loc = section.finalloc
         if useseg:
             loc = section.finalsegloc
-        out += ". = ( 0x%x - %s ) ;\n" % (loc, startsym)
+        if location == "_reloc_init_end":
+            out += ". += 0x%x - %s ;\n" % (loc, location)
+        elif location < loc:
+            out += ". += 0x%x ;\n" % (loc-location,)
         if section.name in ('.rodata.str1.1', '.rodata'):
             out += "_rodata%s = . ;\n" % (section.fileid,)
         out += "*%s.*(%s)\n" % (section.fileid, section.name)
+        location = loc + section.size
     return out
 
 # Build linker script output for a list of relocations.
-- 
2.37.0.144.g8ac04bfd2-goog

_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-le...@seabios.org

Reply via email to