readelf 查看“派生类”的vtable符号

一、查看 .rodata

c 复制代码
ubuntu@aaa $ readelf -x .rodata a.out

Hex dump of section '.rodata':
  0x00002000 01000200 00000000 02000000 00000000 ................
  0x00002010 20204465 72697665 6420636c 61737320   Derived class
  0x00002020 6f626a65 63742069 73206372 65617465 object is create
  0x00002030 6420616e 64206675 6e637469 6f6e2066 d and function f
  0x00002040 28292069 73206361 6c6c6564 2e000000 () is called....
  0x00002050 37446572 69766564 00344261 736500   7Derived.4Base.

ubuntu@aaa $

二、grep vtable没有结果

ubuntu@aaa$ readelf -x .rodata a.out |grep vtalbe

ubuntu@aaa $

三、虚函数除了声明,还需要定义

c 复制代码
ubuntu@aa $ g++ polymorph.cpp
/usr/bin/ld: /tmp/ccstK1jB.o: 
warning: 
relocation against `_ZTV4Base' in read-only section `.text._ZN4BaseC2Ev[_ZN4BaseC5Ev]'

/usr/bin/ld: /tmp/ccstK1jB.o: 
in function `Base::Base()':
polymorph.cpp:
(.text._ZN4BaseC2Ev[_ZN4BaseC5Ev]+0xf): 
undefined reference to `vtable for Base'

/usr/bin/ld: /tmp/ccstK1jB.o: 
in function `Derived::Derived()':
polymorph.cpp:
(.text._ZN7DerivedC2Ev[_ZN7DerivedC5Ev]+0x1f): 
undefined reference to `vtable for Derived'

/usr/bin/ld: warning: 
creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status

ubuntu@aa $
相关推荐
SEO_juper40 分钟前
Node.js 全站 SEO 体检报告生成器:一次查完标题、描述、canonical、H1、图片
开发语言·前端·node.js·html·bash
风落青芜1 小时前
数据结构:堆的概念与实现
c语言·开发语言·数据结构·算法
H H.4 小时前
Java企业级开发:从框架到工程化实战
java·开发语言·经验分享·其他·课程设计
吃我一窝jio16 小时前
Python与Go线程模型深度对比
java·开发语言·python
eggwyw16 小时前
C++ union 的一种妙用法
开发语言·c++
ShineWinsu18 小时前
对于Qt:QHBoxLayout常见属性以及方法的解析
c++·qt·面试·gui·客户端·布局管理器·水平布局器
starzy199018 小时前
深入理解Scala隐式函数:自动类型转换
开发语言·后端·scala
小七在进步19 小时前
string的实现(1)
c++·笔记·visual studio
布莱克60520 小时前
Swift 循环与控制转移详解:从 for-in 到标签跳转
开发语言·ssh·swift·循环
敲上瘾21 小时前
Qt核心机制:信号与槽详解
开发语言·c++·qt·ui·qt6.3