[PATCH] D112500: [lld-macho] Put GOT into `__DATA` segment where appropriate

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 25 17:08:59 PDT 2021


int3 created this revision.
int3 added a reviewer: lld-macho.
Herald added a reviewer: gkm.
Herald added a project: lld-macho.
int3 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

We were previously always emitting the GOT into `__DATA_CONST`, even for
target platforms where it should end up in `__DATA`.

I stumbled onto this while trying to use the `class-dump` tool -- with
the wrong segment names, it fails to locate the ObjC runtime info and
therefore fails to dump any classes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D112500

Files:
  lld/MachO/SyntheticSections.cpp
  lld/test/MachO/builtin-rename.s


Index: lld/test/MachO/builtin-rename.s
===================================================================
--- lld/test/MachO/builtin-rename.s
+++ lld/test/MachO/builtin-rename.s
@@ -55,6 +55,23 @@
 # YDATA-DAG: __DATA_CONST,__objc_imageinfo __DATA__objc_imageinfo
 # YDATA-DAG: __DATA_CONST,__nl_symbol_ptr __IMPORT__pointers
 
+## LLD doesn't support defining symbols in synthetic sections, so we test them
+## via this slightly more awkward route.
+# RUN: llvm-readobj --section-headers %t/ydata | \
+# RUN:     FileCheck %s --check-prefix=SYNTH -DSEGNAME=__DATA_CONST
+# RUN: llvm-readobj --section-headers %t/ndata | \
+# RUN:     FileCheck %s --check-prefix=SYNTH -DSEGNAME=__DATA
+# RUN: llvm-readobj --section-headers %t/nopie | \
+# RUN:     FileCheck %s --check-prefix=SYNTH -DSEGNAME=__DATA
+# RUN: llvm-readobj --section-headers %t/old | \
+# RUN:     FileCheck %s --check-prefix=SYNTH -DSEGNAME=__DATA
+
+# SYNTH:      Name: __got
+# SYNTH-NEXT: Segment: [[SEGNAME]] ({{.*}})
+## Note that __la_symbol_ptr always remains in the non-const data segment.
+# SYNTH:      Name: __la_symbol_ptr
+# SYNTH-NEXT: Segment: __DATA ({{.*}})
+
 #--- renames.s
 .section __DATA,__auth_got
 .global __DATA__auth_got
@@ -81,13 +98,6 @@
 __DATA__cfstring:
   .space 8
 
-# FIXME: error: conflicts with synthetic section ...
-# FIXME: we can't explicitly define syms in synthetic sections
-# COM: .section __DATA,__got
-# COM: .global __DATA__got
-# COM: __DATA__got:
-# COM:   .space 8
-
 .section __DATA,__mod_init_func,mod_init_funcs
 .global __DATA__mod_init_func
 __DATA__mod_init_func:
@@ -128,13 +138,6 @@
 __DATA__objc_imageinfo:
   .space 8
 
-# FIXME: error: conflicts with synthetic section ...
-# FIXME: we can't explicitly define syms in synthetic sections
-# COM: .section __DATA,__la_symbol_ptr,lazy_symbol_pointers
-# COM: .global __DATA__la_symbol_ptr
-# COM: __DATA__la_symbol_ptr:
-# COM:   .space 8
-
 .section __IMPORT,__pointers,non_lazy_symbol_pointers
 .global __IMPORT__pointers
 __IMPORT__pointers:
@@ -150,4 +153,6 @@
 .text
 .global _main
 _main:
+  mov ___nan at GOTPCREL(%rip), %rax ## ensure the __got section is created
+  callq ___isnan ## ensure the __la_symbol_ptr section is created
   ret
Index: lld/MachO/SyntheticSections.cpp
===================================================================
--- lld/MachO/SyntheticSections.cpp
+++ lld/MachO/SyntheticSections.cpp
@@ -259,7 +259,7 @@
 }
 
 GotSection::GotSection()
-    : NonLazyPointerSectionBase(segment_names::dataConst, section_names::got) {
+    : NonLazyPointerSectionBase(segment_names::data, section_names::got) {
   flags = S_NON_LAZY_SYMBOL_POINTERS;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112500.382156.patch
Type: text/x-patch
Size: 2649 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211026/cc2d72fa/attachment.bin>


More information about the llvm-commits mailing list