[llvm] r269303 - [ObjectYAML] Support Thin MachO headers to YAML

Chris Bieneman via llvm-commits llvm-commits at lists.llvm.org
Thu May 12 10:33:37 PDT 2016


I do want to handle that too. I’m new to YAML and haven’t yet figured out how I want to handle the optional field.

My next set of commits is adding yaml2obj support for mach_header structs and the first set of tests. I’ll look into figuring out how to handle the reserved field after that.

-Chris

> On May 12, 2016, at 10:20 AM, Kevin Enderby <enderby at apple.com> wrote:
> 
> Hi Chris,
> 
> For 64-bit Mach-O do you also want to handle the last 32-bit “reserved” field?  As the 32-bit and 64-bit Mach-O headers differ by this to get 8-byte alignment in the latter case.  While this field should always be zero today I could see some day this being used for something.
> 
> My thoughts,
> Kev
> 
>> On May 12, 2016, at 9:04 AM, Chris Bieneman via llvm-commits <llvm-commits at lists.llvm.org> wrote:
>> 
>> Author: cbieneman
>> Date: Thu May 12 11:04:16 2016
>> New Revision: 269303
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=269303&view=rev
>> Log:
>> [ObjectYAML] Support Thin MachO headers to YAML
>> 
>> This patch adds support to ObjectYAML for serializing mach_header structs.
>> 
>> Added:
>>   llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h
>>   llvm/trunk/lib/ObjectYAML/MachOYAML.cpp
>> Modified:
>>   llvm/trunk/lib/ObjectYAML/CMakeLists.txt
>> 
>> Added: llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h?rev=269303&view=auto
>> ==============================================================================
>> --- llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h (added)
>> +++ llvm/trunk/include/llvm/ObjectYAML/MachOYAML.h Thu May 12 11:04:16 2016
>> @@ -0,0 +1,53 @@
>> +//===- MachOYAML.h - Mach-O YAMLIO implementation ---------------*- C++ -*-===//
>> +//
>> +//                     The LLVM Compiler Infrastructure
>> +//
>> +// This file is distributed under the University of Illinois Open Source
>> +// License. See LICENSE.TXT for details.
>> +//
>> +//===----------------------------------------------------------------------===//
>> +///
>> +/// \file
>> +/// \brief This file declares classes for handling the YAML representation
>> +/// of Mach-O.
>> +///
>> +//===----------------------------------------------------------------------===//
>> +
>> +#ifndef LLVM_OBJECTYAML_MACHOYAML_H
>> +#define LLVM_OBJECTYAML_MACHOYAML_H
>> +
>> +#include "llvm/ObjectYAML/YAML.h"
>> +#include "llvm/Support/MachO.h"
>> +
>> +namespace llvm {
>> +namespace MachOYAML {
>> +
>> +struct FileHeader {
>> +  llvm::yaml::Hex32 cputype;
>> +  llvm::yaml::Hex32 cpusubtype;
>> +  llvm::yaml::Hex32 filetype;
>> +  uint32_t ncmds;
>> +  llvm::yaml::Hex32 flags;
>> +};
>> +
>> +struct Object {
>> +  FileHeader Header;
>> +};
>> +
>> +} // namespace llvm::MachOYAML
>> +
>> +namespace yaml {
>> +
>> +template <> struct MappingTraits<MachOYAML::FileHeader> {
>> +  static void mapping(IO &IO, MachOYAML::FileHeader &FileHeader);
>> +};
>> +
>> +template <> struct MappingTraits<MachOYAML::Object> {
>> +  static void mapping(IO &IO, MachOYAML::Object &Object);
>> +};
>> +
>> +} // namespace llvm::yaml
>> +
>> +} // namespace llvm
>> +
>> +#endif
>> 
>> Modified: llvm/trunk/lib/ObjectYAML/CMakeLists.txt
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/CMakeLists.txt?rev=269303&r1=269302&r2=269303&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/ObjectYAML/CMakeLists.txt (original)
>> +++ llvm/trunk/lib/ObjectYAML/CMakeLists.txt Thu May 12 11:04:16 2016
>> @@ -2,4 +2,5 @@ add_llvm_library(LLVMObjectYAML
>>  YAML.cpp
>>  COFFYAML.cpp
>>  ELFYAML.cpp
>> +  MachOYAML.cpp
>>  )
>> 
>> Added: llvm/trunk/lib/ObjectYAML/MachOYAML.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ObjectYAML/MachOYAML.cpp?rev=269303&view=auto
>> ==============================================================================
>> --- llvm/trunk/lib/ObjectYAML/MachOYAML.cpp (added)
>> +++ llvm/trunk/lib/ObjectYAML/MachOYAML.cpp Thu May 12 11:04:16 2016
>> @@ -0,0 +1,44 @@
>> +//===- MachOYAML.cpp - MachO YAMLIO implementation ------------------------===//
>> +//
>> +//                     The LLVM Compiler Infrastructure
>> +//
>> +// This file is distributed under the University of Illinois Open Source
>> +// License. See LICENSE.TXT for details.
>> +//
>> +//===----------------------------------------------------------------------===//
>> +//
>> +// This file defines classes for handling the YAML representation of MachO.
>> +//
>> +//===----------------------------------------------------------------------===//
>> +
>> +#include "llvm/ObjectYAML/MachOYAML.h"
>> +#include "llvm/Support/Casting.h"
>> +
>> +namespace llvm {
>> +
>> +namespace yaml {
>> +
>> +void MappingTraits<MachOYAML::FileHeader>::mapping(
>> +    IO &IO, MachOYAML::FileHeader &FileHdr) {
>> +  IO.mapRequired("cputype", FileHdr.cputype);
>> +  IO.mapRequired("cpusubtype", FileHdr.cpusubtype);
>> +  IO.mapOptional("filetype", FileHdr.filetype);
>> +  IO.mapRequired("ncmds", FileHdr.ncmds);
>> +  IO.mapRequired("flags", FileHdr.flags);
>> +}
>> +
>> +void MappingTraits<MachOYAML::Object>::mapping(IO &IO,
>> +                                               MachOYAML::Object &Object) {
>> +  // If the context isn't already set, tag the document as !mach-o.
>> +  // For Fat files there will be a different tag so they can be differentiated.
>> +  if(!IO.getContext()) {
>> +    IO.setContext(&Object);
>> +    IO.mapTag("!mach-o", true);
>> +  }
>> +  IO.mapRequired("FileHeader", Object.Header);
>> +  IO.setContext(nullptr);
>> +}
>> +
>> +} // namespace llvm::yaml
>> +
>> +} // namespace llvm
>> 
>> 
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
> 



More information about the llvm-commits mailing list