当前位置:网站首页>printf becomes puts
printf becomes puts
2022-06-22 05:40:00 【alex_ mianmian】
Firstly, let's read following simple code:
#include <stdio.h>
int input_number(void)
{
printf("please input numbers:\n");
return 0;
}
int output_number(void)
{
printf("check my implementation");
return 0;
}
int main(int argc, char** argv)
{
input_number();
output_number();
}in function input_number() and output_number(), printf() are called.
After build, will them still be the printf()? Let's dump it.
0000000000001169 <input_number>:
1169: f3 0f 1e fa endbr64
116d: 55 push %rbp
116e: 48 89 e5 mov %rsp,%rbp
1171: 48 8d 3d 8c 0e 00 00 lea 0xe8c(%rip),%rdi # 2004 <_IO_stdin_used+0x4>
1178: e8 e3 fe ff ff callq 1060 <[email protected]>
117d: b8 00 00 00 00 mov $0x0,%eax
1182: 5d pop %rbp
1183: c3 retq
0000000000001184 <output_number>:
1184: f3 0f 1e fa endbr64
1188: 55 push %rbp
1189: 48 89 e5 mov %rsp,%rbp
118c: 48 8d 3d 87 0e 00 00 lea 0xe87(%rip),%rdi # 201a <_IO_stdin_used+0x1a>
1193: b8 00 00 00 00 mov $0x0,%eax
1198: e8 d3 fe ff ff callq 1070 <[email protected]>
119d: b8 00 00 00 00 mov $0x0,%eax
11a2: 5d pop %rbp
11a3: c3 retqLook, in input_number(), address 1178 callq puts.
in output_number(), address 1198 callq printf.
Interesting.
How do I notice it. The whole story is:
we build FreeRTOS with Linux GCC(for some reason). And we found Linux GCC GLibc printf goes to tty. So we write a printf() in FreeRTOS. But when we use printf() in main(), GCC reports link error of missing puts().
Other tips:
1. -nostdlib to avoid use GLibc.
2. implement our own libc functions.
3. remove relocation section(.rela.dyn). So all the libs we developed need to avoid dynamically link by removing cflags -fPIE -fPIC and link flags -pie.
Refer to: https://blog.csdn.net/alex_mianmian/article/details/50582833
边栏推荐
- Record local project startup error: invalid source distribution: 8
- P1061 [NOIP2006 普及组] Jam 的计数法
- Prompt box moving with the mouse
- 微信小程序给子组件赋值方式
- Research Report on global and Chinese active Ethernet access device industry demand trend and investment prospect 2022-2027
- [cloud native] 2.2 kubeadm create cluster
- How to find the source of goods for novice stores and how to find high-quality sources of goods?
- Rambbmitmq consumer
- printf becomes puts
- A reminder to cross-border sellers who are still "shopping"!
猜你喜欢

Kubernetes - bare metal cluster environment

Cookie setting and reading in C #

错误:note: module requires Go 1.17

删除弹窗组件的封装使用

Graduation season | a new start, no goodbye

Someone always asks me: how to play independent station? Three cases, you will understand after reading

數據的存儲(進階)

Summary of knapsack problem

Service migration when deploying SuperMap iserver war package

Tongda OA vulnerability analysis collection
随机推荐
JS regular expression to implement the thousands separator
Gerrit Code Review Setup
Sogou input method cannot output Chinese
Tidb upgrade version
旅行家的预算(洛谷)
Prompt box moving with the mouse
网络、IO流、反射、多线程、异常
Does the air valve perform the en 1634-1 fire resistance test for 4 hours?
CMAKE notes
The "decentralization" mode of independent stations has risen, sweeping the tide of cross-border enterprise transformation
nacos server 源码运行实现
关于图片懒加载的实现(总结梳理)
vscode 远程连接错误:Server status check failed - waiting and retrying
大厂晋升学习方法三:链式学习法
【毕业季·进击的技术er】一个读研学生的唠唠嗑
Implementation of Nacos server source code
Graduation season | a new start, no goodbye
机器学习笔记 六:逻辑回归中的多分类问题之数字识别
Mobile terminal layout adaptation
亚马逊和独立站,不是简单的二选一