닉네임 via llvm-dev
2018-Nov-20 08:45 UTC
[llvm-dev] Get/set custom section information of function by using LLVM Pass.
<html> <head> <style> p{margin-top:0;margin-bottom:0} </style> </head> <body> <table class="txc-wrapper" border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td class="txc-wrapper-td"><div class="txc-content-wrapper" style="color:#111;font-family:Apple SD Gothic Neo,Malgun Gothic,'맑은 고딕',sans-serif;font-size:10pt;line-height:1.5;"><p><br></p> <p><br></p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;">Hello folks,</p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;"><br style="word-break:break-all;overflow-wrap:break-word;"></p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;">How can I get the section information that is set by __attribute__((section("something")) in C?</p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;"><br style="word-break:break-all;overflow-wrap:break-word;"></p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;">For example, I define the function like below.</p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;"><br style="word-break:break-all;overflow-wrap:break-word;"></p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;">------------------------------------------------------</p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;">int callB(int i) __attribute__((section("newSec"))){</p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;">....</p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;">}</p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;">-----------------------------------------------------</p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;"><br style="word-break:break-all;overflow-wrap:break-word;"></p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;">Then, the LLVM IR is like below.</p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;">-----------------------------------------------------</p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;">define i32 @callB(i32 %i) #0 section "newSec" {</p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;">......</p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;">}</p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;">-----------------------------------------------------</p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;"><br style="word-break:break-all;overflow-wrap:break-word;"></p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;"><br style="word-break:break-all;overflow-wrap:break-word;"></p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;"><br style="word-break:break-all;overflow-wrap:break-word;"></p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;">I've explored member functions of LLVM Function Class, but couldn't find a proper function that can be used to set/get the custom section information.</p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;"><br style="word-break:break-all;overflow-wrap:break-word;"></p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;">Could you anybody help me to find useful class or functions for setting (getting) the function's new section information?</p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;"><br style="word-break:break-all;overflow-wrap:break-word;"></p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;">What I want to do is copying function and placing it in a specific section.</p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;"><br></p> <p style="margin:0px;padding:0px;font-size:13.3333px;word-break:break-all;overflow-wrap:break-word;color:rgb(17,17,17);font-family:"font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;orphans:2;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:2;word-spacing:0px;-webkit-text-stroke-width:0px;background-color:rgb(255, 255, 255);text-decoration-style:initial;text-decoration-color:initial;">Thank you!</p></div></td></tr></table> </body> </html> <img src="https://confirm.mail.daum.net/confirmapi/v1/users/e-min2%40hanmail%2Enet/cmails/20181120174501%2EvKI7cCRqR2KJOH9eKcnbzg%40e-min2%2Ehanmail%2Enet/recipients/llvm-dev%40lists%2Ellvm%2Eorg">
Tim Northover via llvm-dev
2018-Nov-20 10:16 UTC
[llvm-dev] Get/set custom section information of function by using LLVM Pass.
Hi, On Tue, 20 Nov 2018 at 08:45, 닉네임 via llvm-dev <llvm-dev at lists.llvm.org> wrote:> I've explored member functions of LLVM Function Class, but couldn't find a proper function that can be used to set/get the custom section information.GlobalValue has getSection, GlobalObject has setSection. And Function is a subclass of both of these, fortunately. Cheers. Tim.