[PATCH] D70212: [llvm-objcopy][MachO] Implement --redefine-sym and --redefine-syms

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 14 09:57:05 PST 2019


MaskRay marked an inline comment as done.
MaskRay added inline comments.


================
Comment at: llvm/test/tools/llvm-objcopy/MachO/redefine-symbol.s:3
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos %s -o %t
+
----------------
jhenderson wrote:
> Any reason you're not using yaml2obj for this?
A YAML test file would be verbose:

```
--- !mach-o
FileHeader:
  magic:           0xFEEDFACF
  cputype:         0x01000007
  cpusubtype:      0x00000003
  filetype:        0x00000001
  ncmds:           3
  sizeofcmds:      336
  flags:           0x00000000
  reserved:        0x00000000
LoadCommands:
  - cmd:             LC_SEGMENT_64
    cmdsize:         232
    segname:         ''
    vmaddr:          0
    vmsize:          0
    fileoff:         368
    filesize:        0
    maxprot:         7
    initprot:        7
    nsects:          2
    flags:           0
    Sections:
      - sectname:        __text
        segname:         __TEXT
        addr:            0x0000000000000000
        size:            0
        offset:          0x00000170
        align:           0
        reloff:          0x00000000
        nreloc:          0
        flags:           0x80000000
        reserved1:       0x00000000
        reserved2:       0x00000000
        reserved3:       0x00000000
        content:         ''
      - sectname:        __const
        segname:         __TEXT
        addr:            0x0000000000000000
        size:            0
        offset:          0x00000170
        align:           0
        reloff:          0x00000000
        nreloc:          0
        flags:           0x00000000
        reserved1:       0x00000000
        reserved2:       0x00000000
        reserved3:       0x00000000
        content:         ''
  - cmd:             LC_SYMTAB
    cmdsize:         24
    symoff:          368
    nsyms:           2
    stroff:          400
    strsize:         12
  - cmd:             LC_DYSYMTAB
    cmdsize:         80
    ilocalsym:       0
    nlocalsym:       0
    iextdefsym:      0
    nextdefsym:      2
    iundefsym:       2
    nundefsym:       0
    tocoff:          0
    ntoc:            0
    modtaboff:       0
    nmodtab:         0
    extrefsymoff:    0
    nextrefsyms:     0
    indirectsymoff:  0
    nindirectsyms:   0
    extreloff:       0
    nextrel:         0
    locreloff:       0
    nlocrel:         0
LinkEditData:
  NameList:
    - n_strx:          1
      n_type:          0x0F
      n_sect:          2
      n_desc:          0
      n_value:         0
    - n_strx:          6
      n_type:          0x0F
      n_sect:          1
      n_desc:          0
      n_value:         0
  StringTable:
    - ''
    - _foo
    - _func
...
```

Most fields of `MachOYAML::Section` (see `lib/ObjectYAML/MachOYAML.cpp`:276) are required. I feel that replicating what we do for ELF may not be very good for MachO. We can probably change the assembly test to YAML when the YAML files used by yaml2obj/obj2yaml become more succinct.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70212/new/

https://reviews.llvm.org/D70212





More information about the llvm-commits mailing list