[PATCH] D81298: [lld-macho] Handle alignment correctly when merging InputSections
Jez Ng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 5 12:57:29 PDT 2020
int3 updated this revision to Diff 268916.
int3 added a comment.
rename i -> isec for consistency
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D81298/new/
https://reviews.llvm.org/D81298
Files:
lld/MachO/MergedOutputSection.cpp
lld/test/MachO/section-merge.s
Index: lld/test/MachO/section-merge.s
===================================================================
--- lld/test/MachO/section-merge.s
+++ lld/test/MachO/section-merge.s
@@ -1,31 +1,19 @@
# REQUIRES: x86
# RUN: mkdir -p %t
-# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libhello.s \
-# RUN: -o %t/libhello.o
-# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libgoodbye.s \
-# RUN: -o %t/libgoodbye.o
-# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libfunction.s \
-# RUN: -o %t/libfunction.o
-# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s \
-# RUN: -o %t/main.o
-# RUN: lld -flavor darwinnew -o %t/output %t/libfunction.o %t/libgoodbye.o %t/libhello.o %t/main.o
+## Verify that we preserve alignment when merging sections.
+# RUN: echo ".globl _foo; .data; .p2align 0; _foo: .space 1" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/foo.o
+# RUN: echo ".globl _bar; .data; .p2align 2; _bar: .space 1" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/bar.o
+# RUN: echo ".globl _baz; .data; .p2align 3; _baz: .space 1" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/baz.o
+# RUN: echo ".globl _qux; .data; .p2align 0; _qux: .space 1" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/qux.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/main.o
+# RUN: lld -flavor darwinnew -o %t/output %t/foo.o %t/bar.o %t/baz.o %t/qux.o %t/main.o
# RUN: llvm-objdump --syms %t/output | FileCheck %s
-# CHECK: SYMBOL TABLE:
-# CHECK-DAG: {{[0-9a-z]+}} g O __TEXT,__cstring _goodbye_world
-# CHECK-DAG: {{[0-9a-z]+}} g O __TEXT,__cstring _hello_its_me
-# CHECK-DAG: {{[0-9a-z]+}} g O __TEXT,__cstring _hello_world
-# CHECK-DAG: {{[0-9a-z]+}} g F __TEXT,__text _main
-# CHECK-DAG: {{[0-9a-z]+}} g F __TEXT,__text _some_function
-
-# RUN: llvm-objdump -d %t/output | FileCheck %s --check-prefix DATA
-# DATA: Disassembly of section __TEXT,__text:
-# DATA: {{0*}}[[#%x,BASE:]] <_some_function>:
-# DATA-NEXT: [[#BASE]]: 48 c7 c0 01 00 00 00 movq $1, %rax
-# DATA-NEXT: [[#BASE + 0x7]]: c3 retq
-# DATA: {{0*}}[[#%x,MAIN:]] <_main>:
-# DATA-NEXT: [[#MAIN]]: 48 c7 c0 00 00 00 00 movq $0, %rax
-# DATA-NEXT: [[#MAIN + 0x7]]: c3 retq
+# CHECK: SYMBOL TABLE:
+# CHECK-DAG: [[#%x, ADDR:]] g O __DATA,__data _foo
+# CHECK-DAG: {{0*}}[[#ADDR+0x4]] g O __DATA,__data _bar
+# CHECK-DAG: {{0*}}[[#ADDR+0x8]] g O __DATA,__data _baz
+# CHECK-DAG: {{0*}}[[#ADDR+0x9]] g O __DATA,__data _qux
.section __TEXT,__text
.global _main
Index: lld/MachO/MergedOutputSection.cpp
===================================================================
--- lld/MachO/MergedOutputSection.cpp
+++ lld/MachO/MergedOutputSection.cpp
@@ -32,11 +32,13 @@
void MergedOutputSection::finalize() {
uint64_t isecAddr = addr;
uint64_t isecFileOff = fileOff;
- for (InputSection *i : inputs) {
- i->outSecOff = alignTo(isecAddr, i->align) - addr;
- i->outSecFileOff = alignTo(isecFileOff, i->align) - fileOff;
- isecAddr += i->getSize();
- isecFileOff += i->getFileSize();
+ for (InputSection *isec : inputs) {
+ isecAddr = alignTo(isecAddr, isec->align);
+ isecFileOff = alignTo(isecFileOff, isec->align);
+ isec->outSecOff = isecAddr - addr;
+ isec->outSecFileOff = isecFileOff - fileOff;
+ isecAddr += isec->getSize();
+ isecFileOff += isec->getFileSize();
}
size = isecAddr - addr;
fileSize = isecFileOff - fileOff;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81298.268916.patch
Type: text/x-patch
Size: 3648 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200605/f2fb81f0/attachment.bin>
More information about the llvm-commits
mailing list