Load IRT in dynamic text region

61 views
Skip to first unread message

zhiting zhu

unread,
Mar 10, 2016, 4:23:25 PM3/10/16
to Native-Client-Discuss
Dear group members:

I'm studying the native client source code for my research project. I find that IRT is loaded into dynamic text region. Is there any reason IRT.nexe needs to be backed by shared memory? Can I load IRT.nexe into static text region? In my use case, I only supports static linking and don't need to support JIT. 

Best,
Zhiting

Mark Seaborn

unread,
Mar 10, 2016, 5:13:37 PM3/10/16
to Native Client Discuss, zzt...@gmail.com
On 10 March 2016 at 13:23, zhiting zhu <zzt...@gmail.com> wrote:
Dear group members:

I'm studying the native client source code for my research project. I find that IRT is loaded into dynamic text region. Is there any reason IRT.nexe needs to be backed by shared memory? Can I load IRT.nexe into static text region? In my use case, I only supports static linking and don't need to support JIT.

In principle, the IRT could be loaded using mmap() rather than being copied into the shared memory segment.  But if I remember correctly (and from looking at NaClElfImageLoadDynamically() in elf_util.c), the codebase does not implement that at the moment.

What's your reason for wanting to avoid using the dynamic code region?  Performance, or a different reason?

Cheers,
Mark

zhiting zhu

unread,
Mar 10, 2016, 6:12:43 PM3/10/16
to Native-Client-Discuss, zzt...@gmail.com, msea...@chromium.org
I'm running NaCl in a environment that shared mapping cannot be implemented. 

在 2016年3月10日星期四 UTC-6下午4:13:37,Mark Seaborn写道:

Mark Seaborn

unread,
Mar 15, 2016, 9:00:37 PM3/15/16
to zhiting zhu, Native Client Discuss
Can you do mmap() of files at all in the context you're running NaCl in?

If so, changing IRT loading to mmap() the IRT's code segment would be a good solution.

Otherwise, you'd need a change that loads the IRT's code segment into anonymous memory.  Or alternatively, you could use NaCl without the IRT -- that might be an option, depending on your use case.

Cheers,
Mark

zhiting zhu

unread,
Mar 15, 2016, 10:55:04 PM3/15/16
to Native-Client-Discuss, zzt...@gmail.com, msea...@chromium.org
Yes, I can mmap() files with MAP_PRIVATE. 

I'm interested in using NaCl without irt. As a off browser environment, I don't need to support PPAPI and imc calls. But I do need support for pthread. Is that a possible option? 

Best,
Zhiting
在 2016年3月15日星期二 UTC-5下午8:00:37,Mark Seaborn写道:

Mark Seaborn

unread,
Mar 18, 2016, 2:17:29 PM3/18/16
to zhiting zhu, Native-Client-Discuss
On 15 March 2016 at 19:55, zhiting zhu <zzt...@gmail.com> wrote:
Yes, I can mmap() files with MAP_PRIVATE. 

I'm interested in using NaCl without irt. As a off browser environment, I don't need to support PPAPI and imc calls. But I do need support for pthread. Is that a possible option?

Yes, you can build nexes that don't depend on the IRT.  Just link against libnacl_sys_private and (if necessary) libpthread_private -- these call NaCl syscalls directly.

The resulting nexes won't be suitable for running in Chrome, because they won't be using ABI-stable interfaces, but they are fine for other use cases for NaCl that don't require ABI stability for nexes.

Cheers,
Mark

zhiting zhu

unread,
Apr 25, 2016, 8:32:53 PM4/25/16
to Mark Seaborn, Native-Client-Discuss

Hi Mark,

After building some application successfully with libnacl_sys_private and libpthread_private, I encounter one application which gives out signal 4 immediately at startup. I trace through the program execution. It fails at __libnacl_fatal. I think it fails in libnacl_irt_init which calls the __libnacl_mandatory_irt_query. As I don't have irt loaded in, the __nacl_irt_query is NULL which calls the __libnacl_fatal. It's quiet strange that their behavior are different. Is there anything I forget to do?  

Best,
Zhiting

Mark Seaborn <msea...@chromium.org>于2016年3月18日周五 下午1:17写道:

Mark Seaborn

unread,
Apr 26, 2016, 2:08:01 PM4/26/16
to zhiting zhu, Native-Client-Discuss
On 25 April 2016 at 17:32, zhiting zhu <zzt...@gmail.com> wrote:
Hi Mark,

After building some application successfully with libnacl_sys_private and libpthread_private, I encounter one application which gives out signal 4 immediately at startup. I trace through the program execution. It fails at __libnacl_fatal. I think it fails in libnacl_irt_init which calls the __libnacl_mandatory_irt_query. As I don't have irt loaded in, the __nacl_irt_query is NULL which calls the __libnacl_fatal. It's quiet strange that their behavior are different. Is there anything I forget to do?

libnacl_sys_private is supposed to override the definition of libnacl_irt_init() with an empty definition.  So when you say you're getting a failure in libnacl_irt_init(), that suggests that the overriding isn't working successfully.  Maybe there's some link ordering problem?

How does the application with the problem get built -- i.e. what type of build system does it use?  How are you adding in libnacl_sys_private at link time?

Cheers,
Mark

zhiting zhu

unread,
May 5, 2016, 9:12:59 AM5/5/16
to Native-Client-Discuss, zzt...@gmail.com, msea...@chromium.org

We figure out a solution. The problem we have is on c++ application built with clang-newlib toolchain. We find that we need to put c++ before libnacl_sys_private in the link order. Not sure why but we find that after multiple trials. 
在 2016年4月26日星期二 UTC-5下午1:08:01,Mark Seaborn写道:

Victor Khimenko

unread,
May 5, 2016, 10:31:05 AM5/5/16
to Native Client Discuss, zzt...@gmail.com, Mark Seaborn
On Thu, May 5, 2016 at 3:12 PM, zhiting zhu <zzt...@gmail.com> wrote:

We figure out a solution. The problem we have is on c++ application built with clang-newlib toolchain. We find that we need to put c++ before libnacl_sys_private in the link order. Not sure why but we find that after multiple trials. 

You need to put libnacl_sys_private after libc++ or libstdc++ because C/C++ linking was designed that way decades ago. I mean: HOW ELSE would you override definition of functions?

The process is described in all books I've seen which teach C starting from the venerable K&R ( https://en.wikipedia.org/wiki/The_C_Programming_Language ), but if you somehow managed to forget about such basic things there are short description of the whole mechanism on stack overflow ( http://stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-are-linked-sometimes-cause-errors-in-gcc ) and also more precise description of what libnacl_sys_private is doing, too ( http://stackoverflow.com/questions/19023018/overriding-c-library-functions-calling-original ).

Again: that's not NaCl-specific at all, Unix did that for longer I've been alive and all popular OSes (including Mac, Windows and so on) work like this - thus, of course, Mark felt that there are no need to describe all the details.

--
You received this message because you are subscribed to the Google Groups "Native-Client-Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to native-client-di...@googlegroups.com.
To post to this group, send email to native-cli...@googlegroups.com.
Visit this group at https://groups.google.com/group/native-client-discuss.
For more options, visit https://groups.google.com/d/optout.

zhiting zhu

unread,
May 5, 2016, 10:55:31 AM5/5/16
to Victor Khimenko, Native Client Discuss, Mark Seaborn
Well, I find the solution before I see the answer. I just report what I did. I don't know about the overriding definition part when I find the answer. I only look at the nacl source code but not the libc/c++ code. There is no any description on how libc/libc++ interect with the libnacl_sys_private. All I can find is without irt is not officially support and nothing else.
Reply all
Reply to author
Forward
0 new messages