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




33 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. Nice Website...
    Hey JOIN now fblikesbot.com and Increase Facebook Likes your profile and websites.
    Increase Facebook Likes and check your website worth worth my websites
    FB Likes and check your website worth Website Value Calculator
    Hot Wallpapers seo tools website
    its may be very beneficial for you also really

    ReplyDelete
  3. Instruments measurement testing is very much popular in several corporate offices. Several intelligent testing instruments are used for intelligent testing. This test helps the employer of any office to judge the mental ability of any individual working in his office. This also helps to understand the cultural and background difference between two employees.

    ReplyDelete
  4. 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
  5. Hello!! I'am glad to read the whole content of this topic and am very excited.Thank you.

    gclub online
    goldenslot
    สูตรบาคาร่า

    ReplyDelete

  6. Nice article thank you for sharing valuable information.
    สโบเบ็ต

    Lsm99

    ReplyDelete
  7. Thank you for sharing valuable information.

    SCR888

    ACE333

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

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

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


    สล็อต

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

    ReplyDelete
  10. 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
  11. Incredible post! I am really getting prepared to over this data, is exceptionally useful my companion. Likewise extraordinary blog here with the majority of the significant data you have. I am sharing related topic which is most important on iTunes Gift card

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

    ReplyDelete
  13. 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
  14. 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
  15. 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
  16. a lot of people doubted us against West Springfield and it went in our favor," Ehorn Jr. said. super bowl stream

    ReplyDelete
  17. Thank you for the useful educational article
    Sa gaming

    ReplyDelete
  18. 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
  19. 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
  20. The market is significant. According to CB Insights, there are "41 VC-backed fintech unicorns worth a mixed $154.1 B." One driving variable is that lots of standard banks are advocates and adopters of the innovation, proactively spending in, acquiring or partnering with fintech startups since it is simpler to offer digitally-minded clients what they desire, while likewise moving the market forward and staying pertinent.


    Eyal Nachum on management

    ReplyDelete
  21. 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
  22. 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

  23. This Is Really Useful And Nices Information. แทงบอลออนไลน์
    This are such great articles. แทงบอลออนไลน์ This articles can help you to make some new ideas.

    ReplyDelete