Saturday 12 September 2015

Calling conventions are hard - Fuzz them!

I am busy implementing the C AMD64 calling conventions in my C compiler suite and have a topic worthy of a post. It is about testing the C ABI (How C programs layout structs and perform function calls).

The old Linux C x86 ABI was relatively simple, to call a function you pushed arguments onto the stack in reverse order and you are done with it. Unfortunately for me, most people now use AMD64 processors, so that is what I need to target first. The AMD64 ABI designers apparently didn't like simple or well specified things (presumably because it would make software engineering too easy), so they created this document to describe the way C structs/arguments are laid out in memory and registers among other things.

I have a few problems with the document, such as a lack of examples, lack of pseudo code for the classification algorithm, and underspecified edge cases. However, regardless of whether my complaints are valid or not, I still need to implement the thing correctly before my compiler can self host. I need a good way to test my implementation...

Enter ABIFUZZ

We have a few C compilers like gcc and clang we can test against, but hand writing interesting test cases is a chore, so I decided to automate it. The general steps are quite simple:

  • Decide how many arguments you want.
  • Decide the types of those arguments.
  • Generate values for the arguments.
  • Decide the return type.
  • Generate a return values.
  • Generate code to do the call and check the values.
The tool is located here here and took an afternoon to write. Here's the end result:




The final step is to write a script to split the caller and callee into two files to test interop when each is compiled by different C compiler.

Bugs found:

http://savannah.nongnu.org/bugs/index.php?45950
https://github.com/andrewchambers/c/issues/14
https://github.com/andrewchambers/c/issues/13




