

用 objdump 學到的一些東西… – Gea-Suan Lin's BLOG
source link: https://blog.gslin.org/archives/2022/04/08/10651/%e7%94%a8-objdump-%e5%ad%b8%e5%88%b0%e7%9a%84%e4%b8%80%e4%ba%9b%e6%9d%b1%e8%a5%bf/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

用 objdump 學到的一些東西...
在 Hacker News 首頁上看到「Hand-optimizing the TCC code generator (briancallahan.net)」這則,原始文章在「Hand-optimizing the TCC code generator」這邊。
主要是在文章內看到 objdump 這個東西,作者用這兩個指令看組語:
tcc -c true.c objdump -d true.o
另外同樣道理也可以用 gcc -c true.c
看 GCC 轉出來的版本。
倒出來的組語是 AT&T 語法,但我熟悉的是 Intel 語法,對我的直覺上需要習慣... 另外我看了一下 GCC 編出來的組語:
0000000000000000 <main>: 0: f3 0f 1e fa endbr64 4: 55 push %rbp 5: 48 89 e5 mov %rsp,%rbp 8: b8 00 00 00 00 mov $0x0,%eax d: 5d pop %rbp e: c3 retq
第一行的那個 endbr64 指令沒看過,查一下發現原來是 Intel 在 CPU 層設計出來的安全機制,標示這個地方可以被 indirect call 進來:「What does the endbr64 instruction actually do?」。
至於文章裡面主要提到的 mov $0x0, %eax
可以用 xor %eax, %eax
代替 (或是 sub %eax, %eax
) 算是很久前就會的東西了...
Related
GCC 裡的 Inline Assembly
Update:感謝某長輩提醒,標題從「Unix 環境下的 Inline Assembly」改成「GCC 裡的 Inline Assembly」。 從大二修 Assembly 後就很久沒寫組語了,當時修的時候還是用 Intel 語法寫,就一直沒學到 AT&T 語法,後來從網路上看也只知道 src 與 dst 的位置通常是相反的,以及 register 前面要用 % 修飾,其他的像是記憶體的定址要怎麼寫都不知道,所以在 Unix 下一直不會寫 Assembly... 前幾天有個學弟剛好在寫作業,要用 MMX 計算一個整數 Vector (看做是 1*n 的 Matrix) 乘上整數 Matrix (n*n) 的結果 (其中 n 會是 4 的倍數,另外每個整數都是 16 bits),趁著這個機會摸索 GCC 裡要怎麼寫 Inline Assembly,以及 AT&T 語法與…
October 28, 2006In "Computer"
用 Python 的 DuckDB 下 SQL 指令翻 Parquet 的資料
在「Querying Parquet using DuckDB」這邊看到 DuckDB 這個東西,裡面引用的文章是「Querying Parquet with Precision using DuckDB」,可以直接對 Parquet 格式的資料下 SQL 找資料。 先前好像有看到 DuckDB 但沒有太注意,剛剛再次看到,然後玩了一下還蠻有趣的。DuckDB 支援蠻多程式語言與資料格式,不過這邊文章拿 Python 與 Parquet 玩還蠻有趣的... 先把 Parquet 的範例資料抓下來,然後透過 pip 裝 duckdb: cd /tmp; wget https://github.com/cwida/duckdb-data/releases/download/v1.0/taxi_2019_04.parquet; pip install -U duckdb 然後進到 Python 3 的互動界面: >>> import duckdb >>> print(duckdb.query("SELECT COUNT(*) FROM 'taxi_2019_04.parquet' WHERE…
June 28, 2021In "Computer"
C++ 與組語的速度...
在 Hacker News Daily 上看到「Why is this C++ code faster than my hand-written assembly for testing the Collatz conjecture?」覺得很有趣... 作者寫了一段 assembly,但跑起來比用 C++ 同義的版本慢多了。目前最高分的答案給了很清楚的解釋... even: mov rbx, 2 xor rdx, rdx div rbx 上面這段 code 是作者寫的組語版本,用到 div 指令,這是非常慢的指令: On Intel Haswell, div r64 is 36 uops, with a latency of 32-96…
August 26, 2017In "Computer"
Author Gea-Suan LinPosted on April 8, 2022Categories Computer, Murmuring, Programming, Security, SoftwareTags compiler, cpu, endbr64, gcc, intel, objdump, security, tcc
Leave a Reply
Your email address will not be published. Required fields are marked *
Comment *
Name *
Email *
Website
Notify me of follow-up comments by email.
Notify me of new posts by email.
To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Learn More)
Post navigation
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK