From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11758 invoked by alias); 31 Mar 2017 15:11:27 -0000 Mailing-List: contact gnu-gabi-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: gnu-gabi-owner@sourceware.org Received: (qmail 11731 invoked by uid 89); 31 Mar 2017 15:11:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99.2 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy=guideline, liner, executions, 30mar2017 X-Spam-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: mail-qt0-f180.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=huT6oiHQIazLeM/sVTVaGFk2qX5GI+gGIosYo7nRotQ=; b=VF/DFnUOSUzzqDV9xQCrxM2HOa2LihHEd7/CoT02FIitD+eaKAwoF5ncvYK4QHVKDr kd98FTtuDhJlvOxKm3ex6fZ7x9duqjaqkEUt2E0kKbt/eErrgwERLTmIoI8OQPrvrzXw 7LaU4MM2IKtcwMO91rglh8OwGjBZ9jyQ5vyV/Ai5PJiJZB7gz2UPUhjxYMGjD0VKESI6 FNSTt4UTbysjWjSR57MhBHmzjeejHyC8mZEhRNyaw2cNOujHImN47nL4KttW6WZqxfTv VfhfB6qAQ9nqIwsGGgn8JMvol30KJ29x5zlHWTLN1I6M3FWji+TqtBEfwLjNxGVFN9/V f7Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=huT6oiHQIazLeM/sVTVaGFk2qX5GI+gGIosYo7nRotQ=; b=JvOoKyUp6swzetdrY7xz18ir5l2e1M9awtaVgi1YtN2xTNfHZrYoix1cGJBM9erHON UefTFvkP0FKI0NMmCi0fkhjpBMIQXLIpRateWWsicxcsvmMXNrvtZO5GVWB2ka/AWciJ 4VkWBTXZxdlAwsiAEmQzEjENOHFYIWdFs1W7eHZCxKXXh96S1+53SrTHjEZWVbfkrDyn MZbNucmRkH7GBYTHUK6fumEnY7UcNE59VPvMeW/hOeGbGACqsq5W5/pa/d/QozhwN/At f8SrwMnlfXVac2VKu7RtVEe9sV/sbNRtX92lCSWfmlM/UbuF7T8L4TRrnOx1HOPz2QoK BGPA== X-Gm-Message-State: AFeK/H0UYElLPjJx/sxdYMeonExrPEDs3iGZDBa6GLw4CFdt/AseAai0ykXTeLnoV49zHvSJ0FOlxIqjJAOlvw== X-Received: by 10.200.35.36 with SMTP id a33mr3227954qta.216.1490973084342; Fri, 31 Mar 2017 08:11:24 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <35fce20b-20e0-3d0e-1957-f3df124a05ac@gmail.com> References: <1d183289-5789-8443-7db8-59816bfdd44c@gmail.com> <7deac251-8f93-9241-3902-daf2abfdef29@gmail.com> <96294553-8088-0a9a-3957-1006743619d5@gmail.com> <35fce20b-20e0-3d0e-1957-f3df124a05ac@gmail.com> From: "H.J. Lu" Date: Sun, 01 Jan 2017 00:00:00 -0000 Message-ID: Subject: Re: RFC: ABI support for special memory area To: Suprateeka R Hegde Cc: "Carlos O'Donell" , gnu-gabi@sourceware.org Content-Type: text/plain; charset=UTF-8 X-SW-Source: 2017-q1/txt/msg00032.txt.bz2 On Fri, Mar 31, 2017 at 6:44 AM, Suprateeka R Hegde wrote: > On 30-Mar-2017 10:10 PM, H.J. Lu wrote: >>> However, I am just thinking that your earlier approach -- >>> __gnu_mbind_setup -- is better when shared libraries with GNU_MBIND >>> segments are dlopen'ed. They dont have to iterate all over again to >>> reach their PHDR. Or what is the recommendation for such dlopen'ed >>> libraries? >> >> It is true that dl_iterate_phdr is called by every shared object, dlopened or >> not, to locate its own PHDR. > > Lets put a one liner on best practices or guideline kind of. You have > already made it clear in the example code. I am just thinking of putting > them in words too. > > Lets say something like, each load module is expected to process only > its special memory segments. To mean that shlibs/exe need not do any > book-keeping to avoid multiple executions of the special memory setup > for the same load module. > >>> And this dl_iterate_phdr(3) not being part of any standards, may change >>> in a totally incompatible way in the future. >>> >> >> dl_iterate_phdr isn't in any standard. But it is in glibc. Given that my >> proposal is a GNU extension, it isn't a major issue. Working with >> existing glibc is a big plus. > > Awesome. Looks great. Thanks a lot for the new approach. > > -- > Supra Here is the updated proposal. Thanks. -- H.J. -- ABI support for special memory area To section attributes, add #define SHF_GNU_MBIND 0x00100000 for sections used to place data or text into a special memory area. The section names should start with ".mbind" so that they won't be grouped together with normal sections by link editor. The sh_info field indicates the special memory type. SHF_GNU_MBIND is only applicable to SHF_ALLOC sections. The following memory types in the sh_info field are defined: /* The highest bandwidth memory. */ #define GNU_MBIND_HBW 0 To the "Program Header" section, add an inclusive range of segment types for GNU_MBIND segments: #define PT_GNU_MBIND_NUM 4096 #define PT_GNU_MBIND_LO (PT_LOOS + 0x474e555) #define PT_GNU_MBIND_HI (PT_GNU_MBIND_LO + PT_GNU_MBIND_NUM - 1) The array element specifies the location and size of a special memory area. Each GNU_MBIND segment contains one GNU_MBIND section and the segment type is PT_GNU_MBIND_LO plus the sh_info value. If the sh_info value is greater than PT_GNU_MBIND_NUM, no GNU_MBIND segment will be created. Each GNU_MBIND segment must be aligned at page boundary. The interpretation of the special memory area information is implementation-dependent. Implementations may ignore GNU_MBIND segment. Run-time support Each load module is expected to process only its special memory segments. There is no need for executable and shared objects to do any book-keeping to avoid multiple executions of the special memory setup for the same load module. dl_iterate_phdr in the the GNU C library: int dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info, size_t size, void *data), void *data); is called via the .init_array section to process GNU_MBIND segments in executable and shared objects: static int callback (struct dl_phdr_info *info, size_t size, void *data) { Compute the load address of the current module. if info->dlpi_addr == the load address of the current module { check ELF program headers and process GNU_MBIND segments return 1; } return 0; } static void call_gnu_mbind_setup (void) { dl_iterate_phdr (callback, NULL); } static void (*init_array) (void) __attribute__ ((section (".init_array"), used)) = &call_gnu_mbind_setup;