-
Notifications
You must be signed in to change notification settings - Fork 178
Any suggest to couple two functions? #309
Comments
Hi @Haishan312, try to add -lite=0 to the list of bolt option |
Hi, @yavtuk This option doesn't work |
Can you add simple example and some details what you are doing and what you are waiting ? |
As a mitigation, try --lite=1 --skip-functions=funcA,funcB where funcA and funcB are these two special functions. Ideally BOLT heuristics would detect that funcB is not another function, but instead a secondary entry point of funcA, and move these two together. Somehow this is failing for your input, so I agree with @yavtuk in the sense that it would be nice to have a test case. |
@yavtuk @rafaelauler thank you for replying. assembly code of the two functions shown as follow:
BOLT will put ec_encode_data_mbinit into other location. Then binary result in segment fault. |
For the case that you posted, it mostly depends on what the ELF symbol table is telling us. The compiler will probably not generate this code (let me know if that's not the case), so this is likely code written directly in assembly language. For these cases, the programmer needs to correctly classify the symbol types. If "ec_encode_data" is registered as being type "function" (ELF STT_FUNC symbol type), BOLT will think that it is a separate function and will try to move it independently. If it is registered as NOTYPE, though, BOLT will consider that the previous function (ec_encode_data_mbinit) contains this code as well, and will correctly move these two pieces together. In a high level language, you cannot rely on function layout. You can't write code that somehow falls back to the next function in the hope that the next function is always going to be there. The linker is free to move functions around as long as you build with -ffunction-sections. BOLT leverages this assumption to freely shuffle functions around without breaking the ABI or the language contracts. If this code was built with -ffunction-sections, it would like break in the linker too, not just BOLT. Whenever writing code in assembly language, it is unlikely that you will adhere to the same rigorous standards that a compiler has in terms of correctly emitting all necessary metadata. These cases are challenging for BOLT, but we do support this if ec_encode_data is not explictly registered as a function in the ELF sym tab. Unfortunately, if the ELF symbol table is saying it is a function, we have to take this statement at face value and assume this code is layout independent. As a workaround, if you can't fix the source code, the only way to make BOLT ingest this is by adding these symbols to --skip-functions. Let me know what does "readelf -Ws your_binary_name | grep ec_encode_data" says for this binary, as well as "readelf -Ws your_binary_name | grep ec_encode_data_mbinit", to confirm that I interpreted correctly your case. |
@rafaelauler you are right. These code is written by assembly language. Moveover, these functions are open source and update long ago. |
@rafaelauler I try
|
The .size directives seems to be skipped for ec_encode_data_mbinit. Could you please try to add it manually in the source code and check if bolt would handle it? |
also it make sense to add the type for ec_encode_data_mbinit #ifndef APPLE |
@yota9 add tail call instructions "bl ec_encode_data" in the source code, then program runs ok after bolt optimization. |
Hello,
My binary has two functions without return instruction, that's the functions depend on each-other. After bolt, the two functions were splited into separate location. Therefore, how to emit the functions together?
Thank you firstly.
The text was updated successfully, but these errors were encountered: