[llvm] r233390 - Add a -raw option to the -section mode of llvm-objdump.

Adrian Prantl aprantl at apple.com
Fri Mar 27 11:31:12 PDT 2015


> On Mar 27, 2015, at 11:28 AM, Kevin Enderby <enderby at apple.com> wrote:
> 
> 
>> On Mar 27, 2015, at 11:22 AM, Adrian Prantl <aprantl at apple.com> wrote:
>> 
>> 
>>> On Mar 27, 2015, at 11:10 AM, Kevin Enderby <enderby at apple.com> wrote:
>>> 
>>> 
>>>> On Mar 27, 2015, at 10:57 AM, Adrian Prantl <aprantl at apple.com> wrote:
>>>> 
>>>> 
>>>>> On Mar 27, 2015, at 10:51 AM, Kevin Enderby <enderby at apple.com> wrote:
>>>>> 
>>>>> Hi Adrian,
>>>>> 
>>>>> I think adding the -non-verbose option already does what your -raw option does with the -macho option.  Why do you feel there is a need for this additional option?
>>>>> 
>>>>> My thinking for the use of llvm-objdump with the -macho option is to default to verbose output and allowing the -non-verbose option for the "numeric form” or “raw” for as you call it.
>>>> 
>>>> Hi Kevin,
>>>> 
>>>> I probably should have talked to you first, sorry.
>>>> The -non-verbose option still outputs a hexdump, whereas -raw can be used to extract the raw binary contents of a section so it can be piped to other tools. Do you think there is a better tool or option to use for this kind of functionality?
>>> 
>>> What tool did you previously use on Mac OS X to do this?  It seems this is “new” functionality.  I worry about the headers being printed with fat files, archives etc to make this functionality really useful in the full context of llvm-objdump’s existing functionality.
>>> 
>>> I’m not sure what the best tool for the job your doing.  Maybe readobj would be better?  But I honestly don’t know.  The goal I have been working towards is to get the Mac OS X functionality of otool(1) into llvm-objdump under its -macho option.  And that output is to be human readable.
>>> 
>>> Not sure what tool one would use to dump raw binary from parts of a Mach-O file.  Can you describe your use case?
>> 
>> For module debugging, we are planning to wrap clang module files in an ELF/COFF/Mach-O container containing debug information and the serialized clang AST. In order to still be able to run tools like llvm-bcanalyzer on the clang AST in the container being able to construct a pipe like
>> llvm-objdump -section=__clang_ast -raw | llvm-bcanalyzer
>> would be very convenient.
> 
> Well if your going to do this for ELF/COFF as well as Mach-O wouldn’t it be better to have a high level option on llvm-objdump that knows the conventions of where the "clang module file” is in each object file format?  Maybe:
> 
> llvm-objdump -raw-clang-ast SomeObject | llvm-bcanalyzer
> 
> Then to make this a -macho specific option to use with the Mach-O specific -section option?

I think that’s a good idea.

thanks,
adrian

> 
>> 
>> -- adrian
>> 
>>> 
>>>> 
>>>> -- adrian
>>>> 
>>>> 
>>>>> 
>>>>> Kev
>>>>> 
>>>>>> On Mar 27, 2015, at 10:31 AM, Adrian Prantl <aprantl at apple.com> wrote:
>>>>>> 
>>>>>> Author: adrian
>>>>>> Date: Fri Mar 27 12:31:15 2015
>>>>>> New Revision: 233390
>>>>>> 
>>>>>> URL: http://llvm.org/viewvc/llvm-project?rev=233390&view=rev
>>>>>> Log:
>>>>>> Add a -raw option to the -section mode of llvm-objdump.
>>>>>> 
>>>>>> Added:
>>>>>> llvm/trunk/test/tools/llvm-objdump/macho-sections.test
>>>>>> Modified:
>>>>>> llvm/trunk/tools/llvm-objdump/MachODump.cpp
>>>>>> llvm/trunk/tools/llvm-objdump/llvm-objdump.h
>>>>>> 
>>>>>> Added: llvm/trunk/test/tools/llvm-objdump/macho-sections.test
>>>>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/macho-sections.test?rev=233390&view=auto
>>>>>> ==============================================================================
>>>>>> --- llvm/trunk/test/tools/llvm-objdump/macho-sections.test (added)
>>>>>> +++ llvm/trunk/test/tools/llvm-objdump/macho-sections.test Fri Mar 27 12:31:15 2015
>>>>>> @@ -0,0 +1,5 @@
>>>>>> +# RUN: llvm-objdump -macho -section=__data %p/Inputs/bind2.macho-x86_64 | FileCheck %s
>>>>>> +# RUN: llvm-objdump -macho -section=__data -raw %p/Inputs/bind2.macho-x86_64 | FileCheck --check-prefix=RAW %s
>>>>>> +
>>>>>> +# CHECK: bind2.macho-x86_64:
>>>>>> +# RAW-NOT: bind2.macho-x86_64:
>>>>>> 
>>>>>> Modified: llvm/trunk/tools/llvm-objdump/MachODump.cpp
>>>>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/MachODump.cpp?rev=233390&r1=233389&r2=233390&view=diff
>>>>>> ==============================================================================
>>>>>> --- llvm/trunk/tools/llvm-objdump/MachODump.cpp (original)
>>>>>> +++ llvm/trunk/tools/llvm-objdump/MachODump.cpp Fri Mar 27 12:31:15 2015
>>>>>> @@ -99,6 +99,9 @@ cl::list<std::string>
>>>>>>                   cl::desc("Prints the specified segment,section for "
>>>>>>                            "Mach-O objects (requires -macho)"));
>>>>>> 
>>>>>> +cl::opt<bool> llvm::Raw("raw",
>>>>>> +                        cl::desc("Have -section dump the raw binary contents"));
>>>>>> +
>>>>>> cl::opt<bool>
>>>>>> llvm::InfoPlist("info-plist",
>>>>>>                cl::desc("Print the info plist section as strings for "
>>>>>> @@ -1043,8 +1046,7 @@ static void DumpSectionContents(StringRe
>>>>>>  StringRef SegName = O->getSectionFinalSegmentName(Ref);
>>>>>>  if ((DumpSegName.empty() || SegName == DumpSegName) &&
>>>>>>      (SectName == DumpSectName)) {
>>>>>> -        outs() << "Contents of (" << SegName << "," << SectName
>>>>>> -               << ") section\n";
>>>>>> +
>>>>>>    uint32_t section_flags;
>>>>>>    if (O->is64Bit()) {
>>>>>>      const MachO::section_64 Sec = O->getSection64(Ref);
>>>>>> @@ -1062,6 +1064,14 @@ static void DumpSectionContents(StringRe
>>>>>>    uint32_t sect_size = BytesStr.size();
>>>>>>    uint64_t sect_addr = Section.getAddress();
>>>>>> 
>>>>>> +        if (Raw) {
>>>>>> +          outs().write(BytesStr.data(), BytesStr.size());
>>>>>> +          continue;
>>>>>> +        }
>>>>>> +
>>>>>> +        outs() << "Contents of (" << SegName << "," << SectName
>>>>>> +               << ") section\n";
>>>>>> +
>>>>>>    if (verbose) {
>>>>>>      if ((section_flags & MachO::S_ATTR_PURE_INSTRUCTIONS) ||
>>>>>>          (section_flags & MachO::S_ATTR_SOME_INSTRUCTIONS)) {
>>>>>> @@ -1181,7 +1191,7 @@ static void ProcessMachO(StringRef Filen
>>>>>> // UniversalHeaders or ArchiveHeaders.
>>>>>> if (Disassemble || PrivateHeaders || ExportsTrie || Rebase || Bind ||
>>>>>>  LazyBind || WeakBind || IndirectSymbols || DataInCode || LinkOptHints ||
>>>>>> -      DylibsUsed || DylibId || DumpSections.size() != 0) {
>>>>>> +      DylibsUsed || DylibId || (DumpSections.size() != 0 && !Raw)) {
>>>>>> outs() << Filename;
>>>>>> if (!ArchiveMemberName.empty())
>>>>>>  outs() << '(' << ArchiveMemberName << ')';
>>>>>> 
>>>>>> Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.h
>>>>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.h?rev=233390&r1=233389&r2=233390&view=diff
>>>>>> ==============================================================================
>>>>>> --- llvm/trunk/tools/llvm-objdump/llvm-objdump.h (original)
>>>>>> +++ llvm/trunk/tools/llvm-objdump/llvm-objdump.h Fri Mar 27 12:31:15 2015
>>>>>> @@ -27,6 +27,7 @@ extern cl::opt<std::string> ArchName;
>>>>>> extern cl::opt<std::string> MCPU;
>>>>>> extern cl::list<std::string> MAttrs;
>>>>>> extern cl::list<std::string> DumpSections;
>>>>>> +extern cl::opt<bool> Raw;
>>>>>> extern cl::opt<bool> Disassemble;
>>>>>> extern cl::opt<bool> NoShowRawInsn;
>>>>>> extern cl::opt<bool> PrivateHeaders;
>>>>>> 
>>>>>> 
>>>>>> _______________________________________________
>>>>>> llvm-commits mailing list
>>>>>> llvm-commits at cs.uiuc.edu
>>>>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>>>> 
>>>> 
>>> 
>> 
> 





More information about the llvm-commits mailing list