Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug/macho: Invalid index reference in macho file Dysyms.IndirectSyms #10178

Closed
gcmurphy opened this issue Mar 16, 2015 · 4 comments
Closed

Comments

@gcmurphy
Copy link

I may be misunderstanding the expected usage of debug/macho but I'm encountering the following and it doesn't seem correct to me.

The godoc for the macho package has this definition:

 type Dysymtab struct {
        LoadBytes
        DysymtabCmd
        IndirectSyms []uint32 // indices into Symtab.Syms
}

So I would expect given the c program:

#include <stdio.h>
int main(void){
    puts("Hello World");
}

/*
$ gcc foo.c -o foo
$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
*/

And reading the symbols using the following go code:

package main

import (
    "debug/macho"
    "fmt"
    "os"
)

func main(){

    for _, path := range os.Args[1:] {

        file, err := macho.Open(path)
        if err != nil {
            fmt.Printf("error: could not open macho file: %v - %v\n", path, err)
            os.Exit(1)
        }
        defer file.Close()

        fmt.Printf("Dysymtab for %v\n", path)
        for _, index := range file.Dysymtab.IndirectSyms {
            if index < uint32(len(file.Symtab.Syms)) {
                fmt.Println(file.Symtab.Syms[index].Name)
            } else {
                fmt.Printf("wtf? >>>>>> %v, max = %v\n", index, len(file.Symtab.Syms))
            }
        }

    }
}

To not see this in the output:

$ go run testcase.go a.out  | grep wtf
wtf? >>>>>> 1073741824, max = 4

This looks suspect to me. Although I may be using the library incorrectly.

@gcmurphy
Copy link
Author

Sorry the version of go I'm using is -

$ go version
go version go1.4.1 darwin/amd64

@mikioh mikioh changed the title Invalid index reference in macho file Dysyms.IndirectSyms debug/macho: Invalid index reference in macho file Dysyms.IndirectSyms Mar 16, 2015
@minux
Copy link
Member

minux commented Mar 16, 2015 via email

@minux
Copy link
Member

minux commented Mar 16, 2015

Just FYI, in /usr/include/mach-o/loader.h, we have

#define INDIRECT_SYMBOL_ABS     0x40000000

And sure enough 0x40000000 == 1073741824.

@minux minux closed this as completed Mar 16, 2015
@gcmurphy
Copy link
Author

Thanks.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants