Golang学习笔记 - 1. 程序启动入口

Go编译生成的是一个可执行文件,因此可以使用相关的工具来查看可执行文件的程序入口

使用gobjdump查看程序入口

以生成的 helloworld 文件为例

由于使用的是mac,所以使用gobjdump来查看

1. 安装 gobjdump

brew update && brew install binutils

2. 找到程序的入口地址

执行 gobjdump -f helloworld  返回如下

helloworld:     file format mach-o-x86-64
architecture: i386:x86-64, flags 0x00000012:
EXEC_P, HAS_SYMS
start address 0x000000000105c780

 可以看到,程序的开始地址为 0x000000000105c780

3. 找到对应地址

执行 gobjdump -x helloworld | grep 000000000105c780 

打印如下,即我们程序的入口是 _rt0_amd64_daewin

000000000105c780 l       0e SECT   01 0000 [.text] __rt0_amd64_darwin

4. 找到对应的go源码 

从源码中 runtime 包中可以找到对应的文件 runtime/rt0_darwin_amd64.s

// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

#include "textflag.h"

TEXT _rt0_amd64_darwin(SB),NOSPLIT,$-8
	JMP	_rt0_amd64(SB)

// When linking with -shared, this symbol is called when the shared library
// is loaded.
TEXT _rt0_amd64_darwin_lib(SB),NOSPLIT,$0
	JMP	_rt0_amd64_lib(SB)

5. 顺着方法便可以一路找到程序的入口了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值