24 comments:

  1. I made a AMD64 compiler. I used the stack and pushed arguments. It seems to work. LOL You Jedi Mind Trick CiA agent, LOL. What a lame Jedi Mind Trick.

    ReplyDelete
    Replies
    1. Hi Terry, I think things are different in TempleOS and Linux. Thanks for the comment.

      Delete
  2. Why not make things exciting with a Milano Formals short dress? Milano Formals new arrival dresses are perfect for all of life's most festive and important events.
    Prom Dresses 2016

    ReplyDelete
  3. มาเล่น”สล็อต” กันดีกว่า

    เนื่องจากเป็นการเล่นพนันที่ใช้เงินลงทุนน้อย แต่มีโอกาสชนะเดิมพันที่มีทั้งรางวัลเล็กและรางวัลใหญ่ได้เงินเป็นจำนวนมาก ได้ลุ้นระทึก สร้างความเร้าใจตลอดช่วงเวลาที่วงล้อของสล็อตหมุนไป ปัจจุบันปัจจุบันเทคโนโลยีสื่อสารที่ทันสมัย ทำให้ เกมส์สล็อต ได้รับการพัฒนาและยกระดับ จากที่เคยเล่นกันแพร่หลายเฉพาะในสถาน ให้สามารถเล่นกันทางออนไลน์ได้แล้ว

    โดยการเล่นผ่านเว็บไซต์ผู้ให้บริการ ออนไลน์ หรือแอพริเคชั่นบนมือถือ ซึ่งการเล่น เกมสล็อตออนไลน์ ได้รับความนิยมไม่ยิ่งหย่อนไปกว่าการเล่นสล็อตในสถาน หรืออาจจะได้ว่าได้รับความนิยมมากกว่าในสถานก็ว่าได้ เนื่องจากอำนวยสะดวกให้แก่ผู้ที่ชื่นชอบการเล่นสล็อตสามารถเล่นได้ทุกที่ ทุกเวลา ไม่พลาดโอกาสการทำกำไรได้ทั้งวันทั่งคืน ปัจจุบันสล็อตออนไลน์ เป็นหนึ่งในเกมส์พนันออนไลน์ที่ได้รับความนิยมสูงมาก


    สล็อต

    ReplyDelete
  4. มาเด้ เป็นยังไง? เป็นส่วนประกอบของสารสกัดที่ได้มาจากธรรมชาติมีทั้งยังวิตามินรวม แร่ เอนเหล้าองุ่นรวมทั้งเชลล์บรรเทา
    มีอีกทั้งพลาสเซนต้ารวมทั้งคอลลาเจนโดนสารทั้งหมดจำเป็นต้องผ่านขั้นตอนจัดเตรียมสูตรยาแบบ(Homeopathy)
    เป็นศาสตร์การบำบัดที่มีต้นกำเนิดมาจาก สหพันธ์สาธารณรัฐเยอรมนี โดยกานศึกษาค้นพบของหมอ ซามุเอลฮาเนมัน แก่มากยิ่งกว่า 200
    ปีโดยมีแนวทางบรรเทาว่า (ใช้สิ่งที่คล้ายคลึงกันมารักษาสิ่งที่คล้ายคลึงกัน) หรือการนำเอาสารที่เป็นต้นเหตุของอาการนั้นๆ
    มาเด้
    มาเด้ หน้าใส
    ฉีดมาเด้ ที่ไหนดี

    ReplyDelete
  5. Nice and valuable article for reader. I have related topic which is share with you. You can visit my Blog How to generate free eBay gift card code ?

    ReplyDelete
  6. The Article Was Very Good and Really Helped Me. Thanks for Sharing
    Instant Ways to Earn Free Robux Legally Fast Free

    ReplyDelete
  7. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.
    If you have time you can check How get free Robux.

    ReplyDelete
  8. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.
    If you have time you can check How get free Robux.

    ReplyDelete
  9. World Series Live Stream Sunday's starter Joe Ross has proven to be a capable pitcher for the Nationals. In fact, Ross has allowed one earned run or less in seven of his last nine appearances.

    ReplyDelete
  10. a lot of people doubted us against West Springfield and it went in our favor," Ehorn Jr. said. super bowl stream

    ReplyDelete
  11. The term Fintech (Financial Technology) refers to software application as well as various other modern technologies utilized by services that give automated and imporved economic solutions. The innovative as well as rapid progresses such as Mobile Payments altered the way we manage our funds. Tech-savvy consumers, particularly millenials anticipate money transfer, loaning, loan management and investing to be effortless, secure and scalable, ideally without the help of a person or the browse through of a financial institution. Bruc Bond endeavor to lead the financial sector with sustainability, customizable product offering, and open communication. At Bruc Bond we aim to make 21st century banking straightforward, simple, and transparent.

    ReplyDelete
  12. Fintech has caused a surge in the number of investing and also savings apps in recent times. Even more than ever before, the barriers to investing are being damaged down by companies like Robinhood, Stash and also Acorns. While these applications vary in strategy, each uses a combination of savings and also very easy, little buck spending to present customers to the markets. Bruc Bond endeavor to lead the financial sector with sustainability, customizable product offering, and open communication. At Bruc Bond we aim to make 21st century banking straightforward, simple, and transparent.

    ReplyDelete
  13. This is actually good to read the content of this blog. here is very general and the huge knowledgeable platform has been known by this blog. I, in reality, appreciate this blog to have such kind of knowledge.I am sharing related topic which is mostly important for How to Generate How to make Debit Card Validator using HTML, CSS & JS

    ReplyDelete
  14. Wonderful post however I was wanting to know if you could write a litte more on this subject?
    I’d be very thankful if you could elaborate a little
    bit further. Appreciate it!
    there is lot people are searches
    Free Robux on internet , most of searches
    How to get free Robux. to
    Get Free Robux and
    FREE ROBUX ROBLOX some people might be confused at this stage. but for
    Earn Free Robux - Redeem Instantly or
    Free Robux - Earn and
    Earn Free Robux you have to visit
    free robux websites. from that you
    earn robux today by very easy way. you may also get
    free robux codes and
    Free​ Roblox ​Robux.

    ReplyDelete
  15. You can do very creative work in a particular field. Exceptional concept That was incredible share. Leon The Professional Coat

    ReplyDelete
  16. Such an interesting article here.I was searching for something like that for quite a long time and at last I have found it here.
    Chris Evans Knives Out Coat

    ReplyDelete
  17. Hi my name is mandal stive. I am a Gamer one and am write some articles about minecraft. for read this please click here
    Click Here

    ReplyDelete
  18. This is a smart blog. I mean it. You have so much knowledge about this issue, and so much passion. You also know how to make people rally behind it, obviously from the responses click here
    Check here

    ReplyDelete
  19. Your site is good Actually, i have seen your post and That was very informative and very entertaining for me. Squall Leonhart Jacket

    ReplyDelete
  20. Hey friend, it is very well written article, thank you for the valuable and useful information you provide in this post. Keep up the good work!
    wordpress
    blogspot
    youtube
    ហ្គេមបាញ់ត្រី

    ReplyDelete
  21. I read this article. I think You put a lot of effort to create this article. I appreciate your work. That was very informative and very entertaining for me I have found it here new blog kindly click on ds emulator for pc


    ReplyDelete