亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? nasmdoc8.htm

?? nasm手冊 大家可以看看 對要寫匯編程序的幫助很大
?? HTM
?? 第 1 頁 / 共 2 頁
字號:
<h3><a name="section-8.2">8.2 Writing NetBSD/FreeBSD/OpenBSD and Linux/ELF Shared Libraries</a></h3><p><code><nobr>ELF</nobr></code> replaced the older<code><nobr>a.out</nobr></code> object file format under Linux because itcontains support for position-independent code (PIC), which makes writingshared libraries much easier. NASM supports the<code><nobr>ELF</nobr></code> position-independent code features, so youcan write Linux <code><nobr>ELF</nobr></code> shared libraries in NASM.<p>NetBSD, and its close cousins FreeBSD and OpenBSD, take a differentapproach by hacking PIC support into the <code><nobr>a.out</nobr></code>format. NASM supports this as the <code><nobr>aoutb</nobr></code> outputformat, so you can write BSD shared libraries in NASM too.<p>The operating system loads a PIC shared library by memory-mapping thelibrary file at an arbitrarily chosen point in the address space of therunning process. The contents of the library's code section must thereforenot depend on where it is loaded in memory.<p>Therefore, you cannot get at your variables by writing code like this:<p><pre>        mov     eax,[myvar]             ; WRONG</pre><p>Instead, the linker provides an area of memory called the <em>globaloffset table</em>, or GOT; the GOT is situated at a constant distance fromyour library's code, so if you can find out where your library is loaded(which is typically done using a <code><nobr>CALL</nobr></code> and<code><nobr>POP</nobr></code> combination), you can obtain the address ofthe GOT, and you can then load the addresses of your variables out oflinker-generated entries in the GOT.<p>The <em>data</em> section of a PIC shared library does not have theserestrictions: since the data section is writable, it has to be copied intomemory anyway rather than just paged in from the library file, so as longas it's being copied it can be relocated too. So you can put ordinary typesof relocation in the data section without too much worry (but see<a href="#section-8.2.4">section 8.2.4</a> for a caveat).<h4><a name="section-8.2.1">8.2.1 Obtaining the Address of the GOT</a></h4><p>Each code module in your shared library should define the GOT as anexternal symbol:<p><pre>extern  _GLOBAL_OFFSET_TABLE_   ; in ELF extern  __GLOBAL_OFFSET_TABLE_  ; in BSD a.out</pre><p>At the beginning of any function in your shared library which plans toaccess your data or BSS sections, you must first calculate the address ofthe GOT. This is typically done by writing the function in this form:<p><pre>func:   push    ebp         mov     ebp,esp         push    ebx         call    .get_GOT .get_GOT:         pop     ebx         add     ebx,_GLOBAL_OFFSET_TABLE_+$$-.get_GOT wrt ..gotpc         ; the function body comes here         mov     ebx,[ebp-4]         mov     esp,ebp         pop     ebp         ret</pre><p>(For BSD, again, the symbol<code><nobr>_GLOBAL_OFFSET_TABLE</nobr></code> requires a second leadingunderscore.)<p>The first two lines of this function are simply the standard C prologueto set up a stack frame, and the last three lines are standard C functionepilogue. The third line, and the fourth to last line, save and restore the<code><nobr>EBX</nobr></code> register, because PIC shared libraries usethis register to store the address of the GOT.<p>The interesting bit is the <code><nobr>CALL</nobr></code> instructionand the following two lines. The <code><nobr>CALL</nobr></code> and<code><nobr>POP</nobr></code> combination obtains the address of the label<code><nobr>.get_GOT</nobr></code>, without having to know in advance wherethe program was loaded (since the <code><nobr>CALL</nobr></code>instruction is encoded relative to the current position). The<code><nobr>ADD</nobr></code> instruction makes use of one of the specialPIC relocation types: GOTPC relocation. With the<code><nobr>WRT ..gotpc</nobr></code> qualifier specified, the symbolreferenced (here <code><nobr>_GLOBAL_OFFSET_TABLE_</nobr></code>, thespecial symbol assigned to the GOT) is given as an offset from thebeginning of the section. (Actually, <code><nobr>ELF</nobr></code> encodesit as the offset from the operand field of the<code><nobr>ADD</nobr></code> instruction, but NASM simplifies thisdeliberately, so you do things the same way for both<code><nobr>ELF</nobr></code> and <code><nobr>BSD</nobr></code>.) So theinstruction then <em>adds</em> the beginning of the section, to get thereal address of the GOT, and subtracts the value of<code><nobr>.get_GOT</nobr></code> which it knows is in<code><nobr>EBX</nobr></code>. Therefore, by the time that instruction hasfinished, <code><nobr>EBX</nobr></code> contains the address of the GOT.<p>If you didn't follow that, don't worry: it's never necessary to obtainthe address of the GOT by any other means, so you can put those threeinstructions into a macro and safely ignore them:<p><pre>%macro  get_GOT 0         call    %%getgot   %%getgot:         pop     ebx         add     ebx,_GLOBAL_OFFSET_TABLE_+$$-%%getgot wrt ..gotpc %endmacro</pre><h4><a name="section-8.2.2">8.2.2 Finding Your Local Data Items</a></h4><p>Having got the GOT, you can then use it to obtain the addresses of yourdata items. Most variables will reside in the sections you have declared;they can be accessed using the <code><nobr>..gotoff</nobr></code> special<code><nobr>WRT</nobr></code> type. The way this works is like this:<p><pre>        lea     eax,[ebx+myvar wrt ..gotoff]</pre><p>The expression <code><nobr>myvar wrt ..gotoff</nobr></code> iscalculated, when the shared library is linked, to be the offset to thelocal variable <code><nobr>myvar</nobr></code> from the beginning of theGOT. Therefore, adding it to <code><nobr>EBX</nobr></code> as above willplace the real address of <code><nobr>myvar</nobr></code> in<code><nobr>EAX</nobr></code>.<p>If you declare variables as <code><nobr>GLOBAL</nobr></code> withoutspecifying a size for them, they are shared between code modules in thelibrary, but do not get exported from the library to the program thatloaded it. They will still be in your ordinary data and BSS sections, soyou can access them in the same way as local variables, using the above<code><nobr>..gotoff</nobr></code> mechanism.<p>Note that due to a peculiarity of the way BSD<code><nobr>a.out</nobr></code> format handles this relocation type, theremust be at least one non-local symbol in the same section as the addressyou're trying to access.<h4><a name="section-8.2.3">8.2.3 Finding External and Common Data Items</a></h4><p>If your library needs to get at an external variable (external to the<em>library</em>, not just to one of the modules within it), you must usethe <code><nobr>..got</nobr></code> type to get at it. The<code><nobr>..got</nobr></code> type, instead of giving you the offset fromthe GOT base to the variable, gives you the offset from the GOT base to aGOT <em>entry</em> containing the address of the variable. The linker willset up this GOT entry when it builds the library, and the dynamic linkerwill place the correct address in it at load time. So to obtain the addressof an external variable <code><nobr>extvar</nobr></code> in<code><nobr>EAX</nobr></code>, you would code<p><pre>        mov     eax,[ebx+extvar wrt ..got]</pre><p>This loads the address of <code><nobr>extvar</nobr></code> out of anentry in the GOT. The linker, when it builds the shared library, collectstogether every relocation of type <code><nobr>..got</nobr></code>, andbuilds the GOT so as to ensure it has every necessary entry present.<p>Common variables must also be accessed in this way.<h4><a name="section-8.2.4">8.2.4 Exporting Symbols to the Library User</a></h4><p>If you want to export symbols to the user of the library, you have todeclare whether they are functions or data, and if they are data, you haveto give the size of the data item. This is because the dynamic linker hasto build procedure linkage table entries for any exported functions, andalso moves exported data items away from the library's data section inwhich they were declared.<p>So to export a function to users of the library, you must use<p><pre>global  func:function           ; declare it as a function func:   push    ebp         ; etc.</pre><p>And to export a data item such as an array, you would have to code<p><pre>global  array:data array.end-array      ; give the size too array:  resd    128 .end:</pre><p>Be careful: If you export a variable to the library user, by declaringit as <code><nobr>GLOBAL</nobr></code> and supplying a size, the variablewill end up living in the data section of the main program, rather than inyour library's data section, where you declared it. So you will have toaccess your own global variable with the <code><nobr>..got</nobr></code>mechanism rather than <code><nobr>..gotoff</nobr></code>, as if it wereexternal (which, effectively, it has become).<p>Equally, if you need to store the address of an exported global in oneof your data sections, you can't do it by means of the standard sort ofcode:<p><pre>dataptr:        dd      global_data_item        ; WRONG</pre><p>NASM will interpret this code as an ordinary relocation, in which<code><nobr>global_data_item</nobr></code> is merely an offset from thebeginning of the <code><nobr>.data</nobr></code> section (or whatever); sothis reference will end up pointing at your data section instead of at theexported global which resides elsewhere.<p>Instead of the above code, then, you must write<p><pre>dataptr:        dd      global_data_item wrt ..sym</pre><p>which makes use of the special <code><nobr>WRT</nobr></code> type<code><nobr>..sym</nobr></code> to instruct NASM to search the symbol tablefor a particular symbol at that address, rather than just relocating bysection base.<p>Either method will work for functions: referring to one of yourfunctions by means of<p><pre>funcptr:        dd      my_function</pre><p>will give the user the address of the code you wrote, whereas<p><pre>funcptr:        dd      my_function wrt .sym</pre><p>will give the address of the procedure linkage table for the function,which is where the calling program will <em>believe</em> the functionlives. Either address is a valid way to call the function.<h4><a name="section-8.2.5">8.2.5 Calling Procedures Outside the Library</a></h4><p>Calling procedures outside your shared library has to be done by meansof a <em>procedure linkage table</em>, or PLT. The PLT is placed at a knownoffset from where the library is loaded, so the library code can make callsto the PLT in a position-independent way. Within the PLT there is code tojump to offsets contained in the GOT, so function calls to other sharedlibraries or to routines in the main program can be transparently passedoff to their real destinations.<p>To call an external routine, you must use another special PIC relocationtype, <code><nobr>WRT ..plt</nobr></code>. This is much easier than theGOT-based ones: you simply replace calls such as<code><nobr>CALL printf</nobr></code> with the PLT-relative version<code><nobr>CALL printf WRT ..plt</nobr></code>.<h4><a name="section-8.2.6">8.2.6 Generating the Library File</a></h4><p>Having written some code modules and assembled them to<code><nobr>.o</nobr></code> files, you then generate your shared librarywith a command such as<p><pre>ld -shared -o library.so module1.o module2.o       # for ELF ld -Bshareable -o library.so module1.o module2.o   # for BSD</pre><p>For ELF, if your shared library is going to reside in system directoriessuch as <code><nobr>/usr/lib</nobr></code> or<code><nobr>/lib</nobr></code>, it is usually worth using the<code><nobr>-soname</nobr></code> flag to the linker, to store the finallibrary file name, with a version number, into the library:<p><pre>ld -shared -soname library.so.1 -o library.so.1.2 *.o</pre><p>You would then copy <code><nobr>library.so.1.2</nobr></code> into thelibrary directory, and create <code><nobr>library.so.1</nobr></code> as asymbolic link to it.<p align=center><a href="nasmdoc9.html">Next Chapter</a> |<a href="nasmdoc7.html">Previous Chapter</a> |<a href="nasmdoc0.html">Contents</a> |<a href="nasmdoci.html">Index</a></body></html>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲一区二区在线免费观看视频| 欧美三级日韩三级| 精品久久五月天| 经典三级在线一区| 26uuu国产一区二区三区| 国产精品一色哟哟哟| 日本一区二区视频在线| 成人在线视频一区| 国产精品传媒入口麻豆| av电影天堂一区二区在线观看| 日韩一区欧美小说| 色婷婷av一区| 偷拍自拍另类欧美| 欧美岛国在线观看| 成人av资源在线| 亚洲精品视频在线| 51精品秘密在线观看| 国产乱码字幕精品高清av| 国产精品白丝在线| 欧美在线观看一二区| 日韩**一区毛片| 国产精品三级电影| 欧美色综合网站| 国产精品综合一区二区三区| 国产精品色眯眯| 欧美日韩视频第一区| 国产一区999| 一区二区三区四区国产精品| 欧美xxxxx牲另类人与| 成人免费视频视频| 日韩精品欧美精品| 中文字幕av不卡| 欧美区一区二区三区| 国产大陆亚洲精品国产| 亚洲午夜一区二区三区| 亚洲精品一区二区三区99| 99v久久综合狠狠综合久久| 日韩精品91亚洲二区在线观看| 中文字幕欧美区| 日韩一区二区三区电影在线观看 | 国产精品中文有码| 一区二区三区精密机械公司| 精品999久久久| 欧美视频在线不卡| 丁香一区二区三区| 蜜桃一区二区三区在线| 天天综合天天综合色| 久久精品在线观看| 69av一区二区三区| 色菇凉天天综合网| 盗摄精品av一区二区三区| 日本女人一区二区三区| 亚洲视频你懂的| 亚洲精品一区二区三区影院| 欧美精品三级日韩久久| 成人深夜在线观看| 国产美女主播视频一区| 麻豆成人久久精品二区三区小说| 亚洲免费观看在线视频| 久久在线免费观看| 欧美一区在线视频| 99re免费视频精品全部| 国产69精品久久777的优势| 精品一区二区三区的国产在线播放| 亚洲最大成人综合| 亚洲欧洲成人精品av97| 国产欧美日韩中文久久| 亚洲精品在线网站| 精品国产一区二区三区忘忧草| 欧美日韩电影在线播放| 欧美在线综合视频| 色哟哟国产精品| 91浏览器在线视频| 93久久精品日日躁夜夜躁欧美| 成人免费视频免费观看| 国产+成+人+亚洲欧洲自线| 国产高清无密码一区二区三区| 黄色日韩网站视频| 狠狠色狠狠色合久久伊人| 久久激情综合网| 麻豆国产一区二区| 国内精品久久久久影院色| 韩国成人福利片在线播放| 精品在线观看视频| 国产高清成人在线| 国产91对白在线观看九色| 成人网在线免费视频| 成人自拍视频在线| 成人黄色片在线观看| 97精品久久久久中文字幕| 一本一本大道香蕉久在线精品 | 久久亚洲春色中文字幕久久久| 日韩欧美激情一区| 日韩欧美一二区| 久久伊人中文字幕| 国产精品久久久久永久免费观看| 亚洲国产高清不卡| 亚洲天堂成人在线观看| 一区二区三区四区精品在线视频| 亚洲高清不卡在线| 免费一级欧美片在线观看| 日本不卡123| 精品制服美女久久| 成人a区在线观看| 色婷婷综合激情| 欧美成人精品福利| 欧美激情一区二区三区不卡| 亚洲美女一区二区三区| 婷婷久久综合九色综合伊人色| 精久久久久久久久久久| 成人晚上爱看视频| 欧美久久久久免费| 久久奇米777| 一区二区在线电影| 麻豆精品视频在线| 91视频你懂的| 91精品国产综合久久精品性色| 欧美激情一区二区三区在线| 亚洲在线一区二区三区| 人人超碰91尤物精品国产| 国产麻豆日韩欧美久久| 日本精品一级二级| 欧美成人午夜电影| 亚洲激情图片qvod| 极品少妇一区二区| 色综合色综合色综合色综合色综合 | 欧美撒尿777hd撒尿| 精品日产卡一卡二卡麻豆| 亚洲日本在线天堂| 国模冰冰炮一区二区| 色哟哟一区二区| 精品国产一区二区三区久久影院| 尤物在线观看一区| 国产成人亚洲综合a∨猫咪| 欧美日韩三级一区| 中文字幕在线视频一区| 精品制服美女丁香| 一本色道久久加勒比精品| 久久色成人在线| 亚洲第一电影网| 不卡电影免费在线播放一区| 欧美一级xxx| 亚洲精品免费在线观看| 国产成人欧美日韩在线电影 | 91精品在线一区二区| 亚洲欧美在线aaa| 久99久精品视频免费观看| 欧美日韩一区久久| 亚洲欧美一区二区三区久本道91| 国产成人精品免费在线| 日韩欧美高清dvd碟片| 麻豆高清免费国产一区| 在线精品视频免费观看| 国产精品午夜电影| 国产一区二区不卡在线| 欧美一区二区三区不卡| 亚洲国产人成综合网站| 色综合视频在线观看| 国产精品久久久久久久久久久免费看| 久久99精品网久久| 日韩欧美一区二区视频| 午夜精品在线视频一区| 91黄色免费网站| 亚洲欧美日韩在线播放| 成人黄动漫网站免费app| 久久久精品黄色| 国模一区二区三区白浆| 久久色成人在线| 国产成人av一区二区三区在线 | 久久久国产午夜精品| 激情文学综合丁香| 久久蜜桃香蕉精品一区二区三区| 久久激五月天综合精品| 久久午夜电影网| 国产电影一区二区三区| 欧美国产激情二区三区| 成人精品视频一区二区三区| 国产视频在线观看一区二区三区| 国产精品18久久久久久久久久久久 | 国产91色综合久久免费分享| 久久精品夜色噜噜亚洲aⅴ| 国产a精品视频| 久久久久一区二区三区四区| 成人午夜激情影院| 亚洲欧美日韩久久精品| 欧美性一级生活| 日日嗨av一区二区三区四区| 欧美成人一区二区| 国产91在线观看丝袜| 亚洲欧洲精品一区二区精品久久久| 成人美女在线视频| 伊人一区二区三区| 欧美另类z0zxhd电影| 久久精品国内一区二区三区| 久久亚洲精精品中文字幕早川悠里| 成人性生交大片免费看中文| 亚洲精品写真福利| 日韩精品一区二区三区老鸭窝| 国产高清精品久久久久| 一区二区三区高清|