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 $
相关推荐
蒸蒸yyyyzwd1 小时前
cpp 选手秋招学习笔记 day37 面经学习
c++·八股
ctlover1 小时前
排序与查找算法详解
开发语言·python
YYYing.1 小时前
【C++进阶系列 (七)】C++ RTTI 深度剖析:从 typeid 到 dynamic_cast 的底层之旅
开发语言·c++·c/c++·rtti
nvvas3 小时前
Java 入门(四):数组——数据的集合管理
java·开发语言
钓鱼的肝3 小时前
csp-j-s总结(2)
c++·经验分享·笔记·算法·青少年编程
重生的黑客3 小时前
Qt 常用控件精讲(1):QWidget 核心属性全解 —— 从 geometry 到 qrc 与 QSS
c++·qt·qwidget·qss·常用控件
Hespethorn3 小时前
取 `X-Forwarded-For` 首段做频控 key,等于把限流开关交给了调用方
c++
米糕闯编程3 小时前
鱼香ros2(七)功能包组织C++节点
c++·ros2·cmakelists
Y3815326623 小时前
SERP 数据清洗实战:字段标准化、日期解析与去重键
开发语言·数据库·python·python数据